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:
parent
59f488e6c7
commit
7c631ba8c0
7 changed files with 21 additions and 17 deletions
|
|
@ -4,6 +4,6 @@ package connector
|
|||
type AllPassFilter struct{}
|
||||
|
||||
// Returns true for all records.
|
||||
func (b *AllPassFilter) KeepRecord(r Record) bool {
|
||||
func (b *AllPassFilter) KeepRecord(r interface{}) bool {
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ package connector
|
|||
// time limit in seconds. The ShouldFlush() method may indicate that the buffer is full based on
|
||||
// these limits.
|
||||
type Buffer interface {
|
||||
ProcessRecord(record Record, sequenceNumber string)
|
||||
ProcessRecord(record interface{}, sequenceNumber string)
|
||||
FirstSequenceNumber() string
|
||||
Flush()
|
||||
LastSequenceNumber() string
|
||||
NumRecordsInBuffer() int
|
||||
Records() []Record
|
||||
Records() []interface{}
|
||||
ShouldFlush() bool
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
// the record.
|
||||
type Filter interface {
|
||||
KeepRecord(r Record) bool
|
||||
KeepRecord(r interface{}) bool
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
package connector
|
||||
|
||||
// Used to store the data being sent through the Kinesis stream
|
||||
type Record interface {
|
||||
ToDelimitedString() string
|
||||
ToJson() []byte
|
||||
}
|
||||
|
|
@ -4,16 +4,16 @@ package connector
|
|||
// 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.
|
||||
type RecordBuffer struct {
|
||||
NumRecordsToBuffer int
|
||||
NumRecordsToBuffer int
|
||||
|
||||
firstSequenceNumber string
|
||||
lastSequenceNumber string
|
||||
recordsInBuffer []Record
|
||||
recordsInBuffer []interface{}
|
||||
sequencesInBuffer []string
|
||||
}
|
||||
|
||||
// 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 {
|
||||
b.firstSequenceNumber = sequenceNumber
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@ func (b *RecordBuffer) ProcessRecord(record Record, sequenceNumber string) {
|
|||
}
|
||||
|
||||
// Returns the records in the buffer.
|
||||
func (b *RecordBuffer) Records() []Record {
|
||||
func (b *RecordBuffer) Records() []interface{} {
|
||||
return b.recordsInBuffer
|
||||
}
|
||||
|
||||
|
|
|
|||
11
string_to_string_transformer.go
Normal file
11
string_to_string_transformer.go
Normal 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))
|
||||
}
|
||||
|
|
@ -3,6 +3,6 @@ package connector
|
|||
// Transformer is used to transform data (byte array) to a Record for
|
||||
// processing in the application.
|
||||
type Transformer interface {
|
||||
ToRecord(data []byte) Record
|
||||
FromRecord(r Record) []byte
|
||||
ToRecord(data []byte) interface{}
|
||||
FromRecord(r interface{}) []byte
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue