Add StringToString transformer

In some cases we'll want to save the data from the stream directly with
no transformation needed. This will allow us to return the raw data
string from the stream

* Add new StringToStringTransformer
* Remove Record from codebase in favor of more generic interface
This commit is contained in:
Harlow Ward 2014-11-15 17:00:37 -08:00
parent 59f488e6c7
commit 7c631ba8c0
7 changed files with 21 additions and 17 deletions

View file

@ -4,6 +4,6 @@ package connector
type AllPassFilter struct{} type AllPassFilter struct{}
// Returns true for all records. // Returns true for all records.
func (b *AllPassFilter) KeepRecord(r Record) bool { func (b *AllPassFilter) KeepRecord(r interface{}) bool {
return true return true
} }

View file

@ -6,11 +6,11 @@ package connector
// time limit in seconds. The ShouldFlush() method may indicate that the buffer is full based on // time limit in seconds. The ShouldFlush() method may indicate that the buffer is full based on
// these limits. // these limits.
type Buffer interface { type Buffer interface {
ProcessRecord(record Record, sequenceNumber string) ProcessRecord(record interface{}, sequenceNumber string)
FirstSequenceNumber() string FirstSequenceNumber() string
Flush() Flush()
LastSequenceNumber() string LastSequenceNumber() string
NumRecordsInBuffer() int NumRecordsInBuffer() int
Records() []Record Records() []interface{}
ShouldFlush() bool ShouldFlush() bool
} }

View file

@ -6,5 +6,5 @@ package connector
// A method enabling the buffer to filter records. Return false if you don't want to hold on to // A method enabling the buffer to filter records. Return false if you don't want to hold on to
// the record. // the record.
type Filter interface { type Filter interface {
KeepRecord(r Record) bool KeepRecord(r interface{}) bool
} }

View file

@ -1,7 +0,0 @@
package connector
// Used to store the data being sent through the Kinesis stream
type Record interface {
ToDelimitedString() string
ToJson() []byte
}

View file

@ -4,16 +4,16 @@ package connector
// records that are periodically flushed. It is configured with an implementation of Filter that // records that are periodically flushed. It is configured with an implementation of Filter that
// decides whether a record will be added to the buffer to be emitted. // decides whether a record will be added to the buffer to be emitted.
type RecordBuffer struct { type RecordBuffer struct {
NumRecordsToBuffer int NumRecordsToBuffer int
firstSequenceNumber string firstSequenceNumber string
lastSequenceNumber string lastSequenceNumber string
recordsInBuffer []Record recordsInBuffer []interface{}
sequencesInBuffer []string sequencesInBuffer []string
} }
// Adds a message to the buffer. // Adds a message to the buffer.
func (b *RecordBuffer) ProcessRecord(record Record, sequenceNumber string) { func (b *RecordBuffer) ProcessRecord(record interface{}, sequenceNumber string) {
if len(b.sequencesInBuffer) == 0 { if len(b.sequencesInBuffer) == 0 {
b.firstSequenceNumber = sequenceNumber b.firstSequenceNumber = sequenceNumber
} }
@ -27,7 +27,7 @@ func (b *RecordBuffer) ProcessRecord(record Record, sequenceNumber string) {
} }
// Returns the records in the buffer. // Returns the records in the buffer.
func (b *RecordBuffer) Records() []Record { func (b *RecordBuffer) Records() []interface{} {
return b.recordsInBuffer return b.recordsInBuffer
} }

View file

@ -0,0 +1,11 @@
package connector
type StringToStringTransformer struct{}
func (t StringToStringTransformer) ToRecord(data []byte) interface{} {
return string(data)
}
func (t StringToStringTransformer) FromRecord(s interface{}) []byte {
return []byte(s.(string))
}

View file

@ -3,6 +3,6 @@ package connector
// Transformer is used to transform data (byte array) to a Record for // Transformer is used to transform data (byte array) to a Record for
// processing in the application. // processing in the application.
type Transformer interface { type Transformer interface {
ToRecord(data []byte) Record ToRecord(data []byte) interface{}
FromRecord(r Record) []byte FromRecord(r interface{}) []byte
} }