From c7c47c33c5bcadb075d37ce57fbdb566631ce5ba Mon Sep 17 00:00:00 2001 From: Bo Du Date: Wed, 28 Nov 2018 19:54:04 -0500 Subject: [PATCH] Add iface defs for all types. --- encoding/bool/encoding.go | 45 +++++++++++++++++++++++++++++++++++++ encoding/common/common.go | 11 +++++++++ encoding/double/encoding.go | 45 +++++++++++++++++++++++++++++++++++++ encoding/int/encoding.go | 8 +++++-- encoding/string/encoding.go | 8 +++++-- glide.lock | 14 +++++++----- 6 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 encoding/bool/encoding.go create mode 100644 encoding/common/common.go create mode 100644 encoding/double/encoding.go diff --git a/encoding/bool/encoding.go b/encoding/bool/encoding.go new file mode 100644 index 0000000..da095ad --- /dev/null +++ b/encoding/bool/encoding.go @@ -0,0 +1,45 @@ +package bool + +import ( + "io" + + "github.com/xichen2020/eventdb/encoding/common" +) + +// Encoder encodes bool values. +type Encoder interface { + // Encode a collection of bools. + // Callers should explicitly call `Reset` before + // subsequent call to `Encode`. + Encode(values Iterator) error + // Bytes returns the encoded bytes of the encoder. + Bytes() []byte + // Reset should be called between `Encode` calls. + Reset() +} + +// Decoder decodes bool values. +type Decoder interface { + // Decode the source bytes. + // Callers should explicitly call `Reset` before + // subsequent call to `Decode`. + Decode(src common.Reader) (Iterator, error) + // Reset should be called between `Decode` calls. + Reset() +} + +// Iterator lazily produces bool values decoded from a byte stream. +type Iterator interface { + io.Closer + + // Next returns true if there is another value + // in the data stream. If it returns false, err should be + // checked for errors. + Next() bool + // Current returns the current value in the iteration. + Current() bool + // Err returns any error encountered during iteration. + Err() error + // Reset iteration back to the first item in the collection. + Reset() +} diff --git a/encoding/common/common.go b/encoding/common/common.go new file mode 100644 index 0000000..d5ce4ee --- /dev/null +++ b/encoding/common/common.go @@ -0,0 +1,11 @@ +package common + +import ( + "io" +) + +// Reader wraps both `io.Reader` and `io.ByteReader` interfaces. +type Reader interface { + io.Reader + io.ByteReader +} diff --git a/encoding/double/encoding.go b/encoding/double/encoding.go new file mode 100644 index 0000000..d5882af --- /dev/null +++ b/encoding/double/encoding.go @@ -0,0 +1,45 @@ +package double + +import ( + "io" + + "github.com/xichen2020/eventdb/encoding/common" +) + +// Encoder encodes float64 values. +type Encoder interface { + // Encode a collection of float64s. + // Callers should explicitly call `Reset` before + // subsequent call to `Encode`. + Encode(values Iterator) error + // Bytes returns the encoded bytes of the encoder. + Bytes() []byte + // Reset should be called between `Encode` calls. + Reset() +} + +// Decoder decodes float64 values. +type Decoder interface { + // Decode the source bytes. + // Callers should explicitly call `Reset` before + // subsequent call to `Decode`. + Decode(src common.Reader) (Iterator, error) + // Reset should be called between `Decode` calls. + Reset() +} + +// Iterator lazily produces float64 values decoded from a byte stream. +type Iterator interface { + io.Closer + + // Next returns true if there is another value + // in the data stream. If it returns false, err should be + // checked for errors. + Next() bool + // Current returns the current value in the iteration. + Current() float64 + // Err returns any error encountered during iteration. + Err() error + // Reset iteration back to the first item in the collection. + Reset() +} diff --git a/encoding/int/encoding.go b/encoding/int/encoding.go index 7c863c7..68b29c0 100644 --- a/encoding/int/encoding.go +++ b/encoding/int/encoding.go @@ -1,6 +1,10 @@ package int -import "io" +import ( + "io" + + "github.com/xichen2020/eventdb/encoding/common" +) // Encoder encodes int values. type Encoder interface { @@ -19,7 +23,7 @@ type Decoder interface { // Decode the source bytes. // Callers should explicitly call `Reset` before // subsequent call to `Decode`. - Decode(src io.Reader) (Iterator, error) + Decode(src common.Reader) (Iterator, error) // Reset should be called between `Decode` calls. Reset() } diff --git a/encoding/string/encoding.go b/encoding/string/encoding.go index a4e41b1..077c06f 100644 --- a/encoding/string/encoding.go +++ b/encoding/string/encoding.go @@ -1,6 +1,10 @@ package string -import "io" +import ( + "io" + + "github.com/xichen2020/eventdb/encoding/common" +) // Encoder encodes string values. type Encoder interface { @@ -19,7 +23,7 @@ type Decoder interface { // Decode the source bytes. // Callers should explicitly call `Reset` before // subsequent call to `Decode`. - Decode(src io.Reader) (Iterator, error) + Decode(src common.Reader) (Iterator, error) // Reset should be called between `Decode` calls. Reset() } diff --git a/glide.lock b/glide.lock index 3d2b8e9..dbc00d9 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ hash: ab923de46b056bfd5c32dbb2dd43d4f1c35bb27b7246434bd5334420a10463aa -updated: 2018-11-27T14:32:40.138382-05:00 +updated: 2018-11-28T19:53:52.276143-05:00 imports: - name: github.com/apache/thrift version: b2a4d4ae21c789b689dd162deb819665567f481c @@ -10,13 +10,13 @@ imports: subpackages: - proto - name: github.com/golang/mock - version: c34cdb4725f4c3844d095133c6e40e448b86589b + version: 49a60242bb5c086a9aacc67bdd056e88f75f3c3e subpackages: - gomock - name: github.com/google/uuid version: 9b3b1e0f5f99ae461456d768e7d301a7acdaa2d8 - name: github.com/m3db/m3cluster - version: d971450316604c151719f53afbb95539e6dbafbb + version: 3b9dd4710f0995c0571cbf79d38b8d8c875c4b44 subpackages: - generated/proto/placementpb - shard @@ -57,12 +57,14 @@ imports: - m3/customtransports - m3/thrift - m3/thriftudp +- name: github.com/valyala/gozstd + version: cb65749dd0720d1687ac3d9923de22eb399bb2c3 - name: go.uber.org/atomic version: 1ea20fb1cbb1cc08cbd0d913a96dead89aa18289 - name: go.uber.org/multierr version: 3c4937480c32f4c13a875a1829af76c98ca3d40a - name: go.uber.org/zap - version: ff33455a0e382e8a81d14dd7c922020b6b5e7982 + version: 67bc79d13d155c02fd008f721863ff8cc5f30659 subpackages: - buffer - internal/bufferpool @@ -70,7 +72,7 @@ imports: - internal/exit - zapcore - name: golang.org/x/net - version: f2499483f923065a842d38eb4c7f1927e6fc6e6d + version: adae6a3d119ae4890b46832a2e88a95adc62b8e7 subpackages: - context testImports: @@ -79,7 +81,7 @@ testImports: subpackages: - spew - name: github.com/pmezard/go-difflib - version: d8ed2627bdf02c080bf22230dbb337003b7aba2d + version: 792786c7400a136282c1664665ae0a8db921c6c2 subpackages: - difflib - name: github.com/stretchr/testify