chore(service): update gen service

This commit is contained in:
bandl 2021-11-01 17:36:35 +08:00
parent 27542cf898
commit 787003d95a
2 changed files with 366 additions and 0 deletions

View File

@ -0,0 +1,297 @@
// Code generated by gen-struct. DO NOT EDIT.
// make gen-service generated
package persisted
import (
"bytes"
"encoding/hex"
"fmt"
"gitee.com/timedb/wheatCache/pkg/errorx"
"gitee.com/timedb/wheatCache/pkg/proto"
protobuf "google.golang.org/protobuf/proto"
)
type codec struct {
}
func (c codec) Encode(method string, m protobuf.Message) ([]byte, error) {
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
}
func (c codec) Decode(buf []byte) (protobuf.Message, error) {
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)
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
}
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
}

69
storage/temp/aof.template Normal file
View File

@ -0,0 +1,69 @@
// Code generated by gen-struct. DO NOT EDIT.
// make gen-service generated
package persisted
import (
"bytes"
"encoding/hex"
"fmt"
"gitee.com/timedb/wheatCache/pkg/errorx"
"gitee.com/timedb/wheatCache/pkg/proto"
protobuf "google.golang.org/protobuf/proto"
)
type codec struct {
}
func (c codec) Encode(method string, m protobuf.Message) ([]byte, error) {
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
}
func (c codec) Decode(buf []byte) (protobuf.Message, error) {
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 {
{% for key in keys -%}
case "{{key.method}}":
return decode{{key.method}}(buf)
{% endfor %}
}
return nil, errorx.New("decode aof err, the method could not be resolved, method:%s", method)
}
{% for key in keys %}
func decode{{key.method}}(buf []byte) (*proto.{{key.method}}Request, error) {
req := &proto.{{key.method}}Request{}
err := protobuf.Unmarshal(buf, req)
if err != nil {
return nil, err
}
return req, nil
}
{% endfor %}