Implement produce service
This commit is contained in:
+8
-8
@@ -8,21 +8,21 @@ import (
|
||||
"github.com/google/btree"
|
||||
)
|
||||
|
||||
type record struct {
|
||||
type Record struct {
|
||||
serialized []byte
|
||||
keyColumn string
|
||||
key string
|
||||
id uint64
|
||||
}
|
||||
|
||||
// NewRecord returns a pointer to a record populated with data, key, and a hash of the key used for ordering in the tree.
|
||||
func NewRecord(key, keyColumn string, data interface{}) (*record, error) {
|
||||
// NewRecord returns a pointer to a Record populated with data, key, and a hash of the key used for ordering in the tree.
|
||||
func NewRecord(key, keyColumn string, data interface{}) (*Record, error) {
|
||||
serialized, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r record
|
||||
var r Record
|
||||
r.serialized = serialized
|
||||
r.keyColumn = keyColumn
|
||||
r.key = key
|
||||
@@ -39,13 +39,13 @@ func keyHash(s string) uint64 {
|
||||
}
|
||||
|
||||
// Deserialize unmarshals the serialized data into `into`.
|
||||
func (r *record) Deserialize(into interface{}) error {
|
||||
func (r *Record) Deserialize(into interface{}) error {
|
||||
err := json.Unmarshal(r.serialized, &into)
|
||||
return err
|
||||
}
|
||||
|
||||
// Less is used to order items and for looking up records in the tree.
|
||||
func (r *record) Less(than btree.Item) bool {
|
||||
re := than.(*record)
|
||||
// Less is used to order items and for looking up Records in the tree.
|
||||
func (r *Record) Less(than btree.Item) bool {
|
||||
re := than.(*Record)
|
||||
return r.id < re.id
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user