-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba4a0a4
commit 4bf4603
Showing
12 changed files
with
250 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package encoding | ||
|
||
// TimeDecoder decodes time values. | ||
type TimeDecoder interface { | ||
// Decode decodes times from reader. | ||
Decode(reader Reader) (ForwardTimeIterator, error) | ||
|
||
// Reset resets the decoder. | ||
Reset() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package encoding | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
) | ||
|
||
// TimeEncoder encodes times values. | ||
type TimeEncoder interface { | ||
// Encode encodes a collection of time values and writes the encoded bytes to the writer. | ||
// Callers should explicitly call `Reset` before subsequent call to `Encode`. | ||
Encode(writer io.Writer, values ForwardTimeIterator) error | ||
|
||
// Reset resets the encoder. | ||
Reset() | ||
} | ||
|
||
// TimeEnc is a int encoder. | ||
type TimeEnc struct{} | ||
|
||
// NewTimeEncoder creates a new time encoder. | ||
func NewTimeEncoder(writer io.Writer) *TimeEnc { return &TimeEnc{} } | ||
|
||
// Encode encodes a collection of time values and writes the encoded bytes to the writer. | ||
func (enc *TimeEnc) Encode(writer io.Writer, values ForwardTimeIterator) error { | ||
return errors.New("not implemented") | ||
} | ||
|
||
// Reset resets the encoder. | ||
func (enc *TimeEnc) Reset() { panic("not implemented") } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package encoding | ||
|
||
// ForwardTimeIterator performs forward iteration over times. | ||
type ForwardTimeIterator interface { | ||
baseIterator | ||
|
||
// Current returns the current value in nanoseconds in the iteration. | ||
Current() int64 | ||
} | ||
|
||
// RewindableTimeIterator is a forward time iterator that can | ||
// be reset and rewind. | ||
type RewindableTimeIterator interface { | ||
ForwardTimeIterator | ||
|
||
// Rewind rewinds the iterator. | ||
Rewind() | ||
|
||
// Reset resets the data source of the iterator. | ||
Reset(timeNanos []int64) | ||
} | ||
|
||
// ArrayBasedTimeIterator is an array-based time iterator. | ||
type ArrayBasedTimeIterator struct { | ||
timeNanos []int64 | ||
idx int | ||
} | ||
|
||
// NewArrayBasedTimeIterator is a new array-based time iterator. | ||
// NB: The values are in nanoseconds. | ||
func NewArrayBasedTimeIterator(timeNanos []int64) *ArrayBasedTimeIterator { | ||
return &ArrayBasedTimeIterator{ | ||
timeNanos: timeNanos, | ||
idx: -1, | ||
} | ||
} | ||
|
||
// Reset resets the values. | ||
func (it *ArrayBasedTimeIterator) Reset(timeNanos []int64) { | ||
it.timeNanos = timeNanos | ||
it.idx = -1 | ||
} | ||
|
||
// Next returns whether the next value is available. | ||
func (it *ArrayBasedTimeIterator) Next() bool { | ||
if it.idx >= len(it.timeNanos) { | ||
return false | ||
} | ||
it.idx++ | ||
return it.idx >= len(it.timeNanos) | ||
} | ||
|
||
// Current returns the current time value in nanoseconds. | ||
func (it *ArrayBasedTimeIterator) Current() int64 { return it.timeNanos[it.idx] } | ||
|
||
// Err returns error if any. | ||
func (it *ArrayBasedTimeIterator) Err() error { return nil } | ||
|
||
// Close closes the iterator. | ||
func (it *ArrayBasedTimeIterator) Close() error { return nil } | ||
|
||
// Rewind rewinds the time iterator. | ||
func (it *ArrayBasedTimeIterator) Rewind() { it.idx = -1 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.