Skip to content

Commit

Permalink
Add iface defs for all types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Du committed Nov 29, 2018
1 parent 8024f1f commit c7c47c3
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 10 deletions.
45 changes: 45 additions & 0 deletions encoding/bool/encoding.go
Original file line number Diff line number Diff line change
@@ -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()
}
11 changes: 11 additions & 0 deletions encoding/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package common

import (
"io"
)

// Reader wraps both `io.Reader` and `io.ByteReader` interfaces.
type Reader interface {
io.Reader
io.ByteReader
}
45 changes: 45 additions & 0 deletions encoding/double/encoding.go
Original file line number Diff line number Diff line change
@@ -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()
}
8 changes: 6 additions & 2 deletions encoding/int/encoding.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package int

import "io"
import (
"io"

"github.com/xichen2020/eventdb/encoding/common"
)

// Encoder encodes int values.
type Encoder interface {
Expand All @@ -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()
}
Expand Down
8 changes: 6 additions & 2 deletions encoding/string/encoding.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package string

import "io"
import (
"io"

"github.com/xichen2020/eventdb/encoding/common"
)

// Encoder encodes string values.
type Encoder interface {
Expand All @@ -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()
}
Expand Down
14 changes: 8 additions & 6 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c7c47c3

Please sign in to comment.