From fa145f79486f9afc658399201a8160adc91f337a Mon Sep 17 00:00:00 2001 From: UnicodingUnicorn <7555ic@gmail.com> Date: Wed, 13 Feb 2019 22:45:23 +0800 Subject: [PATCH] Initial commit --- .gitignore | 12 +++ README.md | 16 +++- bite.pb.go | 103 ++++++++++++++++++++ client.pb.go | 84 +++++++++++++++++ data_request.pb.go | 94 +++++++++++++++++++ key.go | 70 ++++++++++++++ main.go | 229 +++++++++++++++++++++++++++++++++++++++++++++ response.pb.go | 95 +++++++++++++++++++ scan_request.pb.go | 103 ++++++++++++++++++++ store.pb.go | 85 +++++++++++++++++ 10 files changed, 890 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 bite.pb.go create mode 100644 client.pb.go create mode 100644 data_request.pb.go create mode 100644 key.go create mode 100644 main.go create mode 100644 response.pb.go create mode 100644 scan_request.pb.go create mode 100644 store.pb.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2dd955 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out diff --git a/README.md b/README.md index 0daab81..dcd35df 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ # backend-store -Single Badger store to serve bite, transcription and any others. \ No newline at end of file +Single Badger store to serve bite, transcription and any others. Is kinda bite-centric, so required values revolve around a Bite. Transacts through NATS. + +## Key format + +Takes in three variables: ```type```, ```key``` and ```start```. Type is the type of data to be inserted, e.g. ```bite```, ```bite_user``` or ```transcription```. Key could be some secret passphrase declaring you the Raj of British India for all I know. Start is the Epoch timestamp of the start of the Bite. + +## NATS + +Refer to protobuf definitions in ```backend-protobuf```. + +| Name | What you do | Accepted Protobuf | Protobuf redundant fields | Response Protobuf | Response empty fields | +| ---- | ----------- | ----------------- | ------------------------- | ----------------- | --------------------- | +| new_store | Publish to | Store | - | - | - | +| request_store | Request | DataRequest | - | Response | client | +| scan_store | Request | ScanRequest | - | Response | client | diff --git a/bite.pb.go b/bite.pb.go new file mode 100644 index 0000000..2a884ce --- /dev/null +++ b/bite.pb.go @@ -0,0 +1,103 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: bite.proto + +package main + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type Bite struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Start uint64 `protobuf:"varint,2,opt,name=start,proto3" json:"start,omitempty"` + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` + Client *Client `protobuf:"bytes,4,opt,name=client,proto3" json:"client,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Bite) Reset() { *m = Bite{} } +func (m *Bite) String() string { return proto.CompactTextString(m) } +func (*Bite) ProtoMessage() {} +func (*Bite) Descriptor() ([]byte, []int) { + return fileDescriptor_e1ec993646b17549, []int{0} +} + +func (m *Bite) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Bite.Unmarshal(m, b) +} +func (m *Bite) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Bite.Marshal(b, m, deterministic) +} +func (m *Bite) XXX_Merge(src proto.Message) { + xxx_messageInfo_Bite.Merge(m, src) +} +func (m *Bite) XXX_Size() int { + return xxx_messageInfo_Bite.Size(m) +} +func (m *Bite) XXX_DiscardUnknown() { + xxx_messageInfo_Bite.DiscardUnknown(m) +} + +var xxx_messageInfo_Bite proto.InternalMessageInfo + +func (m *Bite) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *Bite) GetStart() uint64 { + if m != nil { + return m.Start + } + return 0 +} + +func (m *Bite) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +func (m *Bite) GetClient() *Client { + if m != nil { + return m.Client + } + return nil +} + +func init() { + proto.RegisterType((*Bite)(nil), "main.Bite") +} + +func init() { proto.RegisterFile("bite.proto", fileDescriptor_e1ec993646b17549) } + +var fileDescriptor_e1ec993646b17549 = []byte{ + // 139 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4a, 0xca, 0x2c, 0x49, + 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, 0x93, 0xe2, 0x49, 0xce, + 0xc9, 0x4c, 0xcd, 0x2b, 0x81, 0x88, 0x29, 0x65, 0x70, 0xb1, 0x38, 0x65, 0x96, 0xa4, 0x0a, 0x09, + 0x70, 0x31, 0x67, 0xa7, 0x56, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x81, 0x98, 0x42, 0x22, + 0x5c, 0xac, 0xc5, 0x25, 0x89, 0x45, 0x25, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0x2c, 0x41, 0x10, 0x8e, + 0x90, 0x10, 0x17, 0x4b, 0x4a, 0x62, 0x49, 0xa2, 0x04, 0xb3, 0x02, 0xa3, 0x06, 0x4f, 0x10, 0x98, + 0x2d, 0xa4, 0xc2, 0xc5, 0x06, 0x31, 0x53, 0x82, 0x45, 0x81, 0x51, 0x83, 0xdb, 0x88, 0x47, 0x0f, + 0x64, 0x91, 0x9e, 0x33, 0x58, 0x2c, 0x08, 0x2a, 0x97, 0xc4, 0x06, 0xb6, 0xd0, 0x18, 0x10, 0x00, + 0x00, 0xff, 0xff, 0x0a, 0x85, 0x92, 0x1b, 0x92, 0x00, 0x00, 0x00, +} diff --git a/client.pb.go b/client.pb.go new file mode 100644 index 0000000..b968e65 --- /dev/null +++ b/client.pb.go @@ -0,0 +1,84 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: client.proto + +package main + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type Client struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Client string `protobuf:"bytes,2,opt,name=client,proto3" json:"client,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Client) Reset() { *m = Client{} } +func (m *Client) String() string { return proto.CompactTextString(m) } +func (*Client) ProtoMessage() {} +func (*Client) Descriptor() ([]byte, []int) { + return fileDescriptor_014de31d7ac8c57c, []int{0} +} + +func (m *Client) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Client.Unmarshal(m, b) +} +func (m *Client) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Client.Marshal(b, m, deterministic) +} +func (m *Client) XXX_Merge(src proto.Message) { + xxx_messageInfo_Client.Merge(m, src) +} +func (m *Client) XXX_Size() int { + return xxx_messageInfo_Client.Size(m) +} +func (m *Client) XXX_DiscardUnknown() { + xxx_messageInfo_Client.DiscardUnknown(m) +} + +var xxx_messageInfo_Client proto.InternalMessageInfo + +func (m *Client) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *Client) GetClient() string { + if m != nil { + return m.Client + } + return "" +} + +func init() { + proto.RegisterType((*Client)(nil), "main.Client") +} + +func init() { proto.RegisterFile("client.proto", fileDescriptor_014de31d7ac8c57c) } + +var fileDescriptor_014de31d7ac8c57c = []byte{ + // 83 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0xce, 0xc9, 0x4c, + 0xcd, 0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, 0x53, 0x32, + 0xe2, 0x62, 0x73, 0x06, 0x8b, 0x0a, 0x09, 0x70, 0x31, 0x67, 0xa7, 0x56, 0x4a, 0x30, 0x2a, 0x30, + 0x6a, 0x70, 0x06, 0x81, 0x98, 0x42, 0x62, 0x5c, 0x6c, 0x10, 0x1d, 0x12, 0x4c, 0x60, 0x41, 0x28, + 0x2f, 0x89, 0x0d, 0x6c, 0x80, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x95, 0x71, 0x3f, 0xbd, 0x50, + 0x00, 0x00, 0x00, +} diff --git a/data_request.pb.go b/data_request.pb.go new file mode 100644 index 0000000..858132e --- /dev/null +++ b/data_request.pb.go @@ -0,0 +1,94 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: store/data_request.proto + +package main + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type DataRequest struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Start uint64 `protobuf:"varint,2,opt,name=start,proto3" json:"start,omitempty"` + Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DataRequest) Reset() { *m = DataRequest{} } +func (m *DataRequest) String() string { return proto.CompactTextString(m) } +func (*DataRequest) ProtoMessage() {} +func (*DataRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_1c7f2c7bfa43f02c, []int{0} +} + +func (m *DataRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DataRequest.Unmarshal(m, b) +} +func (m *DataRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DataRequest.Marshal(b, m, deterministic) +} +func (m *DataRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DataRequest.Merge(m, src) +} +func (m *DataRequest) XXX_Size() int { + return xxx_messageInfo_DataRequest.Size(m) +} +func (m *DataRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DataRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DataRequest proto.InternalMessageInfo + +func (m *DataRequest) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *DataRequest) GetStart() uint64 { + if m != nil { + return m.Start + } + return 0 +} + +func (m *DataRequest) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func init() { + proto.RegisterType((*DataRequest)(nil), "main.DataRequest") +} + +func init() { proto.RegisterFile("store/data_request.proto", fileDescriptor_1c7f2c7bfa43f02c) } + +var fileDescriptor_1c7f2c7bfa43f02c = []byte{ + // 119 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x28, 0x2e, 0xc9, 0x2f, + 0x4a, 0xd5, 0x4f, 0x49, 0x2c, 0x49, 0x8c, 0x2f, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0xd1, 0x2b, + 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, 0x53, 0xf2, 0xe4, 0xe2, 0x76, 0x49, + 0x2c, 0x49, 0x0c, 0x82, 0x48, 0x09, 0x09, 0x70, 0x31, 0x67, 0xa7, 0x56, 0x4a, 0x30, 0x2a, 0x30, + 0x6a, 0x70, 0x06, 0x81, 0x98, 0x42, 0x22, 0x5c, 0xac, 0xc5, 0x25, 0x89, 0x45, 0x25, 0x12, 0x4c, + 0x0a, 0x8c, 0x1a, 0x2c, 0x41, 0x10, 0x8e, 0x90, 0x10, 0x17, 0x4b, 0x49, 0x65, 0x41, 0xaa, 0x04, + 0x33, 0x58, 0x21, 0x98, 0x9d, 0xc4, 0x06, 0x36, 0xd7, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x70, + 0x54, 0xb9, 0xcc, 0x73, 0x00, 0x00, 0x00, +} diff --git a/key.go b/key.go new file mode 100644 index 0000000..a574e1a --- /dev/null +++ b/key.go @@ -0,0 +1,70 @@ +package main + +import ( + "bytes" + "encoding/binary" + "errors" + "regexp" +) + +var ExtractKeyParseError = errors.New("ExtractKey: parse error, possibly because seprator was not found") + +// Marshal keys +func validObj(obj string) bool { + return obj == "bite" || obj == "user" +} + +// TODO: ensure security of regexp +var validConversationRegexp = regexp.MustCompile(`^[a-zA-Z0-9-]+$`) + +func validConversation(conversation string) bool { + return validConversationRegexp.MatchString(conversation) +} + +const conversationSeprator = '@' +const objSeprator = '+' + +func MarshalKey(obj, conversation string, start uint64) ([]byte, error) { + prefixBytes, err := MarshalKeyPrefix(obj, conversation) + if err != nil { + return nil, err + } + + startBytes := make([]byte, 8) + binary.BigEndian.PutUint64(startBytes, start) + + return append(prefixBytes, startBytes...), nil +} + +func MarshalKeyPrefix(obj, conversation string) ([]byte, error) { + if !validObj(obj) || !validConversation(conversation) { + return nil, errors.New("main: FormatKey: bad obj or conversation") + } + return []byte(obj + string(objSeprator) + conversation + string(conversationSeprator)), nil +} + +func ExtractKey(b []byte) (string, string, uint64, error) { + startStart := bytes.LastIndexByte(b, conversationSeprator) + 1 + if startStart < 0 { + return "", "", 0, ExtractKeyParseError + } + startBytes := b[startStart:] + + convStart := bytes.LastIndexByte(b[:startStart-1], objSeprator) + 1 + if convStart < 0 { + return "", "", 0, ExtractKeyParseError + } + convBytes := b[convStart : startStart-1] + + objStart := 0 + if objStart < 0 { + return "", "", 0, ExtractKeyParseError + } + objBytes := b[objStart : convStart-1] + + obj := string(objBytes) + conv := string(convBytes) + start := binary.BigEndian.Uint64(startBytes) + + return obj, conv, start, nil +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..9f14074 --- /dev/null +++ b/main.go @@ -0,0 +1,229 @@ +package main + +import ( + "encoding/json" + "flag" + "log" + "net/http" + + "github.com/dgraph-io/badger" + "github.com/nats-io/go-nats" + "github.com/golang/protobuf/proto" +) + +var dbPath string +var natsHost string + +var db *badger.DB +var nc *nats.Conn + +func main() { + // Parse flags + flag.StringVar(&dbPath, "dbpath", "/tmp/badger", "path to store data") + flag.StringVar(&natsHost, "nats", "nats://localhost:4222", "host and port of NATS") + flag.Parse() + + // Open badger + log.Printf("starting badger at %s", dbPath) + opts := badger.DefaultOptions + opts.Dir = dbPath + opts.ValueDir = dbPath + var err error + db, err = badger.Open(opts) + if err != nil { + log.Fatal(err) + } + defer db.Close() + + // NATS client + nc, err = nats.Connect(natsHost) + if err != nil { + log.Fatal(err) + } + nc.Subscribe("new_store", NewStore) + + nc.Subscribe("request_store", RequestStore) + nc.Subscribe("scan_store", ScanStore) + defer nc.Close() + + select { } // Wait forever +} + +func NewStore(m *nats.Msg) { + storeRequest := Store{} + if err := proto.Unmarshal(m.Data, &storeRequest); err != nil { + log.Println(err) + return + } + + key, err := MarshalKey(storeRequest.Type, storeRequest.Bite.Key, storeRequest.Bite.Start) + if err != nil { + log.Println(err) + return + } + + err = db.Update(func(txn *badger.Txn) error { + // TODO: prevent overwriting existing + err := txn.Set(key, storeRequest.Bite.Data) + return err + }) + + if err != nil { + log.Println(err) + return + } +} + +func RequestStore(m *nats.Msg) { + req := DataRequest{} + if err := proto.Unmarshal(m.Data, &req); err != nil { + log.Println(err) + return + } + + key, err := MarshalKey(req.Type, req.Key, req.Start) + + err = db.View(func(txn *badger.Txn) error { + item, err := txn.Get(key) + if err != nil { + return err + } + err = item.Value(func(value []byte) error { + res := Response { + Code: 200, + Message: value, + } + resBytes, resErr := proto.Marshal(&res) + + if resErr != nil { + return resErr + } + + nc.Publish(m.Reply, resBytes) + return nil + }) + if err != nil { + return err + } + return nil + }) + + if err != nil { + res := ReplyError(err.Error(), 400) + nc.Publish(m.Reply, res) + } +} + +type BitesList struct { + Previous uint64 `json:"previous"` // One bite before starts. Hint for how many steps the client can skip + Starts []uint64 `json:"starts"` + Next uint64 `json:"next"` // One bite after starts. Hint for how many steps the client can skip +} + +func ScanStore(m *nats.Msg) { + req := ScanRequest {} + if err := proto.Unmarshal(m.Data, &req); err != nil { + log.Println(err) + return + } + + prefix, err := MarshalKeyPrefix(req.Type, req.Key) + + if err != nil { + res := ReplyError(http.StatusText(http.StatusBadRequest), http.StatusBadRequest) + nc.Publish(m.Reply, res) + return + } + + fromKey, err := MarshalKey(req.Type, req.Key, req.From) + if err != nil { + res := ReplyError(http.StatusText(http.StatusBadRequest), http.StatusBadRequest) + nc.Publish(m.Reply, res) + return + } + + bitesList := BitesList {} + + err = db.View(func(txn *badger.Txn) error { + opts := badger.DefaultIteratorOptions + opts.PrefetchValues = false + opts.Reverse = true + it := txn.NewIterator(opts) + defer it.Close() + + // Fetch previous key + it.Seek(fromKey) + if it.ValidForPrefix(fromKey) { + // Lazy check to compare key == seeked key + it.Next() + } + if !it.ValidForPrefix(prefix) { + return nil + } + item := it.Item() + key := item.Key() + + _, _, start, err := ExtractKey(key) + if err != nil { + return nil + } + bitesList.Previous = start + + return nil + }) + if err != nil { + res := ReplyError(err.Error(), http.StatusBadRequest) + nc.Publish(m.Reply, res) + return + } + + err = db.View(func(txn *badger.Txn) error { + opts := badger.DefaultIteratorOptions + opts.PrefetchValues = false + it := txn.NewIterator(opts) + defer it.Close() + + for it.Seek(fromKey); it.ValidForPrefix(prefix); it.Next() { + item := it.Item() + key := item.Key() + + _, _, start, err := ExtractKey(key) + if err != nil { + continue + } + if start > req.To { + // A key was found that is greater than to + // Save that as next + bitesList.Next = start + break + } + + bitesList.Starts = append(bitesList.Starts, start) + } + + return nil + }) + if err != nil { + res := ReplyError(err.Error(), http.StatusBadRequest) + nc.Publish(m.Reply, res) + return + } + + jsonString, err := json.Marshal(&bitesList) + res := Response { + Code: 200, + Message: []byte(jsonString), + } + resBytes, _ := proto.Marshal(&res) + nc.Publish(m.Reply, resBytes) +} + +func ReplyError(msg string, code uint32) []byte { + res := Response { + Code: code, + Message: []byte(msg), + } + resBytes, _ := proto.Marshal(&res) + + return resBytes +} diff --git a/response.pb.go b/response.pb.go new file mode 100644 index 0000000..3797a39 --- /dev/null +++ b/response.pb.go @@ -0,0 +1,95 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: response.proto + +package main + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type Response struct { + Code uint32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` + Message []byte `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + Client *Client `protobuf:"bytes,3,opt,name=client,proto3" json:"client,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Response) Reset() { *m = Response{} } +func (m *Response) String() string { return proto.CompactTextString(m) } +func (*Response) ProtoMessage() {} +func (*Response) Descriptor() ([]byte, []int) { + return fileDescriptor_0fbc901015fa5021, []int{0} +} + +func (m *Response) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Response.Unmarshal(m, b) +} +func (m *Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Response.Marshal(b, m, deterministic) +} +func (m *Response) XXX_Merge(src proto.Message) { + xxx_messageInfo_Response.Merge(m, src) +} +func (m *Response) XXX_Size() int { + return xxx_messageInfo_Response.Size(m) +} +func (m *Response) XXX_DiscardUnknown() { + xxx_messageInfo_Response.DiscardUnknown(m) +} + +var xxx_messageInfo_Response proto.InternalMessageInfo + +func (m *Response) GetCode() uint32 { + if m != nil { + return m.Code + } + return 0 +} + +func (m *Response) GetMessage() []byte { + if m != nil { + return m.Message + } + return nil +} + +func (m *Response) GetClient() *Client { + if m != nil { + return m.Client + } + return nil +} + +func init() { + proto.RegisterType((*Response)(nil), "main.Response") +} + +func init() { proto.RegisterFile("response.proto", fileDescriptor_0fbc901015fa5021) } + +var fileDescriptor_0fbc901015fa5021 = []byte{ + // 129 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2b, 0x4a, 0x2d, 0x2e, + 0xc8, 0xcf, 0x2b, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, + 0x93, 0xe2, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0x81, 0x88, 0x29, 0xc5, 0x71, 0x71, 0x04, 0x41, + 0x55, 0x09, 0x09, 0x71, 0xb1, 0x24, 0xe7, 0xa7, 0xa4, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0xf0, 0x06, + 0x81, 0xd9, 0x42, 0x12, 0x5c, 0xec, 0xb9, 0xa9, 0xc5, 0xc5, 0x89, 0xe9, 0xa9, 0x12, 0x4c, 0x0a, + 0x8c, 0x1a, 0x3c, 0x41, 0x30, 0xae, 0x90, 0x0a, 0x17, 0x1b, 0xc4, 0x24, 0x09, 0x66, 0x05, 0x46, + 0x0d, 0x6e, 0x23, 0x1e, 0x3d, 0x90, 0xf1, 0x7a, 0xce, 0x60, 0xb1, 0x20, 0xa8, 0x5c, 0x12, 0x1b, + 0xd8, 0x1a, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x14, 0x8c, 0xe3, 0xa3, 0x8c, 0x00, 0x00, + 0x00, +} diff --git a/scan_request.pb.go b/scan_request.pb.go new file mode 100644 index 0000000..681c08e --- /dev/null +++ b/scan_request.pb.go @@ -0,0 +1,103 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: store/scan_request.proto + +package main + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type ScanRequest struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + From uint64 `protobuf:"varint,2,opt,name=from,proto3" json:"from,omitempty"` + To uint64 `protobuf:"varint,3,opt,name=to,proto3" json:"to,omitempty"` + Type string `protobuf:"bytes,4,opt,name=type,proto3" json:"type,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ScanRequest) Reset() { *m = ScanRequest{} } +func (m *ScanRequest) String() string { return proto.CompactTextString(m) } +func (*ScanRequest) ProtoMessage() {} +func (*ScanRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_812dc305bd560f72, []int{0} +} + +func (m *ScanRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ScanRequest.Unmarshal(m, b) +} +func (m *ScanRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ScanRequest.Marshal(b, m, deterministic) +} +func (m *ScanRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ScanRequest.Merge(m, src) +} +func (m *ScanRequest) XXX_Size() int { + return xxx_messageInfo_ScanRequest.Size(m) +} +func (m *ScanRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ScanRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ScanRequest proto.InternalMessageInfo + +func (m *ScanRequest) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *ScanRequest) GetFrom() uint64 { + if m != nil { + return m.From + } + return 0 +} + +func (m *ScanRequest) GetTo() uint64 { + if m != nil { + return m.To + } + return 0 +} + +func (m *ScanRequest) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func init() { + proto.RegisterType((*ScanRequest)(nil), "main.ScanRequest") +} + +func init() { proto.RegisterFile("store/scan_request.proto", fileDescriptor_812dc305bd560f72) } + +var fileDescriptor_812dc305bd560f72 = []byte{ + // 129 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x28, 0x2e, 0xc9, 0x2f, + 0x4a, 0xd5, 0x2f, 0x4e, 0x4e, 0xcc, 0x8b, 0x2f, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0xd1, 0x2b, + 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, 0x53, 0x0a, 0xe7, 0xe2, 0x0e, 0x4e, + 0x4e, 0xcc, 0x0b, 0x82, 0x48, 0x09, 0x09, 0x70, 0x31, 0x67, 0xa7, 0x56, 0x4a, 0x30, 0x2a, 0x30, + 0x6a, 0x70, 0x06, 0x81, 0x98, 0x42, 0x42, 0x5c, 0x2c, 0x69, 0x45, 0xf9, 0xb9, 0x12, 0x4c, 0x0a, + 0x8c, 0x1a, 0x2c, 0x41, 0x60, 0xb6, 0x10, 0x1f, 0x17, 0x53, 0x49, 0xbe, 0x04, 0x33, 0x58, 0x84, + 0xa9, 0x24, 0x1f, 0xa4, 0xa6, 0xa4, 0xb2, 0x20, 0x55, 0x82, 0x05, 0xac, 0x0d, 0xcc, 0x4e, 0x62, + 0x03, 0xdb, 0x62, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x2e, 0x77, 0x60, 0x56, 0x81, 0x00, 0x00, + 0x00, +} diff --git a/store.pb.go b/store.pb.go new file mode 100644 index 0000000..e6463cc --- /dev/null +++ b/store.pb.go @@ -0,0 +1,85 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: store.proto + +package main + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type Store struct { + Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` + Bite *Bite `protobuf:"bytes,2,opt,name=bite,proto3" json:"bite,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Store) Reset() { *m = Store{} } +func (m *Store) String() string { return proto.CompactTextString(m) } +func (*Store) ProtoMessage() {} +func (*Store) Descriptor() ([]byte, []int) { + return fileDescriptor_98bbca36ef968dfc, []int{0} +} + +func (m *Store) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Store.Unmarshal(m, b) +} +func (m *Store) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Store.Marshal(b, m, deterministic) +} +func (m *Store) XXX_Merge(src proto.Message) { + xxx_messageInfo_Store.Merge(m, src) +} +func (m *Store) XXX_Size() int { + return xxx_messageInfo_Store.Size(m) +} +func (m *Store) XXX_DiscardUnknown() { + xxx_messageInfo_Store.DiscardUnknown(m) +} + +var xxx_messageInfo_Store proto.InternalMessageInfo + +func (m *Store) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *Store) GetBite() *Bite { + if m != nil { + return m.Bite + } + return nil +} + +func init() { + proto.RegisterType((*Store)(nil), "main.Store") +} + +func init() { proto.RegisterFile("store.proto", fileDescriptor_98bbca36ef968dfc) } + +var fileDescriptor_98bbca36ef968dfc = []byte{ + // 104 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2e, 0x2e, 0xc9, 0x2f, + 0x4a, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, 0x93, 0xe2, 0x4a, + 0xca, 0x2c, 0x81, 0x8a, 0x28, 0x59, 0x73, 0xb1, 0x06, 0x83, 0x14, 0x08, 0x09, 0x71, 0xb1, 0x94, + 0x54, 0x16, 0xa4, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x81, 0xd9, 0x42, 0x72, 0x5c, 0x2c, + 0x20, 0xa5, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xdc, 0x46, 0x5c, 0x7a, 0x20, 0xdd, 0x7a, 0x4e, 0x99, + 0x25, 0xa9, 0x41, 0x60, 0xf1, 0x24, 0x36, 0xb0, 0x19, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x84, 0x05, 0xf9, 0x1a, 0x64, 0x00, 0x00, 0x00, +}