wheat-cache/storage/persisted/codec.gen.go

397 lines
8.0 KiB
Go
Raw Normal View History

2021-11-01 17:36:35 +08:00
// Code generated by gen-struct. DO NOT EDIT.
// make gen-service generated
package persisted
import (
"bytes"
"encoding/hex"
"fmt"
2021-11-02 14:45:08 +08:00
"gitee.com/wheat-os/wheatCache/pkg/errorx"
"gitee.com/wheat-os/wheatCache/pkg/proto"
2021-11-01 17:36:35 +08:00
protobuf "google.golang.org/protobuf/proto"
)
2021-11-01 21:55:50 +08:00
type codecProto struct {
2021-11-01 17:36:35 +08:00
}
2021-11-01 21:55:50 +08:00
func (c *codecProto) Encode(method string, m protobuf.Message) ([]byte, error) {
2021-11-01 17:36:35 +08:00
buf, err := protobuf.Marshal(m)
if err != nil {
return nil, err
}
// 16 进制编码
dst := make([]byte, hex.EncodedLen(len(buf)))
n := hex.Encode(dst, buf)
buffer := bytes.NewBuffer(dst[:n])
buffer.WriteString(fmt.Sprint(":", method))
return buffer.Bytes(), nil
}
2021-11-01 21:55:50 +08:00
func (c *codecProto) Decode(buf []byte) (protobuf.Message, error) {
2021-11-01 17:36:35 +08:00
hexBuf := bytes.Split(buf, []byte(":"))
if len(hexBuf) != 2 {
return nil, errorx.New("decode aof err: not a valid aof")
}
method := string(hexBuf[1])
n, err := hex.Decode(buf, hexBuf[0])
if err != nil {
return nil, err
}
return decode(method, buf[:n])
}
func decode(method string, buf []byte) (protobuf.Message, error) {
switch method {
case "LIndex":
return decodeLIndex(buf)
case "LLen":
return decodeLLen(buf)
case "LPop":
return decodeLPop(buf)
case "LPush":
return decodeLPush(buf)
case "LPushX":
return decodeLPushX(buf)
case "LRange":
return decodeLRange(buf)
case "LRem":
return decodeLRem(buf)
case "LSet":
return decodeLSet(buf)
case "RPop":
return decodeRPop(buf)
case "LTrim":
return decodeLTrim(buf)
case "RPush":
return decodeRPush(buf)
case "RPushX":
return decodeRPushX(buf)
2021-11-04 20:36:42 +08:00
case "HDel":
return decodeHDel(buf)
case "HExists":
return decodeHExists(buf)
case "HGet":
return decodeHGet(buf)
case "HGetAll":
return decodeHGetAll(buf)
case "HIncrBy":
return decodeHIncrBy(buf)
case "HKeys":
return decodeHKeys(buf)
case "HLen":
return decodeHLen(buf)
case "HSet":
return decodeHSet(buf)
case "HSetX":
return decodeHSetX(buf)
2021-11-01 17:36:35 +08:00
case "Set":
return decodeSet(buf)
case "Get":
return decodeGet(buf)
case "Add":
return decodeAdd(buf)
case "Reduce":
return decodeReduce(buf)
case "Setnx":
return decodeSetnx(buf)
case "SetBit":
return decodeSetBit(buf)
case "GetBit":
return decodeGetBit(buf)
case "GetRange":
return decodeGetRange(buf)
case "GetSet":
return decodeGetSet(buf)
case "StrLen":
return decodeStrLen(buf)
}
return nil, errorx.New("decode aof err, the method could not be resolved, method:%s", method)
}
func decodeLIndex(buf []byte) (*proto.LIndexRequest, error) {
req := &proto.LIndexRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeLLen(buf []byte) (*proto.LLenRequest, error) {
req := &proto.LLenRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeLPop(buf []byte) (*proto.LPopRequest, error) {
req := &proto.LPopRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeLPush(buf []byte) (*proto.LPushRequest, error) {
req := &proto.LPushRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeLPushX(buf []byte) (*proto.LPushXRequest, error) {
req := &proto.LPushXRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeLRange(buf []byte) (*proto.LRangeRequest, error) {
req := &proto.LRangeRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeLRem(buf []byte) (*proto.LRemRequest, error) {
req := &proto.LRemRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeLSet(buf []byte) (*proto.LSetRequest, error) {
req := &proto.LSetRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeRPop(buf []byte) (*proto.RPopRequest, error) {
req := &proto.RPopRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeLTrim(buf []byte) (*proto.LTrimRequest, error) {
req := &proto.LTrimRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeRPush(buf []byte) (*proto.RPushRequest, error) {
req := &proto.RPushRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeRPushX(buf []byte) (*proto.RPushXRequest, error) {
req := &proto.RPushXRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
2021-11-04 20:36:42 +08:00
func decodeHDel(buf []byte) (*proto.HDelRequest, error) {
req := &proto.HDelRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeHExists(buf []byte) (*proto.HExistsRequest, error) {
req := &proto.HExistsRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeHGet(buf []byte) (*proto.HGetRequest, error) {
req := &proto.HGetRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeHGetAll(buf []byte) (*proto.HGetAllRequest, error) {
req := &proto.HGetAllRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeHIncrBy(buf []byte) (*proto.HIncrByRequest, error) {
req := &proto.HIncrByRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeHKeys(buf []byte) (*proto.HKeysRequest, error) {
req := &proto.HKeysRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeHLen(buf []byte) (*proto.HLenRequest, error) {
req := &proto.HLenRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeHSet(buf []byte) (*proto.HSetRequest, error) {
req := &proto.HSetRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeHSetX(buf []byte) (*proto.HSetXRequest, error) {
req := &proto.HSetXRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
2021-11-01 17:36:35 +08:00
func decodeSet(buf []byte) (*proto.SetRequest, error) {
req := &proto.SetRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeGet(buf []byte) (*proto.GetRequest, error) {
req := &proto.GetRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeAdd(buf []byte) (*proto.AddRequest, error) {
req := &proto.AddRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeReduce(buf []byte) (*proto.ReduceRequest, error) {
req := &proto.ReduceRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeSetnx(buf []byte) (*proto.SetnxRequest, error) {
req := &proto.SetnxRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeSetBit(buf []byte) (*proto.SetBitRequest, error) {
req := &proto.SetBitRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeGetBit(buf []byte) (*proto.GetBitRequest, error) {
req := &proto.GetBitRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeGetRange(buf []byte) (*proto.GetRangeRequest, error) {
req := &proto.GetRangeRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeGetSet(buf []byte) (*proto.GetSetRequest, error) {
req := &proto.GetSetRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
func decodeStrLen(buf []byte) (*proto.StrLenRequest, error) {
req := &proto.StrLenRequest{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}