From 16a7aa9db52d252a9415254858ec0eebd016b3ee Mon Sep 17 00:00:00 2001 From: xubo Date: Wed, 5 Feb 2020 23:20:54 +0800 Subject: [PATCH 01/39] =?UTF-8?q?=E6=89=80=E6=9C=89=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=94=9F=E6=88=90meta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen/golang/func.go | 6 ++++++ gen/golang/text.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gen/golang/func.go b/gen/golang/func.go index bc95813..ddfa195 100644 --- a/gen/golang/func.go +++ b/gen/golang/func.go @@ -9,6 +9,12 @@ import ( var UsefulFunc = template.FuncMap{} func init() { + + // 所有结构生成Entry + UsefulFunc["GenEntry"] = func(d *model.Descriptor) bool { + return true + } + UsefulFunc["StructCodec"] = func(d *model.Descriptor) string { codecName := d.TagValueString("Codec") if codecName == "" { diff --git a/gen/golang/text.go b/gen/golang/text.go index 92966c3..7dfd7ac 100644 --- a/gen/golang/text.go +++ b/gen/golang/text.go @@ -112,7 +112,7 @@ func (self *{{.Name}}) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt pro func init() { {{if .RegEntry}} - {{range .Structs}} {{ if IsMessage . }} + {{range .Structs}} {{ if GenEntry . }} cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ Codec: codec.MustGetCodec("{{StructCodec .}}"), Type: reflect.TypeOf((*{{.Name}})(nil)).Elem(), From cb2b3e7685c47f4667a581a841eeb755b67fdf3c Mon Sep 17 00:00:00 2001 From: xubo Date: Mon, 17 Feb 2020 18:33:04 +0800 Subject: [PATCH 02/39] =?UTF-8?q?C#=E7=94=9F=E6=88=90=E7=9A=84=E5=8C=85?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen/csharp/text.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen/csharp/text.go b/gen/csharp/text.go index 4a44652..4d38196 100644 --- a/gen/csharp/text.go +++ b/gen/csharp/text.go @@ -7,7 +7,7 @@ using System; using System.Collections.Generic; using ProtoPlus; -namespace Proto +namespace {{.PackageName}} { {{range $a, $enumobj := .Enums}} public enum {{.Name}} From da38030299a1b58fbfba2ecd88d107f0754530bc Mon Sep 17 00:00:00 2001 From: davyxu Date: Mon, 25 May 2020 18:45:42 +0800 Subject: [PATCH 03/39] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8E=9F=E5=A7=8B?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=BA=8F=E5=88=97=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/csharp/Example/ProtoGen.cs | 122 +++++++++++- gen/golang/func.go | 18 +- gen/golang/text.go | 18 +- proto/api.go | 287 +++++++++++++++++++++++++++-- proto/buffer.go | 5 + proto/field_unmarshal.go | 96 ++++------ proto/slice_marshal.go | 1 - proto/slice_unmarshal.go | 155 ++++++++-------- tests/Make.sh | 2 +- tests/code.proto | 12 +- tests/code_gen.go | 230 ++++++++++++++++++----- tests/code_test.go | 71 +++++++ tests/pb_gen.proto | 18 +- 13 files changed, 820 insertions(+), 215 deletions(-) diff --git a/example/csharp/Example/ProtoGen.cs b/example/csharp/Example/ProtoGen.cs index 56a1cf2..18f473f 100644 --- a/example/csharp/Example/ProtoGen.cs +++ b/example/csharp/Example/ProtoGen.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using ProtoPlus; -namespace Proto +namespace proto { public enum MyEnum @@ -18,26 +18,44 @@ public enum MyEnum public partial class MyTypeMini : IProtoStruct { - public string Str; public bool Bool; + public int Int32; + public uint UInt32; + public long Int64; + public ulong UInt64; + public float Float32; + public double Float64; + public string Str; #region Serialize Code public void Init( ) { - + } public void Marshal(OutputStream stream) { - stream.WriteString(1, Str ); - stream.WriteBool(2, Bool ); + stream.WriteBool(1, Bool ); + stream.WriteInt32(2, Int32 ); + stream.WriteUInt32(3, UInt32 ); + stream.WriteInt64(4, Int64 ); + stream.WriteUInt64(5, UInt64 ); + stream.WriteFloat(6, Float32 ); + stream.WriteDouble(7, Float64 ); + stream.WriteString(8, Str ); } public int GetSize() { int size = 0; - size += OutputStream.SizeString(1, Str); - size += OutputStream.SizeBool(2, Bool); + size += OutputStream.SizeBool(1, Bool); + size += OutputStream.SizeInt32(2, Int32); + size += OutputStream.SizeUInt32(3, UInt32); + size += OutputStream.SizeInt64(4, Int64); + size += OutputStream.SizeUInt64(5, UInt64); + size += OutputStream.SizeFloat(6, Float32); + size += OutputStream.SizeDouble(7, Float64); + size += OutputStream.SizeString(8, Str); return size; } @@ -46,10 +64,28 @@ public bool Unmarshal(InputStream stream, int fieldNumber, WireFormat.WireType w switch (fieldNumber) { case 1: - stream.ReadString(wt, ref Str); + stream.ReadBool(wt, ref Bool); break; case 2: - stream.ReadBool(wt, ref Bool); + stream.ReadInt32(wt, ref Int32); + break; + case 3: + stream.ReadUInt32(wt, ref UInt32); + break; + case 4: + stream.ReadInt64(wt, ref Int64); + break; + case 5: + stream.ReadUInt64(wt, ref UInt64); + break; + case 6: + stream.ReadFloat(wt, ref Float32); + break; + case 7: + stream.ReadDouble(wt, ref Float64); + break; + case 8: + stream.ReadString(wt, ref Str); break; default: return true; @@ -385,6 +421,72 @@ public bool Unmarshal(InputStream stream, int fieldNumber, WireFormat.WireType w #endregion } + + public partial class LoginREQ : IProtoStruct + { + + #region Serialize Code + public void Init( ) + { + + } + + public void Marshal(OutputStream stream) + { + } + + public int GetSize() + { + int size = 0; + return size; + } + + public bool Unmarshal(InputStream stream, int fieldNumber, WireFormat.WireType wt) + { + switch (fieldNumber) + { + default: + return true; + } + + return false; + } + #endregion + } + + + public partial class LoginACK : IProtoStruct + { + + #region Serialize Code + public void Init( ) + { + + } + + public void Marshal(OutputStream stream) + { + } + + public int GetSize() + { + int size = 0; + return size; + } + + public bool Unmarshal(InputStream stream, int fieldNumber, WireFormat.WireType wt) + { + switch (fieldNumber) + { + default: + return true; + } + + return false; + } + #endregion + } + public static class MessageMetaRegister @@ -404,7 +506,7 @@ public static void RegisterGeneratedMeta(MessageMeta meta) ID = 9980, SourcePeer = "", TargetPeer = "", - }); + }); } } diff --git a/gen/golang/func.go b/gen/golang/func.go index ddfa195..eac6b0d 100644 --- a/gen/golang/func.go +++ b/gen/golang/func.go @@ -31,10 +31,13 @@ func init() { ret += "[]" } - // 默认指针 - //if fd.Kind == model.Kind_Struct { - // ret += "*" - //} + ret += codegen.GoTypeName(fd) + return + } + + UsefulFunc["ProtoElementTypeName"] = func(raw interface{}) (ret string) { + + fd := raw.(*model.FieldDescriptor) ret += codegen.GoTypeName(fd) return @@ -54,6 +57,13 @@ func init() { return !fd.Repeatd && fd.Kind == model.Kind_Struct } + UsefulFunc["IsSlice"] = func(raw interface{}) bool { + + fd := raw.(*model.FieldDescriptor) + + return fd.Repeatd + } + UsefulFunc["IsEnum"] = func(raw interface{}) bool { fd := raw.(*model.FieldDescriptor) diff --git a/gen/golang/text.go b/gen/golang/text.go index 7dfd7ac..2f3243e 100644 --- a/gen/golang/text.go +++ b/gen/golang/text.go @@ -99,9 +99,21 @@ func (self *{{.Name}}) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt pro self.{{GoFieldName .}} = append(self.{{GoFieldName .}}, elm) return nil }{{else if IsEnum .}} - return proto.Unmarshal{{CodecName .}}(buffer, wt, (*int32)(&self.{{GoFieldName .}})) {{else if IsEnumSlice .}} - return proto.Unmarshal{{CodecName .}}(buffer, wt, (*[]int32)(unsafe.Pointer(&self.{{GoFieldName .}}))) {{else}} - return proto.Unmarshal{{CodecName .}}(buffer, wt, &self.{{GoFieldName .}}) {{end}} + v, err := proto.Unmarshal{{CodecName .}}(buffer, wt) + self.{{GoFieldName .}} = {{ProtoTypeName .}}(v) + return err {{else if IsStruct .}} + return proto.Unmarshal{{CodecName .}}(buffer, wt, &self.{{GoFieldName .}}) {{else if IsEnumSlice .}} + v, err := proto.Unmarshal{{CodecName .}}(buffer, wt) + for _, vv := range v { + self.{{GoFieldName .}} = append(self.{{GoFieldName .}}, {{ProtoElementTypeName .}}(vv)) + } + return err {{else if IsSlice .}} + v, err := proto.Unmarshal{{CodecName .}}(buffer, wt) + self.{{GoFieldName .}} = append(self.{{GoFieldName .}}, v...) + return err {{else}} + v, err := proto.Unmarshal{{CodecName .}}(buffer, wt) + self.{{GoFieldName .}} = v + return err{{end}} {{end}} } diff --git a/proto/api.go b/proto/api.go index 06e1cc6..524421c 100644 --- a/proto/api.go +++ b/proto/api.go @@ -1,5 +1,10 @@ package proto +import ( + "errors" + "reflect" +) + type Struct interface { Marshal(buffer *Buffer) error @@ -8,22 +13,42 @@ type Struct interface { Size() int } +const ( + TopFieldIndex = 7 +) + func Marshal(raw interface{}) ([]byte, error) { - msg := raw.(Struct) + switch msg := raw.(type) { + case Struct: + l := msg.Size() - l := msg.Size() + data := make([]byte, 0, l) - data := make([]byte, 0, l) + buffer := NewBuffer(data) - buffer := NewBuffer(data) + err := msg.Marshal(buffer) + if err != nil { + return nil, err + } + + return buffer.Bytes(), nil + default: + size, err := sizeTypes(TopFieldIndex, raw) + if err != nil { + return nil, err + } + + b := NewBufferBySize(size) - err := msg.Marshal(buffer) - if err != nil { - return nil, err + err = marshalTypes(b, TopFieldIndex, raw) + if err != nil { + return nil, err + } + + return b.Bytes(), nil } - return buffer.Bytes(), nil } func Size(raw interface{}) int { @@ -34,10 +59,250 @@ func Size(raw interface{}) int { func Unmarshal(data []byte, raw interface{}) (err error) { - msg := raw.(Struct) - buffer := NewBuffer(data) - return rawUnmarshalStruct(buffer, msg) + switch msg := raw.(type) { + case Struct: + return rawUnmarshalStruct(buffer, msg) + default: + + for buffer.BytesRemains() > 0 { + wireTag, err := buffer.DecodeVarint() + + if err != nil { + return err + } + + fieldIndex, wt := parseWireTag(wireTag) + if fieldIndex != TopFieldIndex { + return errors.New("invalid top field tag") + } + + err = unmarshalTypes(buffer, wt, raw) + if err != nil { + return err + } + } + + return nil + + } +} + +func sizeTypes(fieldIndex uint64, raw interface{}) (size int, err error) { + switch v := raw.(type) { + case Struct: + return SizeStruct(fieldIndex, v), nil + case int32: + return SizeInt32(fieldIndex, v), nil + case int64: + return SizeInt64(fieldIndex, v), nil + case uint32: + return SizeUInt32(fieldIndex, v), nil + case uint64: + return SizeUInt64(fieldIndex, v), nil + case float32: + return SizeFloat32(fieldIndex, v), nil + case float64: + return SizeFloat64(fieldIndex, v), nil + case bool: + return SizeBool(fieldIndex, v), nil + case string: + return SizeString(fieldIndex, v), nil + case []byte: + return SizeBytes(fieldIndex, v), nil + case []int32: + return SizeInt32Slice(fieldIndex, v), nil + case []int64: + return SizeInt64Slice(fieldIndex, v), nil + case []uint32: + return SizeUInt32Slice(fieldIndex, v), nil + case []uint64: + return SizeUInt64Slice(fieldIndex, v), nil + case []float32: + return SizeFloat32Slice(fieldIndex, v), nil + case []float64: + return SizeFloat64Slice(fieldIndex, v), nil + case []bool: + return SizeBoolSlice(fieldIndex, v), nil + case []string: + return SizeStringSlice(fieldIndex, v), nil + } + + tRaw := reflect.TypeOf(raw) + switch tRaw.Kind() { + case reflect.Array, reflect.Slice: + + vRaw := reflect.ValueOf(raw) + for i := 0; i < vRaw.Len(); i++ { + vElement := vRaw.Index(i) + var thisSize int + thisSize, err = sizeTypes(fieldIndex, vElement.Interface()) + if err != nil { + return 0, err + } + + size += thisSize + } + return + + default: + return 0, errors.New("unsupport type: " + tRaw.Kind().String()) + } +} + +func unmarshalTypes(buffer *Buffer, wt WireType, raw interface{}) error { + switch v := raw.(type) { + case Struct: + return UnmarshalStruct(buffer, wt, v) + case *int32: + vv, err := UnmarshalInt32(buffer, wt) + *v = vv + return err + case *int64: + vv, err := UnmarshalInt64(buffer, wt) + *v = vv + return err + case *uint32: + vv, err := UnmarshalUInt32(buffer, wt) + *v = vv + return err + case *uint64: + vv, err := UnmarshalUInt64(buffer, wt) + *v = vv + return err + case *float32: + vv, err := UnmarshalFloat32(buffer, wt) + *v = vv + return err + case *float64: + vv, err := UnmarshalFloat64(buffer, wt) + *v = vv + return err + case *bool: + vv, err := UnmarshalBool(buffer, wt) + *v = vv + return err + case *string: + vv, err := UnmarshalString(buffer, wt) + *v = vv + return err + case *[]byte: + vv, err := UnmarshalBytes(buffer, wt) + *v = append(*v, vv...) + return err + case *[]int32: + vv, err := UnmarshalInt32Slice(buffer, wt) + *v = append(*v, vv...) + return err + case *[]int64: + vv, err := UnmarshalInt64Slice(buffer, wt) + *v = append(*v, vv...) + return err + case *[]uint32: + vv, err := UnmarshalUInt32Slice(buffer, wt) + *v = append(*v, vv...) + return err + case *[]uint64: + vv, err := UnmarshalUInt64Slice(buffer, wt) + *v = append(*v, vv...) + return err + case *[]float32: + vv, err := UnmarshalFloat32Slice(buffer, wt) + *v = append(*v, vv...) + return err + case *[]float64: + vv, err := UnmarshalFloat64Slice(buffer, wt) + *v = append(*v, vv...) + return err + case *[]bool: + vv, err := UnmarshalBoolSlice(buffer, wt) + *v = append(*v, vv...) + return err + case *[]string: + vv, err := UnmarshalStringSlice(buffer, wt) + *v = append(*v, vv...) + return err + } + + tRaw := reflect.TypeOf(raw) + switch tRaw.Kind() { + case reflect.Array, reflect.Slice: + + vRaw := reflect.ValueOf(raw) + + vElement := reflect.New(reflect.TypeOf(raw).Elem()) + err := unmarshalTypes(buffer, wt, vElement.Interface()) + if err != nil { + return err + } + + vRaw.Set(reflect.AppendSlice(vRaw, vElement)) + + return nil + default: + return errors.New("unsupport type: " + tRaw.Kind().String()) + } +} + +func marshalTypes(buffer *Buffer, fieldIndex uint64, raw interface{}) error { + + switch v := raw.(type) { + case Struct: + return MarshalStruct(buffer, fieldIndex, v) + case int32: + return MarshalInt32(buffer, fieldIndex, v) + case int64: + return MarshalInt64(buffer, fieldIndex, v) + case uint32: + return MarshalUInt32(buffer, fieldIndex, v) + case uint64: + return MarshalUInt64(buffer, fieldIndex, v) + case float32: + return MarshalFloat32(buffer, fieldIndex, v) + case float64: + return MarshalFloat64(buffer, fieldIndex, v) + case bool: + return MarshalBool(buffer, fieldIndex, v) + case string: + return MarshalString(buffer, fieldIndex, v) + case []byte: + return MarshalBytes(buffer, fieldIndex, v) + case []int32: + return MarshalInt32Slice(buffer, fieldIndex, v) + case []int64: + return MarshalInt64Slice(buffer, fieldIndex, v) + case []uint32: + return MarshalUInt32Slice(buffer, fieldIndex, v) + case []uint64: + return MarshalUInt64Slice(buffer, fieldIndex, v) + case []float32: + return MarshalFloat32Slice(buffer, fieldIndex, v) + case []float64: + return MarshalFloat64Slice(buffer, fieldIndex, v) + case []bool: + return MarshalBoolSlice(buffer, fieldIndex, v) + case []string: + return MarshalStringSlice(buffer, fieldIndex, v) + } + + tRaw := reflect.TypeOf(raw) + switch tRaw.Kind() { + case reflect.Array, reflect.Slice: + + vRaw := reflect.ValueOf(raw) + + for i := 0; i < vRaw.Len(); i++ { + vElement := vRaw.Index(i) + err := marshalTypes(buffer, fieldIndex, vElement.Interface()) + if err != nil { + return err + } + } + + return nil + default: + return errors.New("unsupport type: " + tRaw.Kind().String()) + } } diff --git a/proto/buffer.go b/proto/buffer.go index 4a85a5a..716326d 100644 --- a/proto/buffer.go +++ b/proto/buffer.go @@ -22,6 +22,11 @@ func NewBuffer(e []byte) *Buffer { return &Buffer{buf: e} } +func NewBufferBySize(size int) *Buffer { + data := make([]byte, 0, size) + return NewBuffer(data) +} + // Reset resets the Buffer, ready for marshaling a new protocol buffer. func (self *Buffer) Reset() { self.buf = self.buf[0:0] // for reading/writing diff --git a/proto/field_unmarshal.go b/proto/field_unmarshal.go index 74054f0..7795428 100644 --- a/proto/field_unmarshal.go +++ b/proto/field_unmarshal.go @@ -5,154 +5,136 @@ import ( "math" ) -func UnmarshalBool(b *Buffer, wt WireType, ret *bool) error { +func UnmarshalBool(b *Buffer, wt WireType) (bool, error) { switch wt { case WireVarint: v, err := b.DecodeVarint() if err != nil { - return err - } - - if v != 0 { - *ret = true - } else { - *ret = false + return false, err } + return v != 0, nil default: - return ErrBadWireType + return false, ErrBadWireType } - - return nil } -func UnmarshalInt32(b *Buffer, wt WireType, ret *int32) error { +func UnmarshalInt32(b *Buffer, wt WireType) (int32, error) { switch wt { case WireVarint: v, err := b.DecodeVarint() if err != nil { - return err + return 0, err } - *ret = int32(v) + return int32(v), nil case WireFixed32: v, err := b.DecodeFixed32() if err != nil { - break + return 0, err } - *ret = int32(v) + return int32(v), nil + default: - return ErrBadWireType + return 0, ErrBadWireType } - - return nil } -func UnmarshalUInt32(b *Buffer, wt WireType, ret *uint32) error { +func UnmarshalUInt32(b *Buffer, wt WireType) (uint32, error) { switch wt { case WireVarint: v, err := b.DecodeVarint() if err != nil { - return err + return 0, err } - *ret = uint32(v) + + return uint32(v), nil default: - return ErrBadWireType + return 0, ErrBadWireType } - - return nil } -func UnmarshalInt64(b *Buffer, wt WireType, ret *int64) error { +func UnmarshalInt64(b *Buffer, wt WireType) (int64, error) { switch wt { case WireVarint: v, err := b.DecodeVarint() if err != nil { - return err + return 0, err } - *ret = int64(v) + return int64(v), nil case WireFixed64: v, err := b.DecodeFixed64() if err != nil { - break + return 0, err } - *ret = int64(v) + return int64(v), nil default: - return ErrBadWireType + return 0, ErrBadWireType } - - return nil } -func UnmarshalUInt64(b *Buffer, wt WireType, ret *uint64) error { +func UnmarshalUInt64(b *Buffer, wt WireType) (uint64, error) { switch wt { case WireVarint: v, err := b.DecodeVarint() if err != nil { - return err + return 0, err } - *ret = v + return v, nil default: - return ErrBadWireType + return 0, ErrBadWireType } - - return nil } -func UnmarshalFloat32(b *Buffer, wt WireType, ret *float32) error { +func UnmarshalFloat32(b *Buffer, wt WireType) (float32, error) { switch wt { case WireFixed32: v, err := b.DecodeFixed32() if err != nil { - return err + return 0, err } - *ret = math.Float32frombits(uint32(v)) + return math.Float32frombits(uint32(v)), nil default: - return ErrBadWireType + return 0, ErrBadWireType } - return nil } -func UnmarshalFloat64(b *Buffer, wt WireType, ret *float64) error { +func UnmarshalFloat64(b *Buffer, wt WireType) (float64, error) { switch wt { case WireFixed64: v, err := b.DecodeFixed64() if err != nil { - return err + return 0, err } - *ret = math.Float64frombits(uint64(v)) + return math.Float64frombits(uint64(v)), nil default: - return ErrBadWireType + return 0, ErrBadWireType } - - return nil } -func UnmarshalString(b *Buffer, wt WireType, ret *string) error { +func UnmarshalString(b *Buffer, wt WireType) (string, error) { switch wt { case WireBytes: v, err := b.DecodeStringBytes() if err != nil { - return err + return "", err } - *ret = v + return v, nil default: - return ErrBadWireType + return "", ErrBadWireType } - - return nil } func skipField(b *Buffer, wt WireType) error { @@ -185,8 +167,6 @@ func skipField(b *Buffer, wt WireType) error { default: return ErrBadWireType } - - return nil } func rawUnmarshalStruct(b *Buffer, msg Struct) error { diff --git a/proto/slice_marshal.go b/proto/slice_marshal.go index 3af4e3b..73bf8e1 100644 --- a/proto/slice_marshal.go +++ b/proto/slice_marshal.go @@ -13,7 +13,6 @@ func MarshalBytes(b *Buffer, fieldIndex uint64, value []byte) error { b.EncodeVarint(makeWireTag(fieldIndex, WireBytes)) - // 因为bool每一个value都是1个字节,size=1*count b.EncodeVarint(uint64(size)) b.buf = append(b.buf, value...) diff --git a/proto/slice_unmarshal.go b/proto/slice_unmarshal.go index cb291a7..35909ec 100644 --- a/proto/slice_unmarshal.go +++ b/proto/slice_unmarshal.go @@ -2,264 +2,265 @@ package proto import "io" -func UnmarshalBytes(b *Buffer, wt WireType, ret *[]byte) error { +func UnmarshalBytes(b *Buffer, wt WireType) ([]byte, error) { switch wt { case WireBytes: size, err := b.DecodeVarint() if err != nil { - return err + return nil, err } if b.BytesRemains() < int(size) { - return io.ErrUnexpectedEOF + return nil, io.ErrUnexpectedEOF } - *ret = append(*ret, b.ConsumeBytes(int(size))...) + return b.ConsumeBytes(int(size)), nil default: - return ErrBadWireType + return nil, ErrBadWireType } - - return nil } -func UnmarshalBoolSlice(b *Buffer, wt WireType, ret *[]bool) error { +func UnmarshalBoolSlice(b *Buffer, wt WireType) ([]bool, error) { switch wt { case WireBytes: count, err := b.DecodeVarint() if err != nil { - return err + return nil, err } if b.BytesRemains() < int(int(count)) { - return io.ErrUnexpectedEOF + return nil, io.ErrUnexpectedEOF } + var ret []bool for _, element := range b.ConsumeBytes(int(count)) { switch element { case 0: - *ret = append(*ret, false) + ret = append(ret, false) case 1: - *ret = append(*ret, true) + ret = append(ret, true) default: - return ErrBadBoolValue + return nil, ErrBadBoolValue } - } + return ret, nil + default: - return ErrBadWireType + return nil, ErrBadWireType } - - return nil } -func UnmarshalInt32Slice(b *Buffer, wt WireType, ret *[]int32) error { +func UnmarshalInt32Slice(b *Buffer, wt WireType) ([]int32, error) { switch wt { case WireBytes: size, err := b.DecodeVarint() if err != nil { - return err + return nil, err } if b.BytesRemains() < int(size) { - return io.ErrUnexpectedEOF + return nil, io.ErrUnexpectedEOF } limitBuffer := NewBuffer(b.ConsumeBytes(int(size))) + var ret []int32 for limitBuffer.BytesRemains() > 0 { var element int32 - err = UnmarshalInt32(limitBuffer, WireVarint, &element) + element, err = UnmarshalInt32(limitBuffer, WireVarint) if err != nil { - return err + return nil, err } - *ret = append(*ret, element) + ret = append(ret, element) } + return ret, nil + default: - return ErrBadWireType + return nil, ErrBadWireType } - - return nil } -func UnmarshalUInt32Slice(b *Buffer, wt WireType, ret *[]uint32) error { +func UnmarshalUInt32Slice(b *Buffer, wt WireType) ([]uint32, error) { switch wt { case WireBytes: size, err := b.DecodeVarint() if err != nil { - return err + return nil, err } if b.BytesRemains() < int(size) { - return io.ErrUnexpectedEOF + return nil, io.ErrUnexpectedEOF } limitBuffer := NewBuffer(b.ConsumeBytes(int(size))) + var ret []uint32 for limitBuffer.BytesRemains() > 0 { var element uint32 - err = UnmarshalUInt32(limitBuffer, WireVarint, &element) + element, err = UnmarshalUInt32(limitBuffer, WireVarint) if err != nil { - return err + return nil, err } - *ret = append(*ret, element) + ret = append(ret, element) } + return ret, nil + default: - return ErrBadWireType + return nil, ErrBadWireType } - - return nil } -func UnmarshalInt64Slice(b *Buffer, wt WireType, ret *[]int64) error { +func UnmarshalInt64Slice(b *Buffer, wt WireType) ([]int64, error) { switch wt { case WireBytes: size, err := b.DecodeVarint() if err != nil { - return err + return nil, err } if b.BytesRemains() < int(size) { - return io.ErrUnexpectedEOF + return nil, io.ErrUnexpectedEOF } limitBuffer := NewBuffer(b.ConsumeBytes(int(size))) + var ret []int64 for limitBuffer.BytesRemains() > 0 { var element int64 - err = UnmarshalInt64(limitBuffer, WireVarint, &element) + element, err = UnmarshalInt64(limitBuffer, WireVarint) if err != nil { - return err + return nil, err } - *ret = append(*ret, element) + ret = append(ret, element) } + return ret, nil default: - return ErrBadWireType + return nil, ErrBadWireType } - - return nil } -func UnmarshalUInt64Slice(b *Buffer, wt WireType, ret *[]uint64) error { +func UnmarshalUInt64Slice(b *Buffer, wt WireType) ([]uint64, error) { switch wt { case WireBytes: size, err := b.DecodeVarint() if err != nil { - return err + return nil, err } if b.BytesRemains() < int(size) { - return io.ErrUnexpectedEOF + return nil, io.ErrUnexpectedEOF } limitBuffer := NewBuffer(b.ConsumeBytes(int(size))) + var ret []uint64 for limitBuffer.BytesRemains() > 0 { var element uint64 - err = UnmarshalUInt64(limitBuffer, WireVarint, &element) + element, err = UnmarshalUInt64(limitBuffer, WireVarint) if err != nil { - return err + return nil, err } - *ret = append(*ret, element) + ret = append(ret, element) } + return ret, nil + default: - return ErrBadWireType + return nil, ErrBadWireType } - - return nil } -func UnmarshalStringSlice(b *Buffer, wt WireType, ret *[]string) error { +func UnmarshalStringSlice(b *Buffer, wt WireType) ([]string, error) { switch wt { case WireBytes: v, err := b.DecodeStringBytes() if err != nil { - return err + return nil, err } - *ret = append(*ret, v) + return []string{v}, nil default: - return ErrBadWireType + return nil, ErrBadWireType } - - return nil } -func UnmarshalFloat32Slice(b *Buffer, wt WireType, ret *[]float32) error { +func UnmarshalFloat32Slice(b *Buffer, wt WireType) ([]float32, error) { switch wt { case WireBytes: size, err := b.DecodeVarint() if err != nil { - return err + return nil, err } if b.BytesRemains() < int(size) { - return io.ErrUnexpectedEOF + return nil, io.ErrUnexpectedEOF } limitBuffer := NewBuffer(b.ConsumeBytes(int(size))) + var ret []float32 for limitBuffer.BytesRemains() > 0 { var element float32 - err = UnmarshalFloat32(limitBuffer, WireFixed32, &element) + element, err = UnmarshalFloat32(limitBuffer, WireFixed32) if err != nil { - return err + return nil, err } - *ret = append(*ret, element) + ret = append(ret, element) } + return ret, nil + default: - return ErrBadWireType + return nil, ErrBadWireType } - - return nil } -func UnmarshalFloat64Slice(b *Buffer, wt WireType, ret *[]float64) error { +func UnmarshalFloat64Slice(b *Buffer, wt WireType) ([]float64, error) { switch wt { case WireBytes: size, err := b.DecodeVarint() if err != nil { - return err + return nil, err } if b.BytesRemains() < int(size) { - return io.ErrUnexpectedEOF + return nil, io.ErrUnexpectedEOF } limitBuffer := NewBuffer(b.ConsumeBytes(int(size))) + var ret []float64 for limitBuffer.BytesRemains() > 0 { var element float64 - err = UnmarshalFloat64(limitBuffer, WireFixed64, &element) + element, err = UnmarshalFloat64(limitBuffer, WireFixed64) if err != nil { - return err + return nil, err } - *ret = append(*ret, element) + ret = append(ret, element) } + return ret, nil + default: - return ErrBadWireType + return nil, ErrBadWireType } - - return nil } diff --git a/tests/Make.sh b/tests/Make.sh index 549b550..8b76c54 100644 --- a/tests/Make.sh +++ b/tests/Make.sh @@ -8,5 +8,5 @@ go build -v -o=${GOPATH}/bin/protoplus github.com/davyxu/protoplus # code.proto为输入文件 ${GOPATH}/bin/protoplus -go_out=code_gen.go -package=tests code.proto -${GOPATH}/bin/protoplus -cs_out=../csharp/Example/ProtoGen.cs -genreg -package=proto code.proto +${GOPATH}/bin/protoplus -cs_out=../example/csharp/Example/ProtoGen.cs -genreg -package=proto code.proto ${GOPATH}/bin/protoplus -pb_out=pb_gen.proto -package=proto code.proto \ No newline at end of file diff --git a/tests/code.proto b/tests/code.proto index c1d76ed..0ec611f 100644 --- a/tests/code.proto +++ b/tests/code.proto @@ -1,7 +1,15 @@ struct MyTypeMini { - Str string - Bool bool + Bool bool + Int32 int32 + UInt32 uint32 + + Int64 int64 + UInt64 uint64 + + Float32 float32 + Float64 float64 + Str string } enum MyEnum diff --git a/tests/code_gen.go b/tests/code_gen.go index bd2ec6a..bb327c3 100644 --- a/tests/code_gen.go +++ b/tests/code_gen.go @@ -39,26 +39,56 @@ func (self MyEnum) String() string { } type MyTypeMini struct { - Str string - Bool bool + Bool bool + Int32 int32 + UInt32 uint32 + Int64 int64 + UInt64 uint64 + Float32 float32 + Float64 float64 + Str string } func (self *MyTypeMini) String() string { return proto.CompactTextString(self) } func (self *MyTypeMini) Size() (ret int) { - ret += proto.SizeString(1, self.Str) + ret += proto.SizeBool(1, self.Bool) + + ret += proto.SizeInt32(2, self.Int32) + + ret += proto.SizeUInt32(3, self.UInt32) + + ret += proto.SizeInt64(4, self.Int64) + + ret += proto.SizeUInt64(5, self.UInt64) - ret += proto.SizeBool(2, self.Bool) + ret += proto.SizeFloat32(6, self.Float32) + + ret += proto.SizeFloat64(7, self.Float64) + + ret += proto.SizeString(8, self.Str) return } func (self *MyTypeMini) Marshal(buffer *proto.Buffer) error { - proto.MarshalString(buffer, 1, self.Str) + proto.MarshalBool(buffer, 1, self.Bool) + + proto.MarshalInt32(buffer, 2, self.Int32) + + proto.MarshalUInt32(buffer, 3, self.UInt32) + + proto.MarshalInt64(buffer, 4, self.Int64) + + proto.MarshalUInt64(buffer, 5, self.UInt64) + + proto.MarshalFloat32(buffer, 6, self.Float32) + + proto.MarshalFloat64(buffer, 7, self.Float64) - proto.MarshalBool(buffer, 2, self.Bool) + proto.MarshalString(buffer, 8, self.Str) return nil } @@ -66,9 +96,37 @@ func (self *MyTypeMini) Marshal(buffer *proto.Buffer) error { func (self *MyTypeMini) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt proto.WireType) error { switch fieldIndex { case 1: - return proto.UnmarshalString(buffer, wt, &self.Str) + v, err := proto.UnmarshalBool(buffer, wt) + self.Bool = v + return err case 2: - return proto.UnmarshalBool(buffer, wt, &self.Bool) + v, err := proto.UnmarshalInt32(buffer, wt) + self.Int32 = v + return err + case 3: + v, err := proto.UnmarshalUInt32(buffer, wt) + self.UInt32 = v + return err + case 4: + v, err := proto.UnmarshalInt64(buffer, wt) + self.Int64 = v + return err + case 5: + v, err := proto.UnmarshalUInt64(buffer, wt) + self.UInt64 = v + return err + case 6: + v, err := proto.UnmarshalFloat32(buffer, wt) + self.Float32 = v + return err + case 7: + v, err := proto.UnmarshalFloat64(buffer, wt) + self.Float64 = v + return err + case 8: + v, err := proto.UnmarshalString(buffer, wt) + self.Str = v + return err } @@ -188,43 +246,83 @@ func (self *MySubType) Marshal(buffer *proto.Buffer) error { func (self *MySubType) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt proto.WireType) error { switch fieldIndex { case 1: - return proto.UnmarshalBool(buffer, wt, &self.Bool) + v, err := proto.UnmarshalBool(buffer, wt) + self.Bool = v + return err case 2: - return proto.UnmarshalInt32(buffer, wt, &self.Int32) + v, err := proto.UnmarshalInt32(buffer, wt) + self.Int32 = v + return err case 3: - return proto.UnmarshalUInt32(buffer, wt, &self.UInt32) + v, err := proto.UnmarshalUInt32(buffer, wt) + self.UInt32 = v + return err case 4: - return proto.UnmarshalInt64(buffer, wt, &self.Int64) + v, err := proto.UnmarshalInt64(buffer, wt) + self.Int64 = v + return err case 5: - return proto.UnmarshalUInt64(buffer, wt, &self.UInt64) + v, err := proto.UnmarshalUInt64(buffer, wt) + self.UInt64 = v + return err case 6: - return proto.UnmarshalFloat32(buffer, wt, &self.Float32) + v, err := proto.UnmarshalFloat32(buffer, wt) + self.Float32 = v + return err case 7: - return proto.UnmarshalFloat64(buffer, wt, &self.Float64) + v, err := proto.UnmarshalFloat64(buffer, wt) + self.Float64 = v + return err case 8: - return proto.UnmarshalString(buffer, wt, &self.Str) + v, err := proto.UnmarshalString(buffer, wt) + self.Str = v + return err case 9: - return proto.UnmarshalBytes(buffer, wt, &self.BytesSlice) + v, err := proto.UnmarshalBytes(buffer, wt) + self.BytesSlice = v + return err case 10: - return proto.UnmarshalBoolSlice(buffer, wt, &self.BoolSlice) + v, err := proto.UnmarshalBoolSlice(buffer, wt) + self.BoolSlice = append(self.BoolSlice, v...) + return err case 11: - return proto.UnmarshalInt32Slice(buffer, wt, &self.Int32Slice) + v, err := proto.UnmarshalInt32Slice(buffer, wt) + self.Int32Slice = append(self.Int32Slice, v...) + return err case 12: - return proto.UnmarshalUInt32Slice(buffer, wt, &self.UInt32Slice) + v, err := proto.UnmarshalUInt32Slice(buffer, wt) + self.UInt32Slice = append(self.UInt32Slice, v...) + return err case 13: - return proto.UnmarshalInt64Slice(buffer, wt, &self.Int64Slice) + v, err := proto.UnmarshalInt64Slice(buffer, wt) + self.Int64Slice = append(self.Int64Slice, v...) + return err case 14: - return proto.UnmarshalUInt64Slice(buffer, wt, &self.UInt64Slice) + v, err := proto.UnmarshalUInt64Slice(buffer, wt) + self.UInt64Slice = append(self.UInt64Slice, v...) + return err case 15: - return proto.UnmarshalFloat32Slice(buffer, wt, &self.Float32Slice) + v, err := proto.UnmarshalFloat32Slice(buffer, wt) + self.Float32Slice = append(self.Float32Slice, v...) + return err case 16: - return proto.UnmarshalFloat64Slice(buffer, wt, &self.Float64Slice) + v, err := proto.UnmarshalFloat64Slice(buffer, wt) + self.Float64Slice = append(self.Float64Slice, v...) + return err case 17: - return proto.UnmarshalStringSlice(buffer, wt, &self.StrSlice) + v, err := proto.UnmarshalStringSlice(buffer, wt) + self.StrSlice = append(self.StrSlice, v...) + return err case 18: - return proto.UnmarshalInt32(buffer, wt, (*int32)(&self.Enum)) + v, err := proto.UnmarshalInt32(buffer, wt) + self.Enum = MyEnum(v) + return err case 19: - return proto.UnmarshalInt32Slice(buffer, wt, (*[]int32)(unsafe.Pointer(&self.EnumSlice))) + v, err := proto.UnmarshalInt32Slice(buffer, wt) + for _, vv := range v { + self.EnumSlice = append(self.EnumSlice, MyEnum(vv)) + } + return err } @@ -360,41 +458,75 @@ func (self *MyType) Marshal(buffer *proto.Buffer) error { func (self *MyType) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt proto.WireType) error { switch fieldIndex { case 1: - return proto.UnmarshalBool(buffer, wt, &self.Bool) + v, err := proto.UnmarshalBool(buffer, wt) + self.Bool = v + return err case 2: - return proto.UnmarshalInt32(buffer, wt, &self.Int32) + v, err := proto.UnmarshalInt32(buffer, wt) + self.Int32 = v + return err case 3: - return proto.UnmarshalUInt32(buffer, wt, &self.UInt32) + v, err := proto.UnmarshalUInt32(buffer, wt) + self.UInt32 = v + return err case 4: - return proto.UnmarshalInt64(buffer, wt, &self.Int64) + v, err := proto.UnmarshalInt64(buffer, wt) + self.Int64 = v + return err case 5: - return proto.UnmarshalUInt64(buffer, wt, &self.UInt64) + v, err := proto.UnmarshalUInt64(buffer, wt) + self.UInt64 = v + return err case 6: - return proto.UnmarshalFloat32(buffer, wt, &self.Float32) + v, err := proto.UnmarshalFloat32(buffer, wt) + self.Float32 = v + return err case 7: - return proto.UnmarshalFloat64(buffer, wt, &self.Float64) + v, err := proto.UnmarshalFloat64(buffer, wt) + self.Float64 = v + return err case 8: - return proto.UnmarshalString(buffer, wt, &self.Str) + v, err := proto.UnmarshalString(buffer, wt) + self.Str = v + return err case 9: return proto.UnmarshalStruct(buffer, wt, &self.Struct) case 10: - return proto.UnmarshalBytes(buffer, wt, &self.BytesSlice) + v, err := proto.UnmarshalBytes(buffer, wt) + self.BytesSlice = v + return err case 11: - return proto.UnmarshalBoolSlice(buffer, wt, &self.BoolSlice) + v, err := proto.UnmarshalBoolSlice(buffer, wt) + self.BoolSlice = append(self.BoolSlice, v...) + return err case 12: - return proto.UnmarshalInt32Slice(buffer, wt, &self.Int32Slice) + v, err := proto.UnmarshalInt32Slice(buffer, wt) + self.Int32Slice = append(self.Int32Slice, v...) + return err case 13: - return proto.UnmarshalUInt32Slice(buffer, wt, &self.UInt32Slice) + v, err := proto.UnmarshalUInt32Slice(buffer, wt) + self.UInt32Slice = append(self.UInt32Slice, v...) + return err case 14: - return proto.UnmarshalInt64Slice(buffer, wt, &self.Int64Slice) + v, err := proto.UnmarshalInt64Slice(buffer, wt) + self.Int64Slice = append(self.Int64Slice, v...) + return err case 15: - return proto.UnmarshalUInt64Slice(buffer, wt, &self.UInt64Slice) + v, err := proto.UnmarshalUInt64Slice(buffer, wt) + self.UInt64Slice = append(self.UInt64Slice, v...) + return err case 16: - return proto.UnmarshalFloat32Slice(buffer, wt, &self.Float32Slice) + v, err := proto.UnmarshalFloat32Slice(buffer, wt) + self.Float32Slice = append(self.Float32Slice, v...) + return err case 17: - return proto.UnmarshalFloat64Slice(buffer, wt, &self.Float64Slice) + v, err := proto.UnmarshalFloat64Slice(buffer, wt) + self.Float64Slice = append(self.Float64Slice, v...) + return err case 18: - return proto.UnmarshalStringSlice(buffer, wt, &self.StrSlice) + v, err := proto.UnmarshalStringSlice(buffer, wt) + self.StrSlice = append(self.StrSlice, v...) + return err case 19: var elm MySubType if err := proto.UnmarshalStruct(buffer, wt, &elm); err != nil { @@ -404,9 +536,15 @@ func (self *MyType) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt proto. return nil } case 20: - return proto.UnmarshalInt32(buffer, wt, (*int32)(&self.Enum)) + v, err := proto.UnmarshalInt32(buffer, wt) + self.Enum = MyEnum(v) + return err case 21: - return proto.UnmarshalInt32Slice(buffer, wt, (*[]int32)(unsafe.Pointer(&self.EnumSlice))) + v, err := proto.UnmarshalInt32Slice(buffer, wt) + for _, vv := range v { + self.EnumSlice = append(self.EnumSlice, MyEnum(vv)) + } + return err } diff --git a/tests/code_test.go b/tests/code_test.go index ed5cdb9..ed31753 100644 --- a/tests/code_test.go +++ b/tests/code_test.go @@ -98,5 +98,76 @@ func TestIntSlice(t *testing.T) { input.Int32Slice = []int32{-1, 1, 2} verify(t, &input) +} + +func testVariant(t *testing.T, raw interface{}) { + data, err := proto.Marshal(raw) + if err != nil { + t.Error(err) + t.FailNow() + } + + tRaw := reflect.TypeOf(raw) + + var newValue interface{} + if tRaw.Kind() == reflect.Slice { + + // go的反射不支持切片取地址, 因此这里需要手动展开 + switch raw.(type) { + case []int32: + newValue = &[]int32{} + case []int64: + newValue = &[]int64{} + case []uint32: + newValue = &[]uint32{} + case []uint64: + newValue = &[]uint64{} + case []float32: + newValue = &[]float32{} + case []float64: + newValue = &[]float64{} + case []bool: + newValue = &[]bool{} + case []string: + newValue = &[]string{} + case []byte: + newValue = &[]byte{} + default: + panic("unsupport type") + } + + } else { + newValue = reflect.New(tRaw).Interface() + } + + err = proto.Unmarshal(data, newValue) + if err != nil { + t.Error(err) + t.FailNow() + } + + newValue = reflect.ValueOf(newValue).Elem().Interface() + + if !reflect.DeepEqual(raw, newValue) { + t.FailNow() + } +} +func TestTopField(t *testing.T) { + testVariant(t, int32(1)) + testVariant(t, int64(10)) + testVariant(t, uint32(100)) + testVariant(t, uint64(1000)) + testVariant(t, float32(10000.1234)) + testVariant(t, float64(100000.1234)) + testVariant(t, true) + testVariant(t, "12345") + testVariant(t, []int32{1, 2, 3, 4}) + testVariant(t, []int64{1, 2, 3, 4}) + testVariant(t, []uint32{1, 2, 3, 4}) + testVariant(t, []uint64{1, 2, 3, 4}) + testVariant(t, []float32{1, 2, 3, 4}) + testVariant(t, []float64{1, 2, 3, 4}) + testVariant(t, []bool{true, false, true}) + testVariant(t, []string{"100", "2", "3"}) } diff --git a/tests/pb_gen.proto b/tests/pb_gen.proto index 59df8d4..33f2a8b 100644 --- a/tests/pb_gen.proto +++ b/tests/pb_gen.proto @@ -14,8 +14,14 @@ enum MyEnum { message MyTypeMini { - string Str = 1; - bool Bool = 2; + bool Bool = 1; + int32 Int32 = 2; + uint32 UInt32 = 3; + int64 Int64 = 4; + uint64 UInt64 = 5; + float Float32 = 6; + double Float64 = 7; + string Str = 8; } @@ -66,3 +72,11 @@ message MyType { repeated MyEnum EnumSlice = 21; } + +message LoginREQ { +} + + +message LoginACK { +} + From 959254af089c2f272cf0ad93ef8a8e703127817b Mon Sep 17 00:00:00 2001 From: davyxu Date: Mon, 6 Jul 2020 17:15:33 +0800 Subject: [PATCH 04/39] =?UTF-8?q?=E5=88=86=E6=8B=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go => cmd/protoplus/main.go | 2 +- gen/golang/text.go | 45 ++-- proto/api.go | 302 ++------------------------- proto/field_size.go | 103 --------- tests/Make.sh | 2 +- tests/code_gen.go | 322 +++++++++++++++-------------- tests/code_test.go | 79 +------ {proto => wire}/buffer.go | 2 +- {proto => wire}/err.go | 2 +- {proto => wire}/field_marshal.go | 44 +--- wire/field_size.go | 81 ++++++++ {proto => wire}/field_unmarshal.go | 48 +---- {proto => wire}/slice_marshal.go | 21 +- {proto => wire}/slice_size.go | 18 +- {proto => wire}/slice_unmarshal.go | 6 +- wire/struct.go | 99 +++++++++ {proto => wire}/variant.go | 2 +- {proto => wire}/wiretype.go | 6 +- 18 files changed, 428 insertions(+), 756 deletions(-) rename main.go => cmd/protoplus/main.go (98%) delete mode 100644 proto/field_size.go rename {proto => wire}/buffer.go (99%) rename {proto => wire}/err.go (92%) rename {proto => wire}/field_marshal.go (60%) create mode 100644 wire/field_size.go rename {proto => wire}/field_unmarshal.go (78%) rename {proto => wire}/slice_marshal.go (84%) rename {proto => wire}/slice_size.go (79%) rename {proto => wire}/slice_unmarshal.go (99%) create mode 100644 wire/struct.go rename {proto => wire}/variant.go (98%) rename {proto => wire}/wiretype.go (79%) diff --git a/main.go b/cmd/protoplus/main.go similarity index 98% rename from main.go rename to cmd/protoplus/main.go index 7d845e5..485d83d 100644 --- a/main.go +++ b/cmd/protoplus/main.go @@ -28,7 +28,7 @@ var ( flagStructBase = flag.String("structbase", "IProtoStruct", "struct inherite class type name in c#") ) -const Version = "0.1.0" +const Version = "2.0.0" func main() { diff --git a/gen/golang/text.go b/gen/golang/text.go index 2f3243e..7b19b34 100644 --- a/gen/golang/text.go +++ b/gen/golang/text.go @@ -6,14 +6,16 @@ const TemplateText = `// Generated by github.com/davyxu/protoplus package {{.PackageName}} import ( - "github.com/davyxu/protoplus/proto" + "github.com/davyxu/protoplus/proto" + "github.com/davyxu/protoplus/wire" "unsafe" {{if .RegEntry}} "reflect" "github.com/davyxu/cellnet" "github.com/davyxu/cellnet/codec" {{end}} ) var ( - _ *proto.Buffer + _ *wire.Buffer + _ = proto.Marshal _ unsafe.Pointer {{if .RegEntry}} _ cellnet.MessageMeta _ codec.CodecRecycler @@ -54,70 +56,70 @@ func (self *{{.Name}}) Size() (ret int) { {{if IsStructSlice .}} if len(self.{{GoFieldName .}}) > 0 { for _, elm := range self.{{GoFieldName .}} { - ret += proto.SizeStruct({{PbTagNumber $obj .}}, &elm) + ret += wire.SizeStruct({{PbTagNumber $obj .}}, &elm) } } {{else if IsStruct .}} - ret += proto.Size{{CodecName .}}({{PbTagNumber $obj .}}, &self.{{GoFieldName .}}) + ret += wire.Size{{CodecName .}}({{PbTagNumber $obj .}}, &self.{{GoFieldName .}}) {{else if IsEnum .}} - ret += proto.Size{{CodecName .}}({{PbTagNumber $obj .}}, int32(self.{{GoFieldName .}})) + ret += wire.Size{{CodecName .}}({{PbTagNumber $obj .}}, int32(self.{{GoFieldName .}})) {{else if IsEnumSlice .}} - ret += proto.Size{{CodecName .}}({{PbTagNumber $obj .}}, *(*[]int32)(unsafe.Pointer(&self.{{GoFieldName .}}))) + ret += wire.Size{{CodecName .}}({{PbTagNumber $obj .}}, *(*[]int32)(unsafe.Pointer(&self.{{GoFieldName .}}))) {{else}} - ret += proto.Size{{CodecName .}}({{PbTagNumber $obj .}}, self.{{GoFieldName .}}) + ret += wire.Size{{CodecName .}}({{PbTagNumber $obj .}}, self.{{GoFieldName .}}) {{end}} {{end}} return } -func (self *{{.Name}}) Marshal(buffer *proto.Buffer) error { +func (self *{{.Name}}) Marshal(buffer *wire.Buffer) error { {{range .Fields}} {{if IsStructSlice .}} for _, elm := range self.{{GoFieldName .}} { - proto.MarshalStruct(buffer, {{PbTagNumber $obj .}}, &elm) + wire.MarshalStruct(buffer, {{PbTagNumber $obj .}}, &elm) } {{else if IsStruct .}} - proto.Marshal{{CodecName .}}(buffer, {{PbTagNumber $obj .}}, &self.{{GoFieldName .}}) + wire.Marshal{{CodecName .}}(buffer, {{PbTagNumber $obj .}}, &self.{{GoFieldName .}}) {{else if IsEnum .}} - proto.Marshal{{CodecName .}}(buffer, {{PbTagNumber $obj .}}, int32(self.{{GoFieldName .}})) + wire.Marshal{{CodecName .}}(buffer, {{PbTagNumber $obj .}}, int32(self.{{GoFieldName .}})) {{else if IsEnumSlice .}} - proto.Marshal{{CodecName .}}(buffer, {{PbTagNumber $obj .}}, *(*[]int32)(unsafe.Pointer(&self.{{GoFieldName .}}))) + wire.Marshal{{CodecName .}}(buffer, {{PbTagNumber $obj .}}, *(*[]int32)(unsafe.Pointer(&self.{{GoFieldName .}}))) {{else}} - proto.Marshal{{CodecName .}}(buffer, {{PbTagNumber $obj .}}, self.{{GoFieldName .}}) + wire.Marshal{{CodecName .}}(buffer, {{PbTagNumber $obj .}}, self.{{GoFieldName .}}) {{end}} {{end}} return nil } -func (self *{{.Name}}) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt proto.WireType) error { +func (self *{{.Name}}) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire.WireType) error { switch fieldIndex { {{range .Fields}} case {{PbTagNumber $obj .}}: {{if IsStructSlice .}} var elm {{.Type}} - if err := proto.UnmarshalStruct(buffer, wt, &elm); err != nil { + if err := wire.UnmarshalStruct(buffer, wt, &elm); err != nil { return err } else { self.{{GoFieldName .}} = append(self.{{GoFieldName .}}, elm) return nil }{{else if IsEnum .}} - v, err := proto.Unmarshal{{CodecName .}}(buffer, wt) + v, err := wire.Unmarshal{{CodecName .}}(buffer, wt) self.{{GoFieldName .}} = {{ProtoTypeName .}}(v) return err {{else if IsStruct .}} - return proto.Unmarshal{{CodecName .}}(buffer, wt, &self.{{GoFieldName .}}) {{else if IsEnumSlice .}} - v, err := proto.Unmarshal{{CodecName .}}(buffer, wt) + return wire.Unmarshal{{CodecName .}}(buffer, wt, &self.{{GoFieldName .}}) {{else if IsEnumSlice .}} + v, err := wire.Unmarshal{{CodecName .}}(buffer, wt) for _, vv := range v { self.{{GoFieldName .}} = append(self.{{GoFieldName .}}, {{ProtoElementTypeName .}}(vv)) } return err {{else if IsSlice .}} - v, err := proto.Unmarshal{{CodecName .}}(buffer, wt) + v, err := wire.Unmarshal{{CodecName .}}(buffer, wt) self.{{GoFieldName .}} = append(self.{{GoFieldName .}}, v...) return err {{else}} - v, err := proto.Unmarshal{{CodecName .}}(buffer, wt) + v, err := wire.Unmarshal{{CodecName .}}(buffer, wt) self.{{GoFieldName .}} = v return err{{end}} {{end}} } - return proto.ErrUnknownField + return wire.ErrUnknownField } {{end}} @@ -129,6 +131,7 @@ func init() { Codec: codec.MustGetCodec("{{StructCodec .}}"), Type: reflect.TypeOf((*{{.Name}})(nil)).Elem(), ID: {{StructMsgID .}}, + New: func() interface{} { return &{{.Name}}{} }, }) {{end}} {{end}} {{end}} } diff --git a/proto/api.go b/proto/api.go index 524421c..f63fe2b 100644 --- a/proto/api.go +++ b/proto/api.go @@ -1,308 +1,34 @@ package proto import ( - "errors" - "reflect" + "github.com/davyxu/protoplus/wire" ) -type Struct interface { - Marshal(buffer *Buffer) error +func Marshal(msg wire.Struct) ([]byte, error) { - Unmarshal(buffer *Buffer, fieldIndex uint64, wt WireType) error + l := msg.Size() - Size() int -} - -const ( - TopFieldIndex = 7 -) - -func Marshal(raw interface{}) ([]byte, error) { - - switch msg := raw.(type) { - case Struct: - l := msg.Size() - - data := make([]byte, 0, l) + data := make([]byte, 0, l) - buffer := NewBuffer(data) + buffer := wire.NewBuffer(data) - err := msg.Marshal(buffer) - if err != nil { - return nil, err - } - - return buffer.Bytes(), nil - default: - size, err := sizeTypes(TopFieldIndex, raw) - if err != nil { - return nil, err - } - - b := NewBufferBySize(size) - - err = marshalTypes(b, TopFieldIndex, raw) - if err != nil { - return nil, err - } - - return b.Bytes(), nil + err := msg.Marshal(buffer) + if err != nil { + return nil, err } -} - -func Size(raw interface{}) int { - msg := raw.(Struct) + return buffer.Bytes(), nil - return msg.Size() } -func Unmarshal(data []byte, raw interface{}) (err error) { - - buffer := NewBuffer(data) - - switch msg := raw.(type) { - case Struct: - return rawUnmarshalStruct(buffer, msg) - default: - - for buffer.BytesRemains() > 0 { - wireTag, err := buffer.DecodeVarint() - - if err != nil { - return err - } - - fieldIndex, wt := parseWireTag(wireTag) - if fieldIndex != TopFieldIndex { - return errors.New("invalid top field tag") - } - - err = unmarshalTypes(buffer, wt, raw) - if err != nil { - return err - } - } - - return nil - - } -} +func Size(msg wire.Struct) int { -func sizeTypes(fieldIndex uint64, raw interface{}) (size int, err error) { - switch v := raw.(type) { - case Struct: - return SizeStruct(fieldIndex, v), nil - case int32: - return SizeInt32(fieldIndex, v), nil - case int64: - return SizeInt64(fieldIndex, v), nil - case uint32: - return SizeUInt32(fieldIndex, v), nil - case uint64: - return SizeUInt64(fieldIndex, v), nil - case float32: - return SizeFloat32(fieldIndex, v), nil - case float64: - return SizeFloat64(fieldIndex, v), nil - case bool: - return SizeBool(fieldIndex, v), nil - case string: - return SizeString(fieldIndex, v), nil - case []byte: - return SizeBytes(fieldIndex, v), nil - case []int32: - return SizeInt32Slice(fieldIndex, v), nil - case []int64: - return SizeInt64Slice(fieldIndex, v), nil - case []uint32: - return SizeUInt32Slice(fieldIndex, v), nil - case []uint64: - return SizeUInt64Slice(fieldIndex, v), nil - case []float32: - return SizeFloat32Slice(fieldIndex, v), nil - case []float64: - return SizeFloat64Slice(fieldIndex, v), nil - case []bool: - return SizeBoolSlice(fieldIndex, v), nil - case []string: - return SizeStringSlice(fieldIndex, v), nil - } - - tRaw := reflect.TypeOf(raw) - switch tRaw.Kind() { - case reflect.Array, reflect.Slice: - - vRaw := reflect.ValueOf(raw) - - for i := 0; i < vRaw.Len(); i++ { - vElement := vRaw.Index(i) - var thisSize int - thisSize, err = sizeTypes(fieldIndex, vElement.Interface()) - if err != nil { - return 0, err - } - - size += thisSize - } - return - - default: - return 0, errors.New("unsupport type: " + tRaw.Kind().String()) - } -} - -func unmarshalTypes(buffer *Buffer, wt WireType, raw interface{}) error { - switch v := raw.(type) { - case Struct: - return UnmarshalStruct(buffer, wt, v) - case *int32: - vv, err := UnmarshalInt32(buffer, wt) - *v = vv - return err - case *int64: - vv, err := UnmarshalInt64(buffer, wt) - *v = vv - return err - case *uint32: - vv, err := UnmarshalUInt32(buffer, wt) - *v = vv - return err - case *uint64: - vv, err := UnmarshalUInt64(buffer, wt) - *v = vv - return err - case *float32: - vv, err := UnmarshalFloat32(buffer, wt) - *v = vv - return err - case *float64: - vv, err := UnmarshalFloat64(buffer, wt) - *v = vv - return err - case *bool: - vv, err := UnmarshalBool(buffer, wt) - *v = vv - return err - case *string: - vv, err := UnmarshalString(buffer, wt) - *v = vv - return err - case *[]byte: - vv, err := UnmarshalBytes(buffer, wt) - *v = append(*v, vv...) - return err - case *[]int32: - vv, err := UnmarshalInt32Slice(buffer, wt) - *v = append(*v, vv...) - return err - case *[]int64: - vv, err := UnmarshalInt64Slice(buffer, wt) - *v = append(*v, vv...) - return err - case *[]uint32: - vv, err := UnmarshalUInt32Slice(buffer, wt) - *v = append(*v, vv...) - return err - case *[]uint64: - vv, err := UnmarshalUInt64Slice(buffer, wt) - *v = append(*v, vv...) - return err - case *[]float32: - vv, err := UnmarshalFloat32Slice(buffer, wt) - *v = append(*v, vv...) - return err - case *[]float64: - vv, err := UnmarshalFloat64Slice(buffer, wt) - *v = append(*v, vv...) - return err - case *[]bool: - vv, err := UnmarshalBoolSlice(buffer, wt) - *v = append(*v, vv...) - return err - case *[]string: - vv, err := UnmarshalStringSlice(buffer, wt) - *v = append(*v, vv...) - return err - } - - tRaw := reflect.TypeOf(raw) - switch tRaw.Kind() { - case reflect.Array, reflect.Slice: - - vRaw := reflect.ValueOf(raw) - - vElement := reflect.New(reflect.TypeOf(raw).Elem()) - err := unmarshalTypes(buffer, wt, vElement.Interface()) - if err != nil { - return err - } - - vRaw.Set(reflect.AppendSlice(vRaw, vElement)) - - return nil - default: - return errors.New("unsupport type: " + tRaw.Kind().String()) - } + return msg.Size() } -func marshalTypes(buffer *Buffer, fieldIndex uint64, raw interface{}) error { +func Unmarshal(data []byte, msg wire.Struct) (err error) { - switch v := raw.(type) { - case Struct: - return MarshalStruct(buffer, fieldIndex, v) - case int32: - return MarshalInt32(buffer, fieldIndex, v) - case int64: - return MarshalInt64(buffer, fieldIndex, v) - case uint32: - return MarshalUInt32(buffer, fieldIndex, v) - case uint64: - return MarshalUInt64(buffer, fieldIndex, v) - case float32: - return MarshalFloat32(buffer, fieldIndex, v) - case float64: - return MarshalFloat64(buffer, fieldIndex, v) - case bool: - return MarshalBool(buffer, fieldIndex, v) - case string: - return MarshalString(buffer, fieldIndex, v) - case []byte: - return MarshalBytes(buffer, fieldIndex, v) - case []int32: - return MarshalInt32Slice(buffer, fieldIndex, v) - case []int64: - return MarshalInt64Slice(buffer, fieldIndex, v) - case []uint32: - return MarshalUInt32Slice(buffer, fieldIndex, v) - case []uint64: - return MarshalUInt64Slice(buffer, fieldIndex, v) - case []float32: - return MarshalFloat32Slice(buffer, fieldIndex, v) - case []float64: - return MarshalFloat64Slice(buffer, fieldIndex, v) - case []bool: - return MarshalBoolSlice(buffer, fieldIndex, v) - case []string: - return MarshalStringSlice(buffer, fieldIndex, v) - } - - tRaw := reflect.TypeOf(raw) - switch tRaw.Kind() { - case reflect.Array, reflect.Slice: - - vRaw := reflect.ValueOf(raw) + buffer := wire.NewBuffer(data) - for i := 0; i < vRaw.Len(); i++ { - vElement := vRaw.Index(i) - err := marshalTypes(buffer, fieldIndex, vElement.Interface()) - if err != nil { - return err - } - } - - return nil - default: - return errors.New("unsupport type: " + tRaw.Kind().String()) - } + return wire.UnmarshalStructObject(buffer, msg) } diff --git a/proto/field_size.go b/proto/field_size.go deleted file mode 100644 index 1359906..0000000 --- a/proto/field_size.go +++ /dev/null @@ -1,103 +0,0 @@ -package proto - -import ( - "reflect" -) - -func SizeBool(fieldIndex uint64, value bool) int { - - if value == false { - return 0 - } - - return SizeVarint(makeWireTag(fieldIndex, WireVarint)) + 1 -} - -func SizeInt32(fieldIndex uint64, value int32) int { - - switch { - case value > 0: - return SizeVarint(makeWireTag(fieldIndex, WireVarint)) + SizeVarint(uint64(value)) - case value < 0: - return SizeVarint(makeWireTag(fieldIndex, WireFixed32)) + 4 - default: - return 0 - } -} - -func SizeUInt32(fieldIndex uint64, value uint32) int { - - if value == 0 { - return 0 - } - - return SizeVarint(makeWireTag(fieldIndex, WireVarint)) + SizeVarint(uint64(value)) -} - -func SizeInt64(fieldIndex uint64, value int64) int { - - switch { - case value > 0: - return SizeVarint(makeWireTag(fieldIndex, WireVarint)) + SizeVarint(uint64(value)) - case value < 0: - return SizeVarint(makeWireTag(fieldIndex, WireFixed64)) + 8 - default: - return 0 - } -} - -func SizeUInt64(fieldIndex uint64, value uint64) int { - - if value == 0 { - return 0 - } - - return SizeVarint(makeWireTag(fieldIndex, WireVarint)) + SizeVarint(uint64(value)) -} - -func SizeFloat32(fieldIndex uint64, value float32) int { - - if value == 0 { - return 0 - } - - return SizeVarint(makeWireTag(fieldIndex, WireFixed32)) + 4 -} - -func SizeFloat64(fieldIndex uint64, value float64) int { - - if value == 0 { - return 0 - } - - return SizeVarint(makeWireTag(fieldIndex, WireFixed64)) + 8 -} - -func SizeString(fieldIndex uint64, value string) int { - - size := len(value) - - if size == 0 { - return 0 - } - - return SizeVarint(makeWireTag(fieldIndex, WireVarint)) + SizeVarint(uint64(size)) + size -} - -func SizeStruct(fieldIndex uint64, msg Struct) int { - - structValue := reflect.ValueOf(msg) - - // *MyType被Message包裹后,判断不为nil - if structValue.IsNil() { - return 0 - } - - size := msg.Size() - - if size == 0 { - return 0 - } - - return SizeVarint(makeWireTag(fieldIndex, WireVarint)) + SizeVarint(uint64(size)) + size -} diff --git a/tests/Make.sh b/tests/Make.sh index 8b76c54..861bb26 100644 --- a/tests/Make.sh +++ b/tests/Make.sh @@ -4,7 +4,7 @@ cd ../../../../.. export GOPATH=`pwd` cd ${CURRDIR} -go build -v -o=${GOPATH}/bin/protoplus github.com/davyxu/protoplus +go build -v -o=${GOPATH}/bin/protoplus github.com/davyxu/protoplus/cmd/protoplus # code.proto为输入文件 ${GOPATH}/bin/protoplus -go_out=code_gen.go -package=tests code.proto diff --git a/tests/code_gen.go b/tests/code_gen.go index bb327c3..4aa377f 100644 --- a/tests/code_gen.go +++ b/tests/code_gen.go @@ -4,11 +4,13 @@ package tests import ( "github.com/davyxu/protoplus/proto" + "github.com/davyxu/protoplus/wire" "unsafe" ) var ( - _ *proto.Buffer + _ *wire.Buffer + _ = proto.Marshal _ unsafe.Pointer ) @@ -53,84 +55,84 @@ func (self *MyTypeMini) String() string { return proto.CompactTextString(self) } func (self *MyTypeMini) Size() (ret int) { - ret += proto.SizeBool(1, self.Bool) + ret += wire.SizeBool(1, self.Bool) - ret += proto.SizeInt32(2, self.Int32) + ret += wire.SizeInt32(2, self.Int32) - ret += proto.SizeUInt32(3, self.UInt32) + ret += wire.SizeUInt32(3, self.UInt32) - ret += proto.SizeInt64(4, self.Int64) + ret += wire.SizeInt64(4, self.Int64) - ret += proto.SizeUInt64(5, self.UInt64) + ret += wire.SizeUInt64(5, self.UInt64) - ret += proto.SizeFloat32(6, self.Float32) + ret += wire.SizeFloat32(6, self.Float32) - ret += proto.SizeFloat64(7, self.Float64) + ret += wire.SizeFloat64(7, self.Float64) - ret += proto.SizeString(8, self.Str) + ret += wire.SizeString(8, self.Str) return } -func (self *MyTypeMini) Marshal(buffer *proto.Buffer) error { +func (self *MyTypeMini) Marshal(buffer *wire.Buffer) error { - proto.MarshalBool(buffer, 1, self.Bool) + wire.MarshalBool(buffer, 1, self.Bool) - proto.MarshalInt32(buffer, 2, self.Int32) + wire.MarshalInt32(buffer, 2, self.Int32) - proto.MarshalUInt32(buffer, 3, self.UInt32) + wire.MarshalUInt32(buffer, 3, self.UInt32) - proto.MarshalInt64(buffer, 4, self.Int64) + wire.MarshalInt64(buffer, 4, self.Int64) - proto.MarshalUInt64(buffer, 5, self.UInt64) + wire.MarshalUInt64(buffer, 5, self.UInt64) - proto.MarshalFloat32(buffer, 6, self.Float32) + wire.MarshalFloat32(buffer, 6, self.Float32) - proto.MarshalFloat64(buffer, 7, self.Float64) + wire.MarshalFloat64(buffer, 7, self.Float64) - proto.MarshalString(buffer, 8, self.Str) + wire.MarshalString(buffer, 8, self.Str) return nil } -func (self *MyTypeMini) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt proto.WireType) error { +func (self *MyTypeMini) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire.WireType) error { switch fieldIndex { case 1: - v, err := proto.UnmarshalBool(buffer, wt) + v, err := wire.UnmarshalBool(buffer, wt) self.Bool = v return err case 2: - v, err := proto.UnmarshalInt32(buffer, wt) + v, err := wire.UnmarshalInt32(buffer, wt) self.Int32 = v return err case 3: - v, err := proto.UnmarshalUInt32(buffer, wt) + v, err := wire.UnmarshalUInt32(buffer, wt) self.UInt32 = v return err case 4: - v, err := proto.UnmarshalInt64(buffer, wt) + v, err := wire.UnmarshalInt64(buffer, wt) self.Int64 = v return err case 5: - v, err := proto.UnmarshalUInt64(buffer, wt) + v, err := wire.UnmarshalUInt64(buffer, wt) self.UInt64 = v return err case 6: - v, err := proto.UnmarshalFloat32(buffer, wt) + v, err := wire.UnmarshalFloat32(buffer, wt) self.Float32 = v return err case 7: - v, err := proto.UnmarshalFloat64(buffer, wt) + v, err := wire.UnmarshalFloat64(buffer, wt) self.Float64 = v return err case 8: - v, err := proto.UnmarshalString(buffer, wt) + v, err := wire.UnmarshalString(buffer, wt) self.Str = v return err } - return proto.ErrUnknownField + return wire.ErrUnknownField } type MySubType struct { @@ -159,166 +161,166 @@ func (self *MySubType) String() string { return proto.CompactTextString(self) } func (self *MySubType) Size() (ret int) { - ret += proto.SizeBool(1, self.Bool) + ret += wire.SizeBool(1, self.Bool) - ret += proto.SizeInt32(2, self.Int32) + ret += wire.SizeInt32(2, self.Int32) - ret += proto.SizeUInt32(3, self.UInt32) + ret += wire.SizeUInt32(3, self.UInt32) - ret += proto.SizeInt64(4, self.Int64) + ret += wire.SizeInt64(4, self.Int64) - ret += proto.SizeUInt64(5, self.UInt64) + ret += wire.SizeUInt64(5, self.UInt64) - ret += proto.SizeFloat32(6, self.Float32) + ret += wire.SizeFloat32(6, self.Float32) - ret += proto.SizeFloat64(7, self.Float64) + ret += wire.SizeFloat64(7, self.Float64) - ret += proto.SizeString(8, self.Str) + ret += wire.SizeString(8, self.Str) - ret += proto.SizeBytes(9, self.BytesSlice) + ret += wire.SizeBytes(9, self.BytesSlice) - ret += proto.SizeBoolSlice(10, self.BoolSlice) + ret += wire.SizeBoolSlice(10, self.BoolSlice) - ret += proto.SizeInt32Slice(11, self.Int32Slice) + ret += wire.SizeInt32Slice(11, self.Int32Slice) - ret += proto.SizeUInt32Slice(12, self.UInt32Slice) + ret += wire.SizeUInt32Slice(12, self.UInt32Slice) - ret += proto.SizeInt64Slice(13, self.Int64Slice) + ret += wire.SizeInt64Slice(13, self.Int64Slice) - ret += proto.SizeUInt64Slice(14, self.UInt64Slice) + ret += wire.SizeUInt64Slice(14, self.UInt64Slice) - ret += proto.SizeFloat32Slice(15, self.Float32Slice) + ret += wire.SizeFloat32Slice(15, self.Float32Slice) - ret += proto.SizeFloat64Slice(16, self.Float64Slice) + ret += wire.SizeFloat64Slice(16, self.Float64Slice) - ret += proto.SizeStringSlice(17, self.StrSlice) + ret += wire.SizeStringSlice(17, self.StrSlice) - ret += proto.SizeInt32(18, int32(self.Enum)) + ret += wire.SizeInt32(18, int32(self.Enum)) - ret += proto.SizeInt32Slice(19, *(*[]int32)(unsafe.Pointer(&self.EnumSlice))) + ret += wire.SizeInt32Slice(19, *(*[]int32)(unsafe.Pointer(&self.EnumSlice))) return } -func (self *MySubType) Marshal(buffer *proto.Buffer) error { +func (self *MySubType) Marshal(buffer *wire.Buffer) error { - proto.MarshalBool(buffer, 1, self.Bool) + wire.MarshalBool(buffer, 1, self.Bool) - proto.MarshalInt32(buffer, 2, self.Int32) + wire.MarshalInt32(buffer, 2, self.Int32) - proto.MarshalUInt32(buffer, 3, self.UInt32) + wire.MarshalUInt32(buffer, 3, self.UInt32) - proto.MarshalInt64(buffer, 4, self.Int64) + wire.MarshalInt64(buffer, 4, self.Int64) - proto.MarshalUInt64(buffer, 5, self.UInt64) + wire.MarshalUInt64(buffer, 5, self.UInt64) - proto.MarshalFloat32(buffer, 6, self.Float32) + wire.MarshalFloat32(buffer, 6, self.Float32) - proto.MarshalFloat64(buffer, 7, self.Float64) + wire.MarshalFloat64(buffer, 7, self.Float64) - proto.MarshalString(buffer, 8, self.Str) + wire.MarshalString(buffer, 8, self.Str) - proto.MarshalBytes(buffer, 9, self.BytesSlice) + wire.MarshalBytes(buffer, 9, self.BytesSlice) - proto.MarshalBoolSlice(buffer, 10, self.BoolSlice) + wire.MarshalBoolSlice(buffer, 10, self.BoolSlice) - proto.MarshalInt32Slice(buffer, 11, self.Int32Slice) + wire.MarshalInt32Slice(buffer, 11, self.Int32Slice) - proto.MarshalUInt32Slice(buffer, 12, self.UInt32Slice) + wire.MarshalUInt32Slice(buffer, 12, self.UInt32Slice) - proto.MarshalInt64Slice(buffer, 13, self.Int64Slice) + wire.MarshalInt64Slice(buffer, 13, self.Int64Slice) - proto.MarshalUInt64Slice(buffer, 14, self.UInt64Slice) + wire.MarshalUInt64Slice(buffer, 14, self.UInt64Slice) - proto.MarshalFloat32Slice(buffer, 15, self.Float32Slice) + wire.MarshalFloat32Slice(buffer, 15, self.Float32Slice) - proto.MarshalFloat64Slice(buffer, 16, self.Float64Slice) + wire.MarshalFloat64Slice(buffer, 16, self.Float64Slice) - proto.MarshalStringSlice(buffer, 17, self.StrSlice) + wire.MarshalStringSlice(buffer, 17, self.StrSlice) - proto.MarshalInt32(buffer, 18, int32(self.Enum)) + wire.MarshalInt32(buffer, 18, int32(self.Enum)) - proto.MarshalInt32Slice(buffer, 19, *(*[]int32)(unsafe.Pointer(&self.EnumSlice))) + wire.MarshalInt32Slice(buffer, 19, *(*[]int32)(unsafe.Pointer(&self.EnumSlice))) return nil } -func (self *MySubType) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt proto.WireType) error { +func (self *MySubType) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire.WireType) error { switch fieldIndex { case 1: - v, err := proto.UnmarshalBool(buffer, wt) + v, err := wire.UnmarshalBool(buffer, wt) self.Bool = v return err case 2: - v, err := proto.UnmarshalInt32(buffer, wt) + v, err := wire.UnmarshalInt32(buffer, wt) self.Int32 = v return err case 3: - v, err := proto.UnmarshalUInt32(buffer, wt) + v, err := wire.UnmarshalUInt32(buffer, wt) self.UInt32 = v return err case 4: - v, err := proto.UnmarshalInt64(buffer, wt) + v, err := wire.UnmarshalInt64(buffer, wt) self.Int64 = v return err case 5: - v, err := proto.UnmarshalUInt64(buffer, wt) + v, err := wire.UnmarshalUInt64(buffer, wt) self.UInt64 = v return err case 6: - v, err := proto.UnmarshalFloat32(buffer, wt) + v, err := wire.UnmarshalFloat32(buffer, wt) self.Float32 = v return err case 7: - v, err := proto.UnmarshalFloat64(buffer, wt) + v, err := wire.UnmarshalFloat64(buffer, wt) self.Float64 = v return err case 8: - v, err := proto.UnmarshalString(buffer, wt) + v, err := wire.UnmarshalString(buffer, wt) self.Str = v return err case 9: - v, err := proto.UnmarshalBytes(buffer, wt) + v, err := wire.UnmarshalBytes(buffer, wt) self.BytesSlice = v return err case 10: - v, err := proto.UnmarshalBoolSlice(buffer, wt) + v, err := wire.UnmarshalBoolSlice(buffer, wt) self.BoolSlice = append(self.BoolSlice, v...) return err case 11: - v, err := proto.UnmarshalInt32Slice(buffer, wt) + v, err := wire.UnmarshalInt32Slice(buffer, wt) self.Int32Slice = append(self.Int32Slice, v...) return err case 12: - v, err := proto.UnmarshalUInt32Slice(buffer, wt) + v, err := wire.UnmarshalUInt32Slice(buffer, wt) self.UInt32Slice = append(self.UInt32Slice, v...) return err case 13: - v, err := proto.UnmarshalInt64Slice(buffer, wt) + v, err := wire.UnmarshalInt64Slice(buffer, wt) self.Int64Slice = append(self.Int64Slice, v...) return err case 14: - v, err := proto.UnmarshalUInt64Slice(buffer, wt) + v, err := wire.UnmarshalUInt64Slice(buffer, wt) self.UInt64Slice = append(self.UInt64Slice, v...) return err case 15: - v, err := proto.UnmarshalFloat32Slice(buffer, wt) + v, err := wire.UnmarshalFloat32Slice(buffer, wt) self.Float32Slice = append(self.Float32Slice, v...) return err case 16: - v, err := proto.UnmarshalFloat64Slice(buffer, wt) + v, err := wire.UnmarshalFloat64Slice(buffer, wt) self.Float64Slice = append(self.Float64Slice, v...) return err case 17: - v, err := proto.UnmarshalStringSlice(buffer, wt) + v, err := wire.UnmarshalStringSlice(buffer, wt) self.StrSlice = append(self.StrSlice, v...) return err case 18: - v, err := proto.UnmarshalInt32(buffer, wt) + v, err := wire.UnmarshalInt32(buffer, wt) self.Enum = MyEnum(v) return err case 19: - v, err := proto.UnmarshalInt32Slice(buffer, wt) + v, err := wire.UnmarshalInt32Slice(buffer, wt) for _, vv := range v { self.EnumSlice = append(self.EnumSlice, MyEnum(vv)) } @@ -326,7 +328,7 @@ func (self *MySubType) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt pro } - return proto.ErrUnknownField + return wire.ErrUnknownField } type MyType struct { @@ -357,190 +359,190 @@ func (self *MyType) String() string { return proto.CompactTextString(self) } func (self *MyType) Size() (ret int) { - ret += proto.SizeBool(1, self.Bool) + ret += wire.SizeBool(1, self.Bool) - ret += proto.SizeInt32(2, self.Int32) + ret += wire.SizeInt32(2, self.Int32) - ret += proto.SizeUInt32(3, self.UInt32) + ret += wire.SizeUInt32(3, self.UInt32) - ret += proto.SizeInt64(4, self.Int64) + ret += wire.SizeInt64(4, self.Int64) - ret += proto.SizeUInt64(5, self.UInt64) + ret += wire.SizeUInt64(5, self.UInt64) - ret += proto.SizeFloat32(6, self.Float32) + ret += wire.SizeFloat32(6, self.Float32) - ret += proto.SizeFloat64(7, self.Float64) + ret += wire.SizeFloat64(7, self.Float64) - ret += proto.SizeString(8, self.Str) + ret += wire.SizeString(8, self.Str) - ret += proto.SizeStruct(9, &self.Struct) + ret += wire.SizeStruct(9, &self.Struct) - ret += proto.SizeBytes(10, self.BytesSlice) + ret += wire.SizeBytes(10, self.BytesSlice) - ret += proto.SizeBoolSlice(11, self.BoolSlice) + ret += wire.SizeBoolSlice(11, self.BoolSlice) - ret += proto.SizeInt32Slice(12, self.Int32Slice) + ret += wire.SizeInt32Slice(12, self.Int32Slice) - ret += proto.SizeUInt32Slice(13, self.UInt32Slice) + ret += wire.SizeUInt32Slice(13, self.UInt32Slice) - ret += proto.SizeInt64Slice(14, self.Int64Slice) + ret += wire.SizeInt64Slice(14, self.Int64Slice) - ret += proto.SizeUInt64Slice(15, self.UInt64Slice) + ret += wire.SizeUInt64Slice(15, self.UInt64Slice) - ret += proto.SizeFloat32Slice(16, self.Float32Slice) + ret += wire.SizeFloat32Slice(16, self.Float32Slice) - ret += proto.SizeFloat64Slice(17, self.Float64Slice) + ret += wire.SizeFloat64Slice(17, self.Float64Slice) - ret += proto.SizeStringSlice(18, self.StrSlice) + ret += wire.SizeStringSlice(18, self.StrSlice) if len(self.StructSlice) > 0 { for _, elm := range self.StructSlice { - ret += proto.SizeStruct(19, &elm) + ret += wire.SizeStruct(19, &elm) } } - ret += proto.SizeInt32(20, int32(self.Enum)) + ret += wire.SizeInt32(20, int32(self.Enum)) - ret += proto.SizeInt32Slice(21, *(*[]int32)(unsafe.Pointer(&self.EnumSlice))) + ret += wire.SizeInt32Slice(21, *(*[]int32)(unsafe.Pointer(&self.EnumSlice))) return } -func (self *MyType) Marshal(buffer *proto.Buffer) error { +func (self *MyType) Marshal(buffer *wire.Buffer) error { - proto.MarshalBool(buffer, 1, self.Bool) + wire.MarshalBool(buffer, 1, self.Bool) - proto.MarshalInt32(buffer, 2, self.Int32) + wire.MarshalInt32(buffer, 2, self.Int32) - proto.MarshalUInt32(buffer, 3, self.UInt32) + wire.MarshalUInt32(buffer, 3, self.UInt32) - proto.MarshalInt64(buffer, 4, self.Int64) + wire.MarshalInt64(buffer, 4, self.Int64) - proto.MarshalUInt64(buffer, 5, self.UInt64) + wire.MarshalUInt64(buffer, 5, self.UInt64) - proto.MarshalFloat32(buffer, 6, self.Float32) + wire.MarshalFloat32(buffer, 6, self.Float32) - proto.MarshalFloat64(buffer, 7, self.Float64) + wire.MarshalFloat64(buffer, 7, self.Float64) - proto.MarshalString(buffer, 8, self.Str) + wire.MarshalString(buffer, 8, self.Str) - proto.MarshalStruct(buffer, 9, &self.Struct) + wire.MarshalStruct(buffer, 9, &self.Struct) - proto.MarshalBytes(buffer, 10, self.BytesSlice) + wire.MarshalBytes(buffer, 10, self.BytesSlice) - proto.MarshalBoolSlice(buffer, 11, self.BoolSlice) + wire.MarshalBoolSlice(buffer, 11, self.BoolSlice) - proto.MarshalInt32Slice(buffer, 12, self.Int32Slice) + wire.MarshalInt32Slice(buffer, 12, self.Int32Slice) - proto.MarshalUInt32Slice(buffer, 13, self.UInt32Slice) + wire.MarshalUInt32Slice(buffer, 13, self.UInt32Slice) - proto.MarshalInt64Slice(buffer, 14, self.Int64Slice) + wire.MarshalInt64Slice(buffer, 14, self.Int64Slice) - proto.MarshalUInt64Slice(buffer, 15, self.UInt64Slice) + wire.MarshalUInt64Slice(buffer, 15, self.UInt64Slice) - proto.MarshalFloat32Slice(buffer, 16, self.Float32Slice) + wire.MarshalFloat32Slice(buffer, 16, self.Float32Slice) - proto.MarshalFloat64Slice(buffer, 17, self.Float64Slice) + wire.MarshalFloat64Slice(buffer, 17, self.Float64Slice) - proto.MarshalStringSlice(buffer, 18, self.StrSlice) + wire.MarshalStringSlice(buffer, 18, self.StrSlice) for _, elm := range self.StructSlice { - proto.MarshalStruct(buffer, 19, &elm) + wire.MarshalStruct(buffer, 19, &elm) } - proto.MarshalInt32(buffer, 20, int32(self.Enum)) + wire.MarshalInt32(buffer, 20, int32(self.Enum)) - proto.MarshalInt32Slice(buffer, 21, *(*[]int32)(unsafe.Pointer(&self.EnumSlice))) + wire.MarshalInt32Slice(buffer, 21, *(*[]int32)(unsafe.Pointer(&self.EnumSlice))) return nil } -func (self *MyType) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt proto.WireType) error { +func (self *MyType) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire.WireType) error { switch fieldIndex { case 1: - v, err := proto.UnmarshalBool(buffer, wt) + v, err := wire.UnmarshalBool(buffer, wt) self.Bool = v return err case 2: - v, err := proto.UnmarshalInt32(buffer, wt) + v, err := wire.UnmarshalInt32(buffer, wt) self.Int32 = v return err case 3: - v, err := proto.UnmarshalUInt32(buffer, wt) + v, err := wire.UnmarshalUInt32(buffer, wt) self.UInt32 = v return err case 4: - v, err := proto.UnmarshalInt64(buffer, wt) + v, err := wire.UnmarshalInt64(buffer, wt) self.Int64 = v return err case 5: - v, err := proto.UnmarshalUInt64(buffer, wt) + v, err := wire.UnmarshalUInt64(buffer, wt) self.UInt64 = v return err case 6: - v, err := proto.UnmarshalFloat32(buffer, wt) + v, err := wire.UnmarshalFloat32(buffer, wt) self.Float32 = v return err case 7: - v, err := proto.UnmarshalFloat64(buffer, wt) + v, err := wire.UnmarshalFloat64(buffer, wt) self.Float64 = v return err case 8: - v, err := proto.UnmarshalString(buffer, wt) + v, err := wire.UnmarshalString(buffer, wt) self.Str = v return err case 9: - return proto.UnmarshalStruct(buffer, wt, &self.Struct) + return wire.UnmarshalStruct(buffer, wt, &self.Struct) case 10: - v, err := proto.UnmarshalBytes(buffer, wt) + v, err := wire.UnmarshalBytes(buffer, wt) self.BytesSlice = v return err case 11: - v, err := proto.UnmarshalBoolSlice(buffer, wt) + v, err := wire.UnmarshalBoolSlice(buffer, wt) self.BoolSlice = append(self.BoolSlice, v...) return err case 12: - v, err := proto.UnmarshalInt32Slice(buffer, wt) + v, err := wire.UnmarshalInt32Slice(buffer, wt) self.Int32Slice = append(self.Int32Slice, v...) return err case 13: - v, err := proto.UnmarshalUInt32Slice(buffer, wt) + v, err := wire.UnmarshalUInt32Slice(buffer, wt) self.UInt32Slice = append(self.UInt32Slice, v...) return err case 14: - v, err := proto.UnmarshalInt64Slice(buffer, wt) + v, err := wire.UnmarshalInt64Slice(buffer, wt) self.Int64Slice = append(self.Int64Slice, v...) return err case 15: - v, err := proto.UnmarshalUInt64Slice(buffer, wt) + v, err := wire.UnmarshalUInt64Slice(buffer, wt) self.UInt64Slice = append(self.UInt64Slice, v...) return err case 16: - v, err := proto.UnmarshalFloat32Slice(buffer, wt) + v, err := wire.UnmarshalFloat32Slice(buffer, wt) self.Float32Slice = append(self.Float32Slice, v...) return err case 17: - v, err := proto.UnmarshalFloat64Slice(buffer, wt) + v, err := wire.UnmarshalFloat64Slice(buffer, wt) self.Float64Slice = append(self.Float64Slice, v...) return err case 18: - v, err := proto.UnmarshalStringSlice(buffer, wt) + v, err := wire.UnmarshalStringSlice(buffer, wt) self.StrSlice = append(self.StrSlice, v...) return err case 19: var elm MySubType - if err := proto.UnmarshalStruct(buffer, wt, &elm); err != nil { + if err := wire.UnmarshalStruct(buffer, wt, &elm); err != nil { return err } else { self.StructSlice = append(self.StructSlice, elm) return nil } case 20: - v, err := proto.UnmarshalInt32(buffer, wt) + v, err := wire.UnmarshalInt32(buffer, wt) self.Enum = MyEnum(v) return err case 21: - v, err := proto.UnmarshalInt32Slice(buffer, wt) + v, err := wire.UnmarshalInt32Slice(buffer, wt) for _, vv := range v { self.EnumSlice = append(self.EnumSlice, MyEnum(vv)) } @@ -548,7 +550,7 @@ func (self *MyType) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt proto. } - return proto.ErrUnknownField + return wire.ErrUnknownField } type LoginREQ struct { @@ -561,17 +563,17 @@ func (self *LoginREQ) Size() (ret int) { return } -func (self *LoginREQ) Marshal(buffer *proto.Buffer) error { +func (self *LoginREQ) Marshal(buffer *wire.Buffer) error { return nil } -func (self *LoginREQ) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt proto.WireType) error { +func (self *LoginREQ) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire.WireType) error { switch fieldIndex { } - return proto.ErrUnknownField + return wire.ErrUnknownField } type LoginACK struct { @@ -584,17 +586,17 @@ func (self *LoginACK) Size() (ret int) { return } -func (self *LoginACK) Marshal(buffer *proto.Buffer) error { +func (self *LoginACK) Marshal(buffer *wire.Buffer) error { return nil } -func (self *LoginACK) Unmarshal(buffer *proto.Buffer, fieldIndex uint64, wt proto.WireType) error { +func (self *LoginACK) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire.WireType) error { switch fieldIndex { } - return proto.ErrUnknownField + return wire.ErrUnknownField } func init() { diff --git a/tests/code_test.go b/tests/code_test.go index ed31753..1fb5c8b 100644 --- a/tests/code_test.go +++ b/tests/code_test.go @@ -2,6 +2,7 @@ package tests import ( "github.com/davyxu/protoplus/proto" + "github.com/davyxu/protoplus/wire" "math" "reflect" "testing" @@ -60,7 +61,7 @@ func makeMyType() (input MyType) { return } -func verify(t *testing.T, raw interface{}) { +func verify(t *testing.T, raw wire.Struct) { t.Logf("size: %d", proto.Size(raw)) data, err := proto.Marshal(raw) @@ -70,7 +71,7 @@ func verify(t *testing.T, raw interface{}) { } t.Log("proto+:", len(data), data) - newType := reflect.New(reflect.TypeOf(raw).Elem()).Interface() + newType := reflect.New(reflect.TypeOf(raw).Elem()).Interface().(wire.Struct) err = proto.Unmarshal(data, newType) if err != nil { @@ -89,7 +90,7 @@ func TestFull(t *testing.T) { verify(t, &input) - t.Logf("%v", input.String()) + t.Logf("%v", proto.MarshalTextString(input)) } func TestIntSlice(t *testing.T) { @@ -99,75 +100,3 @@ func TestIntSlice(t *testing.T) { verify(t, &input) } - -func testVariant(t *testing.T, raw interface{}) { - data, err := proto.Marshal(raw) - if err != nil { - t.Error(err) - t.FailNow() - } - - tRaw := reflect.TypeOf(raw) - - var newValue interface{} - if tRaw.Kind() == reflect.Slice { - - // go的反射不支持切片取地址, 因此这里需要手动展开 - switch raw.(type) { - case []int32: - newValue = &[]int32{} - case []int64: - newValue = &[]int64{} - case []uint32: - newValue = &[]uint32{} - case []uint64: - newValue = &[]uint64{} - case []float32: - newValue = &[]float32{} - case []float64: - newValue = &[]float64{} - case []bool: - newValue = &[]bool{} - case []string: - newValue = &[]string{} - case []byte: - newValue = &[]byte{} - default: - panic("unsupport type") - } - - } else { - newValue = reflect.New(tRaw).Interface() - } - - err = proto.Unmarshal(data, newValue) - if err != nil { - t.Error(err) - t.FailNow() - } - - newValue = reflect.ValueOf(newValue).Elem().Interface() - - if !reflect.DeepEqual(raw, newValue) { - t.FailNow() - } -} - -func TestTopField(t *testing.T) { - testVariant(t, int32(1)) - testVariant(t, int64(10)) - testVariant(t, uint32(100)) - testVariant(t, uint64(1000)) - testVariant(t, float32(10000.1234)) - testVariant(t, float64(100000.1234)) - testVariant(t, true) - testVariant(t, "12345") - testVariant(t, []int32{1, 2, 3, 4}) - testVariant(t, []int64{1, 2, 3, 4}) - testVariant(t, []uint32{1, 2, 3, 4}) - testVariant(t, []uint64{1, 2, 3, 4}) - testVariant(t, []float32{1, 2, 3, 4}) - testVariant(t, []float64{1, 2, 3, 4}) - testVariant(t, []bool{true, false, true}) - testVariant(t, []string{"100", "2", "3"}) -} diff --git a/proto/buffer.go b/wire/buffer.go similarity index 99% rename from proto/buffer.go rename to wire/buffer.go index 716326d..9a55fc3 100644 --- a/proto/buffer.go +++ b/wire/buffer.go @@ -1,4 +1,4 @@ -package proto +package wire import ( "errors" diff --git a/proto/err.go b/wire/err.go similarity index 92% rename from proto/err.go rename to wire/err.go index c212696..7deaf46 100644 --- a/proto/err.go +++ b/wire/err.go @@ -1,4 +1,4 @@ -package proto +package wire import "errors" diff --git a/proto/field_marshal.go b/wire/field_marshal.go similarity index 60% rename from proto/field_marshal.go rename to wire/field_marshal.go index 99d56f7..0e8c6c7 100644 --- a/proto/field_marshal.go +++ b/wire/field_marshal.go @@ -1,8 +1,7 @@ -package proto +package wire import ( "math" - "reflect" ) func MarshalBool(b *Buffer, fieldIndex uint64, value bool) error { @@ -11,7 +10,7 @@ func MarshalBool(b *Buffer, fieldIndex uint64, value bool) error { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireVarint)) + b.EncodeVarint(MakeTag(fieldIndex, WireVarint)) if value { b.buf = append(b.buf, 1) @@ -26,10 +25,10 @@ func MarshalInt32(b *Buffer, fieldIndex uint64, value int32) error { switch { case value > 0: - b.EncodeVarint(makeWireTag(fieldIndex, WireVarint)) + b.EncodeVarint(MakeTag(fieldIndex, WireVarint)) b.EncodeVarint(uint64(value)) case value < 0: - b.EncodeVarint(makeWireTag(fieldIndex, WireFixed32)) + b.EncodeVarint(MakeTag(fieldIndex, WireFixed32)) b.EncodeFixed32(uint64(value)) } @@ -42,7 +41,7 @@ func MarshalUInt32(b *Buffer, fieldIndex uint64, value uint32) error { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireVarint)) + b.EncodeVarint(MakeTag(fieldIndex, WireVarint)) b.EncodeVarint(uint64(value)) return nil @@ -52,10 +51,10 @@ func MarshalInt64(b *Buffer, fieldIndex uint64, value int64) error { switch { case value > 0: - b.EncodeVarint(makeWireTag(fieldIndex, WireVarint)) + b.EncodeVarint(MakeTag(fieldIndex, WireVarint)) b.EncodeVarint(uint64(value)) case value < 0: - b.EncodeVarint(makeWireTag(fieldIndex, WireFixed64)) + b.EncodeVarint(MakeTag(fieldIndex, WireFixed64)) b.EncodeFixed64(uint64(value)) } @@ -68,7 +67,7 @@ func MarshalUInt64(b *Buffer, fieldIndex uint64, value uint64) error { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireVarint)) + b.EncodeVarint(MakeTag(fieldIndex, WireVarint)) b.EncodeVarint(value) return nil @@ -80,7 +79,7 @@ func MarshalFloat32(b *Buffer, fieldIndex uint64, value float32) error { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireFixed32)) + b.EncodeVarint(MakeTag(fieldIndex, WireFixed32)) b.EncodeFixed32(uint64(math.Float32bits(value))) return nil @@ -92,7 +91,7 @@ func MarshalFloat64(b *Buffer, fieldIndex uint64, value float64) error { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireFixed64)) + b.EncodeVarint(MakeTag(fieldIndex, WireFixed64)) b.EncodeFixed64(uint64(math.Float64bits(value))) return nil @@ -103,30 +102,9 @@ func MarshalString(b *Buffer, fieldIndex uint64, value string) error { if value == "" { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireBytes)) + b.EncodeVarint(MakeTag(fieldIndex, WireBytes)) b.EncodeStringBytes(value) return nil } - -func MarshalStruct(b *Buffer, fieldIndex uint64, msg Struct) error { - - structValue := reflect.ValueOf(msg) - - // *MyType被Message包裹后,判断不为nil - if structValue.IsNil() { - return nil - } - - size := msg.Size() - if size == 0 { - return nil - } - - b.EncodeVarint(makeWireTag(fieldIndex, WireBytes)) - - b.EncodeVarint(uint64(size)) - - return msg.Marshal(b) -} diff --git a/wire/field_size.go b/wire/field_size.go new file mode 100644 index 0000000..3f7d0f9 --- /dev/null +++ b/wire/field_size.go @@ -0,0 +1,81 @@ +package wire + +func SizeBool(fieldIndex uint64, value bool) int { + + if value == false { + return 0 + } + + return SizeVarint(MakeTag(fieldIndex, WireVarint)) + 1 +} + +func SizeInt32(fieldIndex uint64, value int32) int { + + switch { + case value > 0: + return SizeVarint(MakeTag(fieldIndex, WireVarint)) + SizeVarint(uint64(value)) + case value < 0: + return SizeVarint(MakeTag(fieldIndex, WireFixed32)) + 4 + default: + return 0 + } +} + +func SizeUInt32(fieldIndex uint64, value uint32) int { + + if value == 0 { + return 0 + } + + return SizeVarint(MakeTag(fieldIndex, WireVarint)) + SizeVarint(uint64(value)) +} + +func SizeInt64(fieldIndex uint64, value int64) int { + + switch { + case value > 0: + return SizeVarint(MakeTag(fieldIndex, WireVarint)) + SizeVarint(uint64(value)) + case value < 0: + return SizeVarint(MakeTag(fieldIndex, WireFixed64)) + 8 + default: + return 0 + } +} + +func SizeUInt64(fieldIndex uint64, value uint64) int { + + if value == 0 { + return 0 + } + + return SizeVarint(MakeTag(fieldIndex, WireVarint)) + SizeVarint(uint64(value)) +} + +func SizeFloat32(fieldIndex uint64, value float32) int { + + if value == 0 { + return 0 + } + + return SizeVarint(MakeTag(fieldIndex, WireFixed32)) + 4 +} + +func SizeFloat64(fieldIndex uint64, value float64) int { + + if value == 0 { + return 0 + } + + return SizeVarint(MakeTag(fieldIndex, WireFixed64)) + 8 +} + +func SizeString(fieldIndex uint64, value string) int { + + size := len(value) + + if size == 0 { + return 0 + } + + return SizeVarint(MakeTag(fieldIndex, WireVarint)) + SizeVarint(uint64(size)) + size +} diff --git a/proto/field_unmarshal.go b/wire/field_unmarshal.go similarity index 78% rename from proto/field_unmarshal.go rename to wire/field_unmarshal.go index 7795428..28834b0 100644 --- a/proto/field_unmarshal.go +++ b/wire/field_unmarshal.go @@ -1,4 +1,4 @@ -package proto +package wire import ( "io" @@ -168,49 +168,3 @@ func skipField(b *Buffer, wt WireType) error { return ErrBadWireType } } - -func rawUnmarshalStruct(b *Buffer, msg Struct) error { - - for b.BytesRemains() > 0 { - wireTag, err := b.DecodeVarint() - - if err != nil { - return err - } - - fieldIndex, wt := parseWireTag(wireTag) - - err = msg.Unmarshal(b, fieldIndex, wt) - - if err == ErrUnknownField { - err = skipField(b, wt) - } - - if err != nil { - return err - } - } - - return nil -} - -func UnmarshalStruct(b *Buffer, wt WireType, msgPtr Struct) error { - switch wt { - case WireBytes: - size, err := b.DecodeVarint() - if err != nil { - return err - } - - if b.BytesRemains() < int(size) { - return io.ErrUnexpectedEOF - } - - limitBuffer := NewBuffer(b.ConsumeBytes(int(size))) - - return rawUnmarshalStruct(limitBuffer, msgPtr) - - default: - return ErrBadWireType - } -} diff --git a/proto/slice_marshal.go b/wire/slice_marshal.go similarity index 84% rename from proto/slice_marshal.go rename to wire/slice_marshal.go index 73bf8e1..002be14 100644 --- a/proto/slice_marshal.go +++ b/wire/slice_marshal.go @@ -1,4 +1,4 @@ -package proto +package wire import ( "math" @@ -11,8 +11,9 @@ func MarshalBytes(b *Buffer, fieldIndex uint64, value []byte) error { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireBytes)) + b.EncodeVarint(MakeTag(fieldIndex, WireBytes)) + // 因为bool每一个value都是1个字节,size=1*count b.EncodeVarint(uint64(size)) b.buf = append(b.buf, value...) @@ -26,7 +27,7 @@ func MarshalBoolSlice(b *Buffer, fieldIndex uint64, value []bool) error { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireBytes)) + b.EncodeVarint(MakeTag(fieldIndex, WireBytes)) // 因为bool每一个value都是1个字节,size=1*count b.EncodeVarint(uint64(size)) @@ -49,7 +50,7 @@ func MarshalInt32Slice(b *Buffer, fieldIndex uint64, value []int32) error { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireBytes)) + b.EncodeVarint(MakeTag(fieldIndex, WireBytes)) // 计算变长单元大小 var size int @@ -72,7 +73,7 @@ func MarshalUInt32Slice(b *Buffer, fieldIndex uint64, value []uint32) error { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireBytes)) + b.EncodeVarint(MakeTag(fieldIndex, WireBytes)) // 计算变长单元大小 var size int @@ -95,7 +96,7 @@ func MarshalInt64Slice(b *Buffer, fieldIndex uint64, value []int64) error { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireBytes)) + b.EncodeVarint(MakeTag(fieldIndex, WireBytes)) // 计算变长单元大小 var size int @@ -118,7 +119,7 @@ func MarshalUInt64Slice(b *Buffer, fieldIndex uint64, value []uint64) error { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireBytes)) + b.EncodeVarint(MakeTag(fieldIndex, WireBytes)) // 计算变长单元大小 var size int @@ -142,7 +143,7 @@ func MarshalStringSlice(b *Buffer, fieldIndex uint64, value []string) error { } for _, v := range value { - b.EncodeVarint(makeWireTag(fieldIndex, WireBytes)) + b.EncodeVarint(MakeTag(fieldIndex, WireBytes)) b.EncodeStringBytes(v) } @@ -156,7 +157,7 @@ func MarshalFloat32Slice(b *Buffer, fieldIndex uint64, value []float32) error { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireBytes)) + b.EncodeVarint(MakeTag(fieldIndex, WireBytes)) // 写入长度 b.EncodeVarint(uint64(count * 4)) @@ -175,7 +176,7 @@ func MarshalFloat64Slice(b *Buffer, fieldIndex uint64, value []float64) error { return nil } - b.EncodeVarint(makeWireTag(fieldIndex, WireBytes)) + b.EncodeVarint(MakeTag(fieldIndex, WireBytes)) // 写入长度 b.EncodeVarint(uint64(count * 8)) diff --git a/proto/slice_size.go b/wire/slice_size.go similarity index 79% rename from proto/slice_size.go rename to wire/slice_size.go index 2eee558..d994097 100644 --- a/proto/slice_size.go +++ b/wire/slice_size.go @@ -1,4 +1,4 @@ -package proto +package wire func SizeBytes(fieldIndex uint64, value []byte) int { @@ -9,7 +9,7 @@ func SizeBytes(fieldIndex uint64, value []byte) int { size := count * 1 - return SizeVarint(makeWireTag(fieldIndex, WireBytes)) + SizeVarint(uint64(size)) + size + return SizeVarint(MakeTag(fieldIndex, WireBytes)) + SizeVarint(uint64(size)) + size } func SizeBoolSlice(fieldIndex uint64, value []bool) int { @@ -21,7 +21,7 @@ func SizeBoolSlice(fieldIndex uint64, value []bool) int { size := count * 1 - return SizeVarint(makeWireTag(fieldIndex, WireBytes)) + SizeVarint(uint64(size)) + size + return SizeVarint(MakeTag(fieldIndex, WireBytes)) + SizeVarint(uint64(size)) + size } func SizeInt32Slice(fieldIndex uint64, value []int32) (ret int) { @@ -31,7 +31,7 @@ func SizeInt32Slice(fieldIndex uint64, value []int32) (ret int) { return 0 } - ret = SizeVarint(makeWireTag(fieldIndex, WireBytes)) + ret = SizeVarint(MakeTag(fieldIndex, WireBytes)) // 后部分的长度 size := 0 @@ -53,7 +53,7 @@ func SizeUInt32Slice(fieldIndex uint64, value []uint32) (ret int) { return 0 } - ret = SizeVarint(makeWireTag(fieldIndex, WireBytes)) + ret = SizeVarint(MakeTag(fieldIndex, WireBytes)) // 后部分的长度 size := 0 @@ -75,7 +75,7 @@ func SizeInt64Slice(fieldIndex uint64, value []int64) (ret int) { return 0 } - ret = SizeVarint(makeWireTag(fieldIndex, WireBytes)) + ret = SizeVarint(MakeTag(fieldIndex, WireBytes)) // 后部分的长度 size := 0 @@ -97,7 +97,7 @@ func SizeUInt64Slice(fieldIndex uint64, value []uint64) (ret int) { return 0 } - ret = SizeVarint(makeWireTag(fieldIndex, WireBytes)) + ret = SizeVarint(MakeTag(fieldIndex, WireBytes)) // 后部分的长度 size := 0 @@ -132,7 +132,7 @@ func SizeFloat32Slice(fieldIndex uint64, value []float32) (ret int) { return 0 } - ret = SizeVarint(makeWireTag(fieldIndex, WireBytes)) + ret = SizeVarint(MakeTag(fieldIndex, WireBytes)) size := count * 4 @@ -150,7 +150,7 @@ func SizeFloat64Slice(fieldIndex uint64, value []float64) (ret int) { return 0 } - ret = SizeVarint(makeWireTag(fieldIndex, WireBytes)) + ret = SizeVarint(MakeTag(fieldIndex, WireBytes)) size := count * 8 diff --git a/proto/slice_unmarshal.go b/wire/slice_unmarshal.go similarity index 99% rename from proto/slice_unmarshal.go rename to wire/slice_unmarshal.go index 35909ec..7482c44 100644 --- a/proto/slice_unmarshal.go +++ b/wire/slice_unmarshal.go @@ -1,6 +1,8 @@ -package proto +package wire -import "io" +import ( + "io" +) func UnmarshalBytes(b *Buffer, wt WireType) ([]byte, error) { diff --git a/wire/struct.go b/wire/struct.go new file mode 100644 index 0000000..b74d205 --- /dev/null +++ b/wire/struct.go @@ -0,0 +1,99 @@ +package wire + +import ( + "io" + "reflect" +) + +type Struct interface { + Marshal(buffer *Buffer) error + + Unmarshal(buffer *Buffer, fieldIndex uint64, wt WireType) error + + Size() int +} + +func MarshalStruct(b *Buffer, fieldIndex uint64, msg Struct) error { + + structValue := reflect.ValueOf(msg) + + // *MyType被Message包裹后,判断不为nil + if structValue.IsNil() { + return nil + } + + size := msg.Size() + if size == 0 { + return nil + } + + b.EncodeVarint(MakeTag(fieldIndex, WireBytes)) + + b.EncodeVarint(uint64(size)) + + return msg.Marshal(b) +} + +func SizeStruct(fieldIndex uint64, msg Struct) int { + + structValue := reflect.ValueOf(msg) + + // *MyType被Message包裹后,判断不为nil + if structValue.IsNil() { + return 0 + } + + size := msg.Size() + + if size == 0 { + return 0 + } + + return SizeVarint(MakeTag(fieldIndex, WireVarint)) + SizeVarint(uint64(size)) + size +} + +func UnmarshalStructObject(b *Buffer, msg Struct) error { + + for b.BytesRemains() > 0 { + wireTag, err := b.DecodeVarint() + + if err != nil { + return err + } + + fieldIndex, wt := ParseTag(wireTag) + + err = msg.Unmarshal(b, fieldIndex, wt) + + if err == ErrUnknownField { + err = skipField(b, wt) + } + + if err != nil { + return err + } + } + + return nil +} + +func UnmarshalStruct(b *Buffer, wt WireType, msgPtr Struct) error { + switch wt { + case WireBytes: + size, err := b.DecodeVarint() + if err != nil { + return err + } + + if b.BytesRemains() < int(size) { + return io.ErrUnexpectedEOF + } + + limitBuffer := NewBuffer(b.ConsumeBytes(int(size))) + + return UnmarshalStructObject(limitBuffer, msgPtr) + + default: + return ErrBadWireType + } +} diff --git a/proto/variant.go b/wire/variant.go similarity index 98% rename from proto/variant.go rename to wire/variant.go index b7a7fb3..f483e78 100644 --- a/proto/variant.go +++ b/wire/variant.go @@ -1,4 +1,4 @@ -package proto +package wire const maxVarintBytes = 10 // maximum length of a varint diff --git a/proto/wiretype.go b/wire/wiretype.go similarity index 79% rename from proto/wiretype.go rename to wire/wiretype.go index dbd07a0..4a94c09 100644 --- a/proto/wiretype.go +++ b/wire/wiretype.go @@ -1,4 +1,4 @@ -package proto +package wire type WireType = uint64 @@ -11,11 +11,11 @@ const ( WireFixed64 // 64位定长 float64 ) -func makeWireTag(tag uint64, wt WireType) WireType { +func MakeTag(tag uint64, wt WireType) WireType { return uint64(tag)<<3 | uint64(wt) } -func parseWireTag(wireTag WireType) (tag uint64, wt WireType) { +func ParseTag(wireTag WireType) (tag uint64, wt WireType) { tag = wireTag >> 3 wt = WireType(wireTag & 7) return From d6934aac6fe99401dec6b4487c36d96f2dffc96c Mon Sep 17 00:00:00 2001 From: davyxu Date: Thu, 9 Jul 2020 15:22:19 +0800 Subject: [PATCH 05/39] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8F=8D?= =?UTF-8?q?=E5=B0=84=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 11 ++- go.sum | 17 +++- proto/api.go | 8 +- tests/code_test.go | 95 ++++++++++++++------ text/parse.go | 216 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 316 insertions(+), 31 deletions(-) create mode 100644 text/parse.go diff --git a/go.mod b/go.mod index 46414ab..9bfd73f 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,13 @@ module github.com/davyxu/protoplus go 1.12 -require github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200 +require ( + github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200 + github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50 + github.com/davyxu/ureflect v0.0.0-20200707090133-2cae47a4db63 + github.com/stretchr/testify v1.6.1 +) + +replace github.com/davyxu/ureflect => ../ureflect + +replace github.com/davyxu/ulexer => ../ulexer diff --git a/go.sum b/go.sum index ab0c915..0af858b 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,17 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200 h1:qLWlQBFg5c7HUOK+UdoGouLzRaYBQr2WwoAqixU+eik= github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200/go.mod h1:K/1PVWqaQEwMs+N+VvaoS66o1BAAwso+jEgXKBIa8QY= -github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50 h1:LhNcRLxSnxoE6nfEEBdNib+r932OtQoea7ZUZNh27zs= +github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50/go.mod h1:0aiydOTmjo/kWslAOerN4nz9Mlia75fwDs9LXp+Ed1c= +github.com/go-test/deep v1.0.6 h1:UHSEyLZUwX9Qoi99vVwvewiMC8mM2bf7XEM2nqvzEn8= +github.com/go-test/deep v1.0.6/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/proto/api.go b/proto/api.go index f63fe2b..0ab5f1b 100644 --- a/proto/api.go +++ b/proto/api.go @@ -4,7 +4,9 @@ import ( "github.com/davyxu/protoplus/wire" ) -func Marshal(msg wire.Struct) ([]byte, error) { +type Struct = wire.Struct + +func Marshal(msg Struct) ([]byte, error) { l := msg.Size() @@ -21,12 +23,12 @@ func Marshal(msg wire.Struct) ([]byte, error) { } -func Size(msg wire.Struct) int { +func Size(msg Struct) int { return msg.Size() } -func Unmarshal(data []byte, msg wire.Struct) (err error) { +func Unmarshal(data []byte, msg Struct) (err error) { buffer := wire.NewBuffer(data) diff --git a/tests/code_test.go b/tests/code_test.go index 1fb5c8b..44f8787 100644 --- a/tests/code_test.go +++ b/tests/code_test.go @@ -2,7 +2,9 @@ package tests import ( "github.com/davyxu/protoplus/proto" + "github.com/davyxu/protoplus/text" "github.com/davyxu/protoplus/wire" + "github.com/stretchr/testify/assert" "math" "reflect" "testing" @@ -11,18 +13,12 @@ import ( func TestOptional(t *testing.T) { bigData := makeMyType() data, err := proto.Marshal(&bigData) - if err != nil { - t.Error(err) - t.FailNow() - } + assert.Equal(t, err, nil) var output MyTypeMini - err = proto.Unmarshal(data, &output) - if err != nil { - t.Error(err) - t.FailNow() - } + assert.Equal(t, proto.Unmarshal(data, &output), nil) t.Logf("%+v", output) + assert.Equal(t, bigData, output) } @@ -61,34 +57,43 @@ func makeMyType() (input MyType) { return } -func verify(t *testing.T, raw wire.Struct) { - t.Logf("size: %d", proto.Size(raw)) - +func verifyWire(t *testing.T, raw wire.Struct) { data, err := proto.Marshal(raw) - if err != nil { - t.Error(err) - t.FailNow() - } + assert.Equal(t, err, nil) + t.Log("proto+:", len(data), data) newType := reflect.New(reflect.TypeOf(raw).Elem()).Interface().(wire.Struct) - err = proto.Unmarshal(data, newType) - if err != nil { - t.Error(err) - t.FailNow() - } + assert.Equal(t, proto.Unmarshal(data, newType), nil) + + assert.Equal(t, raw, newType) +} + +func verifyText(t *testing.T, raw interface{}) { - if !reflect.DeepEqual(raw, newType) { - t.FailNow() + tRaw := reflect.TypeOf(raw) + + if tRaw.Kind() != reflect.Ptr { + panic("expect ptr") } + + data := proto.CompactTextString(raw) + + t.Log(data) + + newType := reflect.New(tRaw.Elem()).Interface() + + assert.Equal(t, text.UnmarshalText(data, newType), nil) + + assert.Equal(t, raw, newType) } func TestFull(t *testing.T) { input := makeMyType() - verify(t, &input) + verifyWire(t, &input) t.Logf("%v", proto.MarshalTextString(input)) } @@ -98,5 +103,45 @@ func TestIntSlice(t *testing.T) { var input MyType input.Int32Slice = []int32{-1, 1, 2} - verify(t, &input) + verifyWire(t, &input) +} + +func TestText(t *testing.T) { + + input := makeMyType() + + //var input MyType + //input.Int32Slice = []int32{-1, 1, 2} + + verifyText(t, &input) +} + +func TestFloat(t *testing.T) { + + type MyFloat struct { + Value float64 + } + + input := MyFloat{math.MaxFloat64} + + verifyText(t, &input) +} + +func TestSlice(t *testing.T) { + + type DummyStruct struct { + Num int32 + } + + type MyFloat struct { + Value []int32 + Dummy DummyStruct + } + + input := MyFloat{ + []int32{-1, 1, 2}, + DummyStruct{5}, + } + + verifyText(t, &input) } diff --git a/text/parse.go b/text/parse.go new file mode 100644 index 0000000..1bfe9ce --- /dev/null +++ b/text/parse.go @@ -0,0 +1,216 @@ +package text + +import ( + "github.com/davyxu/ulexer" + "github.com/davyxu/ureflect" +) + +func detectEnd(lex *ulexer.Lexer, literal string) bool { + if literal != "" { + lex.Read(ulexer.WhiteSpace()) + if tk := lex.Read(ulexer.Contain(literal)); tk.String() == literal { + return true + } + } + + return false +} + +func parseStruct(lex *ulexer.Lexer, tObj *ureflect.Type, vObj ureflect.Pointer, endLiteral string) { + for { + + if detectEnd(lex, endLiteral) { + break + } + + fieldTk := ulexer.NextToken(lex, ulexer.Identifier()) + + tField := tObj.FieldByName(fieldTk.String()) + + //fmt.Println(tObj.Name(), tField.Name) + + if tField.Name == "BytesSlice" { + tField.Name = tField.Name + } + + ulexer.NextToken(lex, ulexer.Contain(":")) + + lex.Read(ulexer.WhiteSpace()) + + parseValue(lex, func(tk *ulexer.Token) { + if tField == nil { + return + } + + switch tField.Type().Kind() { + case ureflect.Bool: + tField.SetBool(vObj, tk.Bool()) + case ureflect.String: + tField.SetString(vObj, tk.String()) + case ureflect.Int32: + tField.SetInt32(vObj, tk.Int32()) + case ureflect.Int64: + tField.SetInt64(vObj, tk.Int64()) + case ureflect.UInt32: + tField.SetUInt32(vObj, tk.UInt32()) + case ureflect.UInt64: + tField.SetUInt64(vObj, tk.UInt64()) + case ureflect.Float32: + tField.SetFloat32(vObj, tk.Float32()) + case ureflect.Float64: + tField.SetFloat64(vObj, tk.Float64()) + case ureflect.Slice: + parseArray(lex, tField, vObj, "]") + case ureflect.Struct: + parseStruct(lex, tField.Type(), tField.Value(vObj), "}") + default: + panic("unsupport field kind " + tField.Type().Kind().String()) + } + }) + } +} + +func parseValue(lex *ulexer.Lexer, action ulexer.MatchAction) { + lex.SelectAction( + []ulexer.Matcher{ulexer.String(), + ulexer.Numeral(), + ulexer.Bool(), + ulexer.Contain("["), + ulexer.Contain("{"), + ulexer.Identifier(), + }, + []ulexer.MatchAction{ + action, + action, + action, + action, + action, + action, + }, + ) +} + +func parseElement(lex *ulexer.Lexer, endLiteral string, onValue ulexer.MatchAction, onEnd func()) { + for { + + if detectEnd(lex, endLiteral) { + onEnd() + break + } + + parseValue(lex, onValue) + } + +} + +func parseArray(lex *ulexer.Lexer, tField *ureflect.Field, vObj ureflect.Pointer, endLiteral string) { + + switch tField.Type().Elem().Kind() { + case ureflect.Int32: + var value []int32 + // TODO 按整数parse + parseElement(lex, endLiteral, func(tk *ulexer.Token) { + value = append(value, tk.Int32()) + }, func() { + tField.SetInt32Slice(vObj, value) + }) + case ureflect.Int64: + var value []int64 + // TODO 按整数parse + parseElement(lex, endLiteral, func(tk *ulexer.Token) { + value = append(value, tk.Int64()) + }, func() { + tField.SetInt64Slice(vObj, value) + }) + case ureflect.UInt64: + var value []uint64 + // TODO 按整数parse + parseElement(lex, endLiteral, func(tk *ulexer.Token) { + value = append(value, tk.UInt64()) + }, func() { + tField.SetUInt64Slice(vObj, value) + }) + case ureflect.Float32: + var value []float32 + parseElement(lex, endLiteral, func(tk *ulexer.Token) { + value = append(value, tk.Float32()) + }, func() { + tField.SetFloat32Slice(vObj, value) + }) + case ureflect.Float64: + var value []float64 + parseElement(lex, endLiteral, func(tk *ulexer.Token) { + value = append(value, tk.Float64()) + }, func() { + tField.SetFloat64Slice(vObj, value) + }) + case ureflect.UInt32: + var value []uint32 + // TODO 按整数parse + parseElement(lex, endLiteral, func(tk *ulexer.Token) { + value = append(value, tk.UInt32()) + }, func() { + tField.SetUInt32Slice(vObj, value) + }) + case ureflect.Bool: + var value []bool + parseElement(lex, endLiteral, func(tk *ulexer.Token) { + value = append(value, tk.Bool()) + }, func() { + tField.SetBoolSlice(vObj, value) + }) + case ureflect.String: + var value []string + parseElement(lex, endLiteral, func(tk *ulexer.Token) { + value = append(value, tk.String()) + }, func() { + tField.SetStringSlice(vObj, value) + }) + case ureflect.UInt8: + var value []byte + // TODO 按整数parse + parseElement(lex, endLiteral, func(tk *ulexer.Token) { + value = append(value, tk.UInt8()) + }, func() { + tField.SetBytes(vObj, value) + }) + case ureflect.Struct: + + list := tField.Type().New() + for { + + if detectEnd(lex, endLiteral) { + break + } + + lex.Read(ulexer.WhiteSpace()) + lex.Expect(ulexer.Contain("{")) + + element := tField.Type().Elem().New() + + parseStruct(lex, tField.Type().Elem(), element, "}") + + tField.SetValue(vObj, ureflect.PointerOf(list)) + } + + default: + panic("unsupport array element " + tField.Type().Kind().String()) + } + +} + +func UnmarshalText(s string, obj interface{}) error { + + vObj := ureflect.PointerOf(obj) + tObj := ureflect.TypeOf(obj) + + lex := ulexer.NewLexer(s) + + err := lex.Run(func(lex *ulexer.Lexer) { + + parseStruct(lex, tObj, vObj, "") + + }) + + return err +} From af78dae93dc7395b86e99040537cc1d076ffa55b Mon Sep 17 00:00:00 2001 From: davyxu Date: Fri, 10 Jul 2020 16:52:40 +0800 Subject: [PATCH 06/39] =?UTF-8?q?=E6=8D=A2=E5=8F=8D=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 3 - proto/text_marshaler.go | 12 +++ tests/code_test.go | 16 ++++ text/parse.go | 167 ++++++++++++++++++++++++---------------- 4 files changed, 129 insertions(+), 69 deletions(-) diff --git a/go.mod b/go.mod index 9bfd73f..9b95afd 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,7 @@ go 1.12 require ( github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200 github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50 - github.com/davyxu/ureflect v0.0.0-20200707090133-2cae47a4db63 github.com/stretchr/testify v1.6.1 ) -replace github.com/davyxu/ureflect => ../ureflect - replace github.com/davyxu/ulexer => ../ulexer diff --git a/proto/text_marshaler.go b/proto/text_marshaler.go index 89bfd95..6195b5c 100644 --- a/proto/text_marshaler.go +++ b/proto/text_marshaler.go @@ -159,6 +159,18 @@ func (self *TextMarshaler) writeAny(w *textWriter, v reflect.Value) error { if err := w.WriteByte(ket); err != nil { return err } + case reflect.Int32: + // 枚举切片的值应该是输出整形 + if _, ok := v.Interface().(fmt.Stringer); ok { + + _, err := fmt.Fprint(w, v.Int()) + return err + + } else { + _, err := fmt.Fprint(w, v.Interface()) + return err + } + default: _, err := fmt.Fprint(w, v.Interface()) return err diff --git a/tests/code_test.go b/tests/code_test.go index 44f8787..2164b2c 100644 --- a/tests/code_test.go +++ b/tests/code_test.go @@ -1,6 +1,8 @@ package tests import ( + "encoding/json" + "fmt" "github.com/davyxu/protoplus/proto" "github.com/davyxu/protoplus/text" "github.com/davyxu/protoplus/wire" @@ -110,6 +112,9 @@ func TestText(t *testing.T) { input := makeMyType() + data, _ := json.Marshal(input) + fmt.Println(string(data)) + //var input MyType //input.Int32Slice = []int32{-1, 1, 2} @@ -145,3 +150,14 @@ func TestSlice(t *testing.T) { verifyText(t, &input) } + +func TestEnum(t *testing.T) { + + type MyFloat struct { + Value []MyEnum + } + + input := MyFloat{Value: []MyEnum{MyEnum_One}} + + verifyText(t, &input) +} diff --git a/text/parse.go b/text/parse.go index 1bfe9ce..484d303 100644 --- a/text/parse.go +++ b/text/parse.go @@ -2,7 +2,7 @@ package text import ( "github.com/davyxu/ulexer" - "github.com/davyxu/ureflect" + "reflect" ) func detectEnd(lex *ulexer.Lexer, literal string) bool { @@ -16,7 +16,7 @@ func detectEnd(lex *ulexer.Lexer, literal string) bool { return false } -func parseStruct(lex *ulexer.Lexer, tObj *ureflect.Type, vObj ureflect.Pointer, endLiteral string) { +func parseStruct(lex *ulexer.Lexer, tObj reflect.Type, vObj reflect.Value, endLiteral string) { for { if detectEnd(lex, endLiteral) { @@ -25,46 +25,41 @@ func parseStruct(lex *ulexer.Lexer, tObj *ureflect.Type, vObj ureflect.Pointer, fieldTk := ulexer.NextToken(lex, ulexer.Identifier()) - tField := tObj.FieldByName(fieldTk.String()) - - //fmt.Println(tObj.Name(), tField.Name) - - if tField.Name == "BytesSlice" { - tField.Name = tField.Name - } + tField, fieldExists := tObj.FieldByName(fieldTk.String()) + vField := vObj.FieldByName(fieldTk.String()) ulexer.NextToken(lex, ulexer.Contain(":")) lex.Read(ulexer.WhiteSpace()) parseValue(lex, func(tk *ulexer.Token) { - if tField == nil { + if !fieldExists { return } - switch tField.Type().Kind() { - case ureflect.Bool: - tField.SetBool(vObj, tk.Bool()) - case ureflect.String: - tField.SetString(vObj, tk.String()) - case ureflect.Int32: - tField.SetInt32(vObj, tk.Int32()) - case ureflect.Int64: - tField.SetInt64(vObj, tk.Int64()) - case ureflect.UInt32: - tField.SetUInt32(vObj, tk.UInt32()) - case ureflect.UInt64: - tField.SetUInt64(vObj, tk.UInt64()) - case ureflect.Float32: - tField.SetFloat32(vObj, tk.Float32()) - case ureflect.Float64: - tField.SetFloat64(vObj, tk.Float64()) - case ureflect.Slice: - parseArray(lex, tField, vObj, "]") - case ureflect.Struct: - parseStruct(lex, tField.Type(), tField.Value(vObj), "}") + switch tField.Type.Kind() { + case reflect.Bool: + vField.SetBool(tk.Bool()) + case reflect.String: + vField.SetString(tk.String()) + case reflect.Int32: + vField.SetInt(int64(tk.Int32())) + case reflect.Int64: + vField.SetInt(int64(tk.Int64())) + case reflect.Uint32: + vField.SetUint(uint64(tk.UInt32())) + case reflect.Uint64: + vField.SetUint(uint64(tk.UInt64())) + case reflect.Float32: + vField.SetFloat(float64(tk.Float32())) + case reflect.Float64: + vField.SetFloat(tk.Float64()) + case reflect.Slice: + parseArray(lex, tField.Type, vField, "]") + case reflect.Struct: + parseStruct(lex, tField.Type, vField, "}") default: - panic("unsupport field kind " + tField.Type().Kind().String()) + panic("unsupport field kind " + tField.Type.Kind().String()) } }) } @@ -103,80 +98,100 @@ func parseElement(lex *ulexer.Lexer, endLiteral string, onValue ulexer.MatchActi } -func parseArray(lex *ulexer.Lexer, tField *ureflect.Field, vObj ureflect.Pointer, endLiteral string) { +func parseArray(lex *ulexer.Lexer, tField reflect.Type, vObj reflect.Value, endLiteral string) { - switch tField.Type().Elem().Kind() { - case ureflect.Int32: - var value []int32 - // TODO 按整数parse - parseElement(lex, endLiteral, func(tk *ulexer.Token) { - value = append(value, tk.Int32()) - }, func() { - tField.SetInt32Slice(vObj, value) - }) - case ureflect.Int64: + switch tField.Elem().Kind() { + case reflect.Int32: + + // 枚举 + if vObj.Kind() != reflect.Int32 { + + list := reflect.MakeSlice(vObj.Type(), 0, 0) + + parseElement(lex, endLiteral, func(tk *ulexer.Token) { + + vElm := reflect.ValueOf(tk.Int32()) + + list = reflect.Append(list, vElm.Convert(vObj.Type().Elem())) + }, func() { + + vObj.Set(list) + }) + + } else { + var value []int32 + // TODO 按整数parse + parseElement(lex, endLiteral, func(tk *ulexer.Token) { + value = append(value, tk.Int32()) + }, func() { + + vObj.Set(reflect.ValueOf(value)) + }) + } + + case reflect.Int64: var value []int64 // TODO 按整数parse parseElement(lex, endLiteral, func(tk *ulexer.Token) { value = append(value, tk.Int64()) }, func() { - tField.SetInt64Slice(vObj, value) + vObj.Set(reflect.ValueOf(value)) }) - case ureflect.UInt64: + case reflect.Uint64: var value []uint64 // TODO 按整数parse parseElement(lex, endLiteral, func(tk *ulexer.Token) { value = append(value, tk.UInt64()) }, func() { - tField.SetUInt64Slice(vObj, value) + vObj.Set(reflect.ValueOf(value)) }) - case ureflect.Float32: + case reflect.Float32: var value []float32 parseElement(lex, endLiteral, func(tk *ulexer.Token) { value = append(value, tk.Float32()) }, func() { - tField.SetFloat32Slice(vObj, value) + vObj.Set(reflect.ValueOf(value)) }) - case ureflect.Float64: + case reflect.Float64: var value []float64 parseElement(lex, endLiteral, func(tk *ulexer.Token) { value = append(value, tk.Float64()) }, func() { - tField.SetFloat64Slice(vObj, value) + vObj.Set(reflect.ValueOf(value)) }) - case ureflect.UInt32: + case reflect.Uint32: var value []uint32 // TODO 按整数parse parseElement(lex, endLiteral, func(tk *ulexer.Token) { value = append(value, tk.UInt32()) }, func() { - tField.SetUInt32Slice(vObj, value) + vObj.Set(reflect.ValueOf(value)) }) - case ureflect.Bool: + case reflect.Bool: var value []bool parseElement(lex, endLiteral, func(tk *ulexer.Token) { value = append(value, tk.Bool()) }, func() { - tField.SetBoolSlice(vObj, value) + vObj.Set(reflect.ValueOf(value)) }) - case ureflect.String: + case reflect.String: var value []string parseElement(lex, endLiteral, func(tk *ulexer.Token) { value = append(value, tk.String()) }, func() { - tField.SetStringSlice(vObj, value) + vObj.Set(reflect.ValueOf(value)) }) - case ureflect.UInt8: + case reflect.Uint8: var value []byte // TODO 按整数parse parseElement(lex, endLiteral, func(tk *ulexer.Token) { value = append(value, tk.UInt8()) }, func() { - tField.SetBytes(vObj, value) + vObj.SetBytes(value) }) - case ureflect.Struct: + case reflect.Struct: - list := tField.Type().New() + list := reflect.MakeSlice(tField, 0, 0) for { if detectEnd(lex, endLiteral) { @@ -186,23 +201,43 @@ func parseArray(lex *ulexer.Lexer, tField *ureflect.Field, vObj ureflect.Pointer lex.Read(ulexer.WhiteSpace()) lex.Expect(ulexer.Contain("{")) - element := tField.Type().Elem().New() + element := reflect.New(tField.Elem()).Elem() - parseStruct(lex, tField.Type().Elem(), element, "}") + parseStruct(lex, tField.Elem(), element, "}") - tField.SetValue(vObj, ureflect.PointerOf(list)) + list = reflect.Append(list, element) + + vObj.Set(list) } default: - panic("unsupport array element " + tField.Type().Kind().String()) + panic("unsupport array element " + tField.Kind().String()) + } + +} + +func safeValueOf(obj interface{}) reflect.Value { + vObj := reflect.ValueOf(obj) + if vObj.Kind() == reflect.Ptr { + return vObj.Elem() + } + + return vObj +} + +func safeTypeOf(obj interface{}) reflect.Type { + tObj := reflect.TypeOf(obj) + if tObj.Kind() == reflect.Ptr { + return tObj.Elem() } + return tObj } func UnmarshalText(s string, obj interface{}) error { - vObj := ureflect.PointerOf(obj) - tObj := ureflect.TypeOf(obj) + vObj := safeValueOf(obj) + tObj := safeTypeOf(obj) lex := ulexer.NewLexer(s) From c4e2963edde4f103a0d65e97d77ab69e86ae19bf Mon Sep 17 00:00:00 2001 From: davyxu Date: Fri, 10 Jul 2020 18:06:15 +0800 Subject: [PATCH 07/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- text/parse.go | 63 ++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/text/parse.go b/text/parse.go index 484d303..f3bd255 100644 --- a/text/parse.go +++ b/text/parse.go @@ -32,7 +32,13 @@ func parseStruct(lex *ulexer.Lexer, tObj reflect.Type, vObj reflect.Value, endLi lex.Read(ulexer.WhiteSpace()) - parseValue(lex, func(tk *ulexer.Token) { + parseMultiValue(lex, []ulexer.Matcher{ulexer.String(), + ulexer.Numeral(), + ulexer.Bool(), + ulexer.Contain("["), + ulexer.Contain("{"), + ulexer.Identifier(), + }, func(tk *ulexer.Token) { if !fieldExists { return } @@ -65,27 +71,20 @@ func parseStruct(lex *ulexer.Lexer, tObj reflect.Type, vObj reflect.Value, endLi } } -func parseValue(lex *ulexer.Lexer, action ulexer.MatchAction) { +func parseMultiValue(lex *ulexer.Lexer, mlist []ulexer.Matcher, action ulexer.MatchAction) { + + alist := make([]ulexer.MatchAction, 0, len(mlist)) + for i := 0; i < len(mlist); i++ { + alist = append(alist, action) + } + lex.SelectAction( - []ulexer.Matcher{ulexer.String(), - ulexer.Numeral(), - ulexer.Bool(), - ulexer.Contain("["), - ulexer.Contain("{"), - ulexer.Identifier(), - }, - []ulexer.MatchAction{ - action, - action, - action, - action, - action, - action, - }, + mlist, + alist, ) } -func parseElement(lex *ulexer.Lexer, endLiteral string, onValue ulexer.MatchAction, onEnd func()) { +func parseElement(lex *ulexer.Lexer, endLiteral string, m ulexer.Matcher, onValue ulexer.MatchAction, onEnd func()) { for { if detectEnd(lex, endLiteral) { @@ -93,7 +92,8 @@ func parseElement(lex *ulexer.Lexer, endLiteral string, onValue ulexer.MatchActi break } - parseValue(lex, onValue) + tk := lex.Expect(m) + onValue(tk) } } @@ -108,7 +108,7 @@ func parseArray(lex *ulexer.Lexer, tField reflect.Type, vObj reflect.Value, endL list := reflect.MakeSlice(vObj.Type(), 0, 0) - parseElement(lex, endLiteral, func(tk *ulexer.Token) { + parseElement(lex, endLiteral, ulexer.Integer(), func(tk *ulexer.Token) { vElm := reflect.ValueOf(tk.Int32()) @@ -120,8 +120,7 @@ func parseArray(lex *ulexer.Lexer, tField reflect.Type, vObj reflect.Value, endL } else { var value []int32 - // TODO 按整数parse - parseElement(lex, endLiteral, func(tk *ulexer.Token) { + parseElement(lex, endLiteral, ulexer.Integer(), func(tk *ulexer.Token) { value = append(value, tk.Int32()) }, func() { @@ -131,60 +130,56 @@ func parseArray(lex *ulexer.Lexer, tField reflect.Type, vObj reflect.Value, endL case reflect.Int64: var value []int64 - // TODO 按整数parse - parseElement(lex, endLiteral, func(tk *ulexer.Token) { + parseElement(lex, endLiteral, ulexer.Integer(), func(tk *ulexer.Token) { value = append(value, tk.Int64()) }, func() { vObj.Set(reflect.ValueOf(value)) }) case reflect.Uint64: var value []uint64 - // TODO 按整数parse - parseElement(lex, endLiteral, func(tk *ulexer.Token) { + parseElement(lex, endLiteral, ulexer.UInteger(), func(tk *ulexer.Token) { value = append(value, tk.UInt64()) }, func() { vObj.Set(reflect.ValueOf(value)) }) case reflect.Float32: var value []float32 - parseElement(lex, endLiteral, func(tk *ulexer.Token) { + parseElement(lex, endLiteral, ulexer.Numeral(), func(tk *ulexer.Token) { value = append(value, tk.Float32()) }, func() { vObj.Set(reflect.ValueOf(value)) }) case reflect.Float64: var value []float64 - parseElement(lex, endLiteral, func(tk *ulexer.Token) { + parseElement(lex, endLiteral, ulexer.Numeral(), func(tk *ulexer.Token) { value = append(value, tk.Float64()) }, func() { vObj.Set(reflect.ValueOf(value)) }) case reflect.Uint32: var value []uint32 - // TODO 按整数parse - parseElement(lex, endLiteral, func(tk *ulexer.Token) { + parseElement(lex, endLiteral, ulexer.UInteger(), func(tk *ulexer.Token) { value = append(value, tk.UInt32()) }, func() { vObj.Set(reflect.ValueOf(value)) }) case reflect.Bool: var value []bool - parseElement(lex, endLiteral, func(tk *ulexer.Token) { + parseElement(lex, endLiteral, ulexer.Bool(), func(tk *ulexer.Token) { value = append(value, tk.Bool()) }, func() { vObj.Set(reflect.ValueOf(value)) }) case reflect.String: var value []string - parseElement(lex, endLiteral, func(tk *ulexer.Token) { + parseElement(lex, endLiteral, ulexer.String(), func(tk *ulexer.Token) { value = append(value, tk.String()) }, func() { vObj.Set(reflect.ValueOf(value)) }) case reflect.Uint8: var value []byte - // TODO 按整数parse - parseElement(lex, endLiteral, func(tk *ulexer.Token) { + parseElement(lex, endLiteral, ulexer.Numeral(), func(tk *ulexer.Token) { value = append(value, tk.UInt8()) }, func() { vObj.SetBytes(value) From ed8eadf31e9439e7dd33e13d8400b7667ebe0b18 Mon Sep 17 00:00:00 2001 From: davyxu Date: Mon, 13 Jul 2020 13:47:23 +0800 Subject: [PATCH 08/39] =?UTF-8?q?=E6=96=87=E6=9C=AC=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proto/api.go | 35 +++++++++++++++++++++++++++ proto/text_marshaler.go | 11 --------- text/parse.go => proto/text_parser.go | 26 +++----------------- tests/code_test.go | 11 +-------- 4 files changed, 39 insertions(+), 44 deletions(-) rename text/parse.go => proto/text_parser.go (91%) diff --git a/proto/api.go b/proto/api.go index 0ab5f1b..b665cc9 100644 --- a/proto/api.go +++ b/proto/api.go @@ -2,6 +2,7 @@ package proto import ( "github.com/davyxu/protoplus/wire" + "github.com/davyxu/ulexer" ) type Struct = wire.Struct @@ -34,3 +35,37 @@ func Unmarshal(data []byte, msg Struct) (err error) { return wire.UnmarshalStructObject(buffer, msg) } + +var ( + defaultTextMarshaler = TextMarshaler{} + compactTextMarshaler = TextMarshaler{Compact: true, IgnoreDefault: true, CompactBytesSize: 50} +) + +func MarshalTextString(obj interface{}) string { + return defaultTextMarshaler.Text(obj) +} + +func CompactTextString(obj interface{}) string { return compactTextMarshaler.Text(obj) } + +func UnmarshalText(s string, obj interface{}) error { + + vObj := safeValueOf(obj) + tObj := safeTypeOf(obj) + + lex := ulexer.NewLexer(s) + + // 读之前, 清掉空白 + lex.SetPreHook(func(lex *ulexer.Lexer) *ulexer.Token { + + lex.Read(ulexer.WhiteSpace()) + return nil + }) + + err := lex.Run(func(lex *ulexer.Lexer) { + + parseStruct(lex, tObj, vObj, "") + + }) + + return err +} diff --git a/proto/text_marshaler.go b/proto/text_marshaler.go index 6195b5c..b8a46ec 100644 --- a/proto/text_marshaler.go +++ b/proto/text_marshaler.go @@ -371,14 +371,3 @@ func (self *TextMarshaler) Text(obj interface{}) string { self.Marshal(&buf, obj) return buf.String() } - -var ( - defaultTextMarshaler = TextMarshaler{} - compactTextMarshaler = TextMarshaler{Compact: true, IgnoreDefault: true, CompactBytesSize: 50} -) - -func MarshalTextString(obj interface{}) string { - return defaultTextMarshaler.Text(obj) -} - -func CompactTextString(obj interface{}) string { return compactTextMarshaler.Text(obj) } diff --git a/text/parse.go b/proto/text_parser.go similarity index 91% rename from text/parse.go rename to proto/text_parser.go index f3bd255..0d16ed5 100644 --- a/text/parse.go +++ b/proto/text_parser.go @@ -1,4 +1,4 @@ -package text +package proto import ( "github.com/davyxu/ulexer" @@ -7,7 +7,6 @@ import ( func detectEnd(lex *ulexer.Lexer, literal string) bool { if literal != "" { - lex.Read(ulexer.WhiteSpace()) if tk := lex.Read(ulexer.Contain(literal)); tk.String() == literal { return true } @@ -23,14 +22,12 @@ func parseStruct(lex *ulexer.Lexer, tObj reflect.Type, vObj reflect.Value, endLi break } - fieldTk := ulexer.NextToken(lex, ulexer.Identifier()) + fieldTk := lex.Expect(ulexer.Identifier()) tField, fieldExists := tObj.FieldByName(fieldTk.String()) vField := vObj.FieldByName(fieldTk.String()) - ulexer.NextToken(lex, ulexer.Contain(":")) - - lex.Read(ulexer.WhiteSpace()) + lex.Expect(ulexer.Contain(":")) parseMultiValue(lex, []ulexer.Matcher{ulexer.String(), ulexer.Numeral(), @@ -193,7 +190,6 @@ func parseArray(lex *ulexer.Lexer, tField reflect.Type, vObj reflect.Value, endL break } - lex.Read(ulexer.WhiteSpace()) lex.Expect(ulexer.Contain("{")) element := reflect.New(tField.Elem()).Elem() @@ -228,19 +224,3 @@ func safeTypeOf(obj interface{}) reflect.Type { return tObj } - -func UnmarshalText(s string, obj interface{}) error { - - vObj := safeValueOf(obj) - tObj := safeTypeOf(obj) - - lex := ulexer.NewLexer(s) - - err := lex.Run(func(lex *ulexer.Lexer) { - - parseStruct(lex, tObj, vObj, "") - - }) - - return err -} diff --git a/tests/code_test.go b/tests/code_test.go index 2164b2c..4c8c444 100644 --- a/tests/code_test.go +++ b/tests/code_test.go @@ -1,10 +1,7 @@ package tests import ( - "encoding/json" - "fmt" "github.com/davyxu/protoplus/proto" - "github.com/davyxu/protoplus/text" "github.com/davyxu/protoplus/wire" "github.com/stretchr/testify/assert" "math" @@ -86,7 +83,7 @@ func verifyText(t *testing.T, raw interface{}) { newType := reflect.New(tRaw.Elem()).Interface() - assert.Equal(t, text.UnmarshalText(data, newType), nil) + assert.Equal(t, proto.UnmarshalText(data, newType), nil) assert.Equal(t, raw, newType) } @@ -112,12 +109,6 @@ func TestText(t *testing.T) { input := makeMyType() - data, _ := json.Marshal(input) - fmt.Println(string(data)) - - //var input MyType - //input.Int32Slice = []int32{-1, 1, 2} - verifyText(t, &input) } From f14500b5f2eeebbb2ae1f985eda4304c208780fb Mon Sep 17 00:00:00 2001 From: davyxu Date: Wed, 15 Jul 2020 10:27:57 +0800 Subject: [PATCH 09/39] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proto/api.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/proto/api.go b/proto/api.go index b665cc9..a70e282 100644 --- a/proto/api.go +++ b/proto/api.go @@ -9,6 +9,10 @@ type Struct = wire.Struct func Marshal(msg Struct) ([]byte, error) { + if msg == nil { + return nil, nil + } + l := msg.Size() data := make([]byte, 0, l) @@ -26,6 +30,10 @@ func Marshal(msg Struct) ([]byte, error) { func Size(msg Struct) int { + if msg == nil { + return 0 + } + return msg.Size() } From 953521acb4114c55e7bb047424309f375e24fb70 Mon Sep 17 00:00:00 2001 From: davyxu Date: Tue, 4 Aug 2020 15:29:00 +0800 Subject: [PATCH 10/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +-- .../csharp/ProtoPlus/FastBitConverter.cs | 0 .../csharp/ProtoPlus/InputStream.cs | 0 .../csharp/ProtoPlus/MessageMeta.cs | 0 .../csharp/ProtoPlus/OutputStream.cs | 0 .../csharp/ProtoPlus/ProtoPlus.csproj | 0 .../csharp/ProtoPlus/ProtoStruct.cs | 0 .../csharp/ProtoPlus/SizeCaculator.cs | 0 {example => api}/csharp/ProtoPlus/WireType.cs | 0 example/csharp/Example.sln | 10 +++---- example/csharp/Example/Example.csproj | 2 +- example/csharp/Example/ProtoGen.cs | 6 ++--- example/csharp/Example/Test.cs | 27 +++++++++++++++++-- gen/csharp/func.go | 21 +++++++++++++-- gen/csharp/text.go | 9 +++---- parser/parse_descriptor.go | 25 +++++++---------- tests/Make.sh | 7 +---- tests/code_test.go | 26 ++++++++++++++++++ 18 files changed, 96 insertions(+), 41 deletions(-) rename {example => api}/csharp/ProtoPlus/FastBitConverter.cs (100%) rename {example => api}/csharp/ProtoPlus/InputStream.cs (100%) rename {example => api}/csharp/ProtoPlus/MessageMeta.cs (100%) rename {example => api}/csharp/ProtoPlus/OutputStream.cs (100%) rename {example => api}/csharp/ProtoPlus/ProtoPlus.csproj (100%) rename {example => api}/csharp/ProtoPlus/ProtoStruct.cs (100%) rename {example => api}/csharp/ProtoPlus/SizeCaculator.cs (100%) rename {example => api}/csharp/ProtoPlus/WireType.cs (100%) diff --git a/.gitignore b/.gitignore index ec4359b..2dbb55a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ example/csharp/.vs example/csharp/Example/bin example/csharp/Example/obj -example/csharp/ProtoPlus/obj -example/csharp/ProtoPlus/bin +api/csharp/ProtoPlus/obj +api/csharp/ProtoPlus/bin diff --git a/example/csharp/ProtoPlus/FastBitConverter.cs b/api/csharp/ProtoPlus/FastBitConverter.cs similarity index 100% rename from example/csharp/ProtoPlus/FastBitConverter.cs rename to api/csharp/ProtoPlus/FastBitConverter.cs diff --git a/example/csharp/ProtoPlus/InputStream.cs b/api/csharp/ProtoPlus/InputStream.cs similarity index 100% rename from example/csharp/ProtoPlus/InputStream.cs rename to api/csharp/ProtoPlus/InputStream.cs diff --git a/example/csharp/ProtoPlus/MessageMeta.cs b/api/csharp/ProtoPlus/MessageMeta.cs similarity index 100% rename from example/csharp/ProtoPlus/MessageMeta.cs rename to api/csharp/ProtoPlus/MessageMeta.cs diff --git a/example/csharp/ProtoPlus/OutputStream.cs b/api/csharp/ProtoPlus/OutputStream.cs similarity index 100% rename from example/csharp/ProtoPlus/OutputStream.cs rename to api/csharp/ProtoPlus/OutputStream.cs diff --git a/example/csharp/ProtoPlus/ProtoPlus.csproj b/api/csharp/ProtoPlus/ProtoPlus.csproj similarity index 100% rename from example/csharp/ProtoPlus/ProtoPlus.csproj rename to api/csharp/ProtoPlus/ProtoPlus.csproj diff --git a/example/csharp/ProtoPlus/ProtoStruct.cs b/api/csharp/ProtoPlus/ProtoStruct.cs similarity index 100% rename from example/csharp/ProtoPlus/ProtoStruct.cs rename to api/csharp/ProtoPlus/ProtoStruct.cs diff --git a/example/csharp/ProtoPlus/SizeCaculator.cs b/api/csharp/ProtoPlus/SizeCaculator.cs similarity index 100% rename from example/csharp/ProtoPlus/SizeCaculator.cs rename to api/csharp/ProtoPlus/SizeCaculator.cs diff --git a/example/csharp/ProtoPlus/WireType.cs b/api/csharp/ProtoPlus/WireType.cs similarity index 100% rename from example/csharp/ProtoPlus/WireType.cs rename to api/csharp/ProtoPlus/WireType.cs diff --git a/example/csharp/Example.sln b/example/csharp/Example.sln index fc95afb..53b8293 100644 --- a/example/csharp/Example.sln +++ b/example/csharp/Example.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.28010.2046 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example", "Example\Example.csproj", "{660CB175-1256-4A1C-B76C-08B45E9F0159}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProtoPlus", "ProtoPlus\ProtoPlus.csproj", "{59F81F0A-5130-4882-90A3-100358537F2E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProtoPlus", "..\..\api\csharp\ProtoPlus\ProtoPlus.csproj", "{1E171D88-E6CB-4493-98D1-5C7A36CA422B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,10 +17,10 @@ Global {660CB175-1256-4A1C-B76C-08B45E9F0159}.Debug|Any CPU.Build.0 = Debug|Any CPU {660CB175-1256-4A1C-B76C-08B45E9F0159}.Release|Any CPU.ActiveCfg = Release|Any CPU {660CB175-1256-4A1C-B76C-08B45E9F0159}.Release|Any CPU.Build.0 = Release|Any CPU - {59F81F0A-5130-4882-90A3-100358537F2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {59F81F0A-5130-4882-90A3-100358537F2E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {59F81F0A-5130-4882-90A3-100358537F2E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {59F81F0A-5130-4882-90A3-100358537F2E}.Release|Any CPU.Build.0 = Release|Any CPU + {1E171D88-E6CB-4493-98D1-5C7A36CA422B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E171D88-E6CB-4493-98D1-5C7A36CA422B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E171D88-E6CB-4493-98D1-5C7A36CA422B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E171D88-E6CB-4493-98D1-5C7A36CA422B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/example/csharp/Example/Example.csproj b/example/csharp/Example/Example.csproj index 86932a4..3fb65b0 100644 --- a/example/csharp/Example/Example.csproj +++ b/example/csharp/Example/Example.csproj @@ -16,7 +16,7 @@ - + diff --git a/example/csharp/Example/ProtoGen.cs b/example/csharp/Example/ProtoGen.cs index 18f473f..5ecbca3 100644 --- a/example/csharp/Example/ProtoGen.cs +++ b/example/csharp/Example/ProtoGen.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using ProtoPlus; -namespace proto +namespace Proto { public enum MyEnum @@ -496,14 +496,14 @@ public static void RegisterGeneratedMeta(MessageMeta meta) meta.RegisterMeta(new MetaInfo { Type = typeof(MySubType), - ID = 33606, + ID = 16166, SourcePeer = "client", TargetPeer = "game", }); meta.RegisterMeta(new MetaInfo { Type = typeof(MyType), - ID = 9980, + ID = 28380, SourcePeer = "", TargetPeer = "", }); diff --git a/example/csharp/Example/Test.cs b/example/csharp/Example/Test.cs index 99bded8..483e3b2 100644 --- a/example/csharp/Example/Test.cs +++ b/example/csharp/Example/Test.cs @@ -110,6 +110,28 @@ static MyType MakeMyType() }; } + static void TestSkipField() + { + byte[] data = new byte[256]; + var s = new OutputStream(data); + + var myType = MakeMyType(); + + s.Marshal(myType); + + var s2 = new InputStream(); + s2.Init(data, 0, s.Position); + + var myType2 = InputStream.CreateStruct(); + + s2.Unmarshal(myType2); + + Debug.Assert(myType2.Bool == myType2.Bool && myType2.Float32 == myType.Float32 && + myType2.Int32 == myType.Int32 && myType2.Int64 == myType.Int64 + && myType2.UInt64 == myType.UInt64 && myType2.UInt32 == myType.UInt32 + && myType2.Str == myType.Str); + } + static void TestFull() { byte[] data = new byte[256]; @@ -133,11 +155,11 @@ static void TestMessage() { var mm = new MessageMeta(); MessageMetaRegister.RegisterGeneratedMeta(mm); - var msg = mm.CreateMessageByID(33606); + var msg = mm.CreateMessageByID(28380); var meta = mm.GetMetaByType(msg.GetType()); - Debug.Assert(meta.ID == 33606); + Debug.Assert(meta.ID == 28380); Debug.Assert(meta.SourcePeer == "client"); } @@ -146,6 +168,7 @@ static void Main(string[] args) { TestFull(); TestMessage(); + TestSkipField(); } } diff --git a/gen/csharp/func.go b/gen/csharp/func.go index fa978ad..c992d26 100644 --- a/gen/csharp/func.go +++ b/gen/csharp/func.go @@ -42,11 +42,28 @@ func init() { return CSTypeNameFull(fd) } - UsefulFunc["IsPrimitiveSlice"] = func(raw interface{}) bool { + // 原生类型/结构体 | 数组 | 导出方式 + // 原生类型 无初始化 + // 原生类型 是 new Type[]() + // 结构体 MessageMeta.NewStruct() + // 结构体 是 new Type[]() + + UsefulFunc["NoneStructCanInit"] = func(raw interface{}) bool { + + fd := raw.(*model.FieldDescriptor) + + if fd.Kind == model.Kind_Primitive && fd.Type == "string" { + return false + } + + return !fd.TagExists("NoInit") && fd.Repeatd + } + + UsefulFunc["StructCanInit"] = func(raw interface{}) bool { fd := raw.(*model.FieldDescriptor) - return fd.Repeatd && fd.Kind != model.Kind_Struct + return !fd.TagExists("NoInit") && !fd.Repeatd && fd.Kind == model.Kind_Struct } UsefulFunc["IsStructSlice"] = func(raw interface{}) bool { diff --git a/gen/csharp/text.go b/gen/csharp/text.go index 4d38196..1b5aec5 100644 --- a/gen/csharp/text.go +++ b/gen/csharp/text.go @@ -23,15 +23,14 @@ namespace {{.PackageName}} {{end}} #region Serialize Code public void Init( ) - { {{range .Fields}}{{if IsPrimitiveSlice .}} - {{.Name}} = new {{CSTypeNameFull .}}(); {{end}}{{end}} - {{range .Fields}}{{if IsStruct .}} - {{.Name}} = ({{CSTypeNameFull .}}) InputStream.CreateStruct(typeof({{CSTypeNameFull .}})); {{end}} {{end}} + { {{range .Fields}}{{if NoneStructCanInit . }} + {{.Name}} = new {{CSTypeNameFull .}}(); {{end}}{{end}}{{range .Fields}}{{if StructCanInit .}} + {{.Name}} = ({{CSTypeNameFull .}}) MessageMeta.NewStruct(typeof({{CSTypeNameFull .}})); {{end}} {{end}} } public void Marshal(OutputStream stream) { {{range .Fields}} - stream.Write{{CodecName .}}({{PbTagNumber $obj .}}, {{.Name}} ); {{end}} + stream.Write{{CodecName .}}({{PbTagNumber $obj .}}, {{.Name}}); {{end}} } public int GetSize() diff --git a/parser/parse_descriptor.go b/parser/parse_descriptor.go index 5678631..b4c5242 100644 --- a/parser/parse_descriptor.go +++ b/parser/parse_descriptor.go @@ -23,30 +23,25 @@ func parseObject(ctx *Context) { for ctx.TokenID() != Token_CurlyBraceR { switch ctx.Descriptor.Kind { - case model.Kind_Struct, model.Kind_Enum: + case model.Kind_Struct: var fd model.FieldDescriptor ctx.FieldDescriptor = &fd - if ctx.TokenID() == Token_BracketL { - fd.TagSet = parseTagSet(ctx) - } - - case model.Kind_Service: - var sc model.ServiceCall - ctx.ServiceCall = &sc - if ctx.TokenID() == Token_BracketL { - sc.TagSet = parseTagSet(ctx) - } - } - - switch ctx.Descriptor.Kind { - case model.Kind_Struct: parseStructField(ctx) case model.Kind_Enum: + var fd model.FieldDescriptor + ctx.FieldDescriptor = &fd parseEnumField(ctx) case model.Kind_Service: + var sc model.ServiceCall + ctx.ServiceCall = &sc parseSvcCallField(ctx) } + // 读取字段后面的[Tag项] + if ctx.TokenID() == Token_BracketL { + ctx.FieldDescriptor.TagSet = parseTagSet(ctx) + } + } ctx.Expect(Token_CurlyBraceR) diff --git a/tests/Make.sh b/tests/Make.sh index 861bb26..accbf94 100644 --- a/tests/Make.sh +++ b/tests/Make.sh @@ -1,12 +1,7 @@ #!/usr/bin/env bash -CURRDIR=`pwd` -cd ../../../../.. -export GOPATH=`pwd` -cd ${CURRDIR} - go build -v -o=${GOPATH}/bin/protoplus github.com/davyxu/protoplus/cmd/protoplus # code.proto为输入文件 ${GOPATH}/bin/protoplus -go_out=code_gen.go -package=tests code.proto -${GOPATH}/bin/protoplus -cs_out=../example/csharp/Example/ProtoGen.cs -genreg -package=proto code.proto +${GOPATH}/bin/protoplus -cs_out=../example/csharp/Example/ProtoGen.cs -genreg -package=Proto code.proto ${GOPATH}/bin/protoplus -pb_out=pb_gen.proto -package=proto code.proto \ No newline at end of file diff --git a/tests/code_test.go b/tests/code_test.go index 4c8c444..1bfc5d0 100644 --- a/tests/code_test.go +++ b/tests/code_test.go @@ -1,6 +1,7 @@ package tests import ( + "encoding/json" "github.com/davyxu/protoplus/proto" "github.com/davyxu/protoplus/wire" "github.com/stretchr/testify/assert" @@ -105,6 +106,31 @@ func TestIntSlice(t *testing.T) { verifyWire(t, &input) } +func TestSkipField(t *testing.T) { + + input := makeMyType() + + data, err := proto.Marshal(&input) + assert.Equal(t, err, nil) + + jsondata, _ := json.Marshal(&input) + + var mini MyTypeMini + assert.Equal(t, proto.Unmarshal(data, &mini), nil) + + var miniJson MyTypeMini + json.Unmarshal(jsondata, &miniJson) + assert.Equal(t, miniJson, mini) +} + +func TestPtrField(t *testing.T) { + + input := MyType{} + data, err := proto.Marshal(&input) + t.Log(data, err) + +} + func TestText(t *testing.T) { input := makeMyType() From 7485c371cfff6c0d167798274c1104da8c1e5a15 Mon Sep 17 00:00:00 2001 From: xubo Date: Fri, 21 Aug 2020 15:21:07 +0800 Subject: [PATCH 11/39] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=AE=E7=82=B9?= =?UTF-8?q?=E6=95=B0=E5=BA=8F=E5=88=97=E5=8C=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/csharp/ProtoPlus/OutputStream.cs | 6 +- api/csharp/ProtoPlus/ProtoPlus.csproj | 6 +- api/csharp/ProtoPlus/SizeCaculator.cs | 4 +- example/csharp/Example/Example.csproj | 6 +- example/csharp/Example/ProtoGen.cs | 116 ++++++++++++-------------- tests/code.proto | 2 +- 6 files changed, 71 insertions(+), 69 deletions(-) diff --git a/api/csharp/ProtoPlus/OutputStream.cs b/api/csharp/ProtoPlus/OutputStream.cs index 0d2b2af..c47545d 100644 --- a/api/csharp/ProtoPlus/OutputStream.cs +++ b/api/csharp/ProtoPlus/OutputStream.cs @@ -272,8 +272,8 @@ public void WriteUInt64(int fieldIndex, List value) } public void WriteFloat(int fieldIndex, float value) - { - if (value < float.Epsilon) + { + if( value == 0F) { return; } @@ -307,7 +307,7 @@ public void WriteFloat(int fieldIndex, List value) public void WriteDouble(int fieldIndex, double value) { - if (value < double.Epsilon) + if (value == 0D) { return; } diff --git a/api/csharp/ProtoPlus/ProtoPlus.csproj b/api/csharp/ProtoPlus/ProtoPlus.csproj index 86ea3bb..79699fd 100644 --- a/api/csharp/ProtoPlus/ProtoPlus.csproj +++ b/api/csharp/ProtoPlus/ProtoPlus.csproj @@ -1,7 +1,11 @@ - netcoreapp2.1 + netcoreapp2.0 + + + + TRACE;DEBUG;NETCOREAPP2_0 diff --git a/api/csharp/ProtoPlus/SizeCaculator.cs b/api/csharp/ProtoPlus/SizeCaculator.cs index 0bf14de..17a00f7 100644 --- a/api/csharp/ProtoPlus/SizeCaculator.cs +++ b/api/csharp/ProtoPlus/SizeCaculator.cs @@ -75,7 +75,7 @@ public static int SizeEnum(int fieldIndex, List value) where T : struct, I public static int SizeFloat(int fieldIndex, float value) { - if (value < float.Epsilon) + if (value == 0F) { return 0; } @@ -100,7 +100,7 @@ public static int SizeFloat(int fieldIndex, List value) public static int SizeDouble(int fieldIndex, double value) { - if (value < double.Epsilon) + if (value == 0D) { return 0; } diff --git a/example/csharp/Example/Example.csproj b/example/csharp/Example/Example.csproj index 3fb65b0..c9a24bf 100644 --- a/example/csharp/Example/Example.csproj +++ b/example/csharp/Example/Example.csproj @@ -2,10 +2,14 @@ Exe - netcoreapp2.1 + netcoreapp2.0 Example.Program + + TRACE;DEBUG;NETCOREAPP2_0 + + diff --git a/example/csharp/Example/ProtoGen.cs b/example/csharp/Example/ProtoGen.cs index 5ecbca3..35bb8c4 100644 --- a/example/csharp/Example/ProtoGen.cs +++ b/example/csharp/Example/ProtoGen.cs @@ -29,20 +29,19 @@ public partial class MyTypeMini : IProtoStruct #region Serialize Code public void Init( ) - { - + { } public void Marshal(OutputStream stream) { - stream.WriteBool(1, Bool ); - stream.WriteInt32(2, Int32 ); - stream.WriteUInt32(3, UInt32 ); - stream.WriteInt64(4, Int64 ); - stream.WriteUInt64(5, UInt64 ); - stream.WriteFloat(6, Float32 ); - stream.WriteDouble(7, Float64 ); - stream.WriteString(8, Str ); + stream.WriteBool(1, Bool); + stream.WriteInt32(2, Int32); + stream.WriteUInt32(3, UInt32); + stream.WriteInt64(4, Int64); + stream.WriteUInt64(5, UInt64); + stream.WriteFloat(6, Float32); + stream.WriteDouble(7, Float64); + stream.WriteString(8, Str); } public int GetSize() @@ -129,32 +128,30 @@ public void Init( ) UInt64Slice = new List(); Float32Slice = new List(); Float64Slice = new List(); - StrSlice = new List(); - EnumSlice = new List(); - + EnumSlice = new List(); } public void Marshal(OutputStream stream) { - stream.WriteBool(1, Bool ); - stream.WriteInt32(2, Int32 ); - stream.WriteUInt32(3, UInt32 ); - stream.WriteInt64(4, Int64 ); - stream.WriteUInt64(5, UInt64 ); - stream.WriteFloat(6, Float32 ); - stream.WriteDouble(7, Float64 ); - stream.WriteString(8, Str ); - stream.WriteBytes(9, BytesSlice ); - stream.WriteBool(10, BoolSlice ); - stream.WriteInt32(11, Int32Slice ); - stream.WriteUInt32(12, UInt32Slice ); - stream.WriteInt64(13, Int64Slice ); - stream.WriteUInt64(14, UInt64Slice ); - stream.WriteFloat(15, Float32Slice ); - stream.WriteDouble(16, Float64Slice ); - stream.WriteString(17, StrSlice ); - stream.WriteEnum(18, Enum ); - stream.WriteEnum(19, EnumSlice ); + stream.WriteBool(1, Bool); + stream.WriteInt32(2, Int32); + stream.WriteUInt32(3, UInt32); + stream.WriteInt64(4, Int64); + stream.WriteUInt64(5, UInt64); + stream.WriteFloat(6, Float32); + stream.WriteDouble(7, Float64); + stream.WriteString(8, Str); + stream.WriteBytes(9, BytesSlice); + stream.WriteBool(10, BoolSlice); + stream.WriteInt32(11, Int32Slice); + stream.WriteUInt32(12, UInt32Slice); + stream.WriteInt64(13, Int64Slice); + stream.WriteUInt64(14, UInt64Slice); + stream.WriteFloat(15, Float32Slice); + stream.WriteDouble(16, Float64Slice); + stream.WriteString(17, StrSlice); + stream.WriteEnum(18, Enum); + stream.WriteEnum(19, EnumSlice); } public int GetSize() @@ -287,35 +284,34 @@ public void Init( ) UInt64Slice = new List(); Float32Slice = new List(); Float64Slice = new List(); - StrSlice = new List(); - EnumSlice = new List(); - - Struct = (MySubType) InputStream.CreateStruct(typeof(MySubType)); + StructSlice = new List(); + EnumSlice = new List(); + Struct = (MySubType) MessageMeta.NewStruct(typeof(MySubType)); } public void Marshal(OutputStream stream) { - stream.WriteBool(1, Bool ); - stream.WriteInt32(2, Int32 ); - stream.WriteUInt32(3, UInt32 ); - stream.WriteInt64(4, Int64 ); - stream.WriteUInt64(5, UInt64 ); - stream.WriteFloat(6, Float32 ); - stream.WriteDouble(7, Float64 ); - stream.WriteString(8, Str ); - stream.WriteStruct(9, Struct ); - stream.WriteBytes(10, BytesSlice ); - stream.WriteBool(11, BoolSlice ); - stream.WriteInt32(12, Int32Slice ); - stream.WriteUInt32(13, UInt32Slice ); - stream.WriteInt64(14, Int64Slice ); - stream.WriteUInt64(15, UInt64Slice ); - stream.WriteFloat(16, Float32Slice ); - stream.WriteDouble(17, Float64Slice ); - stream.WriteString(18, StrSlice ); - stream.WriteStruct(19, StructSlice ); - stream.WriteEnum(20, Enum ); - stream.WriteEnum(21, EnumSlice ); + stream.WriteBool(1, Bool); + stream.WriteInt32(2, Int32); + stream.WriteUInt32(3, UInt32); + stream.WriteInt64(4, Int64); + stream.WriteUInt64(5, UInt64); + stream.WriteFloat(6, Float32); + stream.WriteDouble(7, Float64); + stream.WriteString(8, Str); + stream.WriteStruct(9, Struct); + stream.WriteBytes(10, BytesSlice); + stream.WriteBool(11, BoolSlice); + stream.WriteInt32(12, Int32Slice); + stream.WriteUInt32(13, UInt32Slice); + stream.WriteInt64(14, Int64Slice); + stream.WriteUInt64(15, UInt64Slice); + stream.WriteFloat(16, Float32Slice); + stream.WriteDouble(17, Float64Slice); + stream.WriteString(18, StrSlice); + stream.WriteStruct(19, StructSlice); + stream.WriteEnum(20, Enum); + stream.WriteEnum(21, EnumSlice); } public int GetSize() @@ -428,7 +424,6 @@ public partial class LoginREQ : IProtoStruct #region Serialize Code public void Init( ) { - } public void Marshal(OutputStream stream) @@ -461,7 +456,6 @@ public partial class LoginACK : IProtoStruct #region Serialize Code public void Init( ) { - } public void Marshal(OutputStream stream) @@ -504,8 +498,8 @@ public static void RegisterGeneratedMeta(MessageMeta meta) { Type = typeof(MyType), ID = 28380, - SourcePeer = "", - TargetPeer = "", + SourcePeer = "client", + TargetPeer = "game", }); } } diff --git a/tests/code.proto b/tests/code.proto index 0ec611f..517d9fe 100644 --- a/tests/code.proto +++ b/tests/code.proto @@ -56,7 +56,7 @@ struct MySubType EnumSlice []MyEnum } -[AutoMsgID ] +[AutoMsgID MsgDir: "client -> game"] struct MyType { Bool bool From 820a6af1262e80ba04c42f8f6a286e67047fca95 Mon Sep 17 00:00:00 2001 From: davyxu Date: Wed, 28 Oct 2020 16:15:41 +0800 Subject: [PATCH 12/39] =?UTF-8?q?=E9=81=BF=E5=85=8DMsgID=3D0=E7=9A=84?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=B3=A8=E5=86=8C=E4=B8=8D=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen/csharp/text.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gen/csharp/text.go b/gen/csharp/text.go index 1b5aec5..79051ab 100644 --- a/gen/csharp/text.go +++ b/gen/csharp/text.go @@ -61,14 +61,14 @@ namespace {{.PackageName}} public static class MessageMetaRegister { public static void RegisterGeneratedMeta(MessageMeta meta) - { {{range .Structs}}{{ if IsMessage .}} + { {{range .Structs}} meta.RegisterMeta(new MetaInfo { Type = typeof({{.Name}}), ID = {{StructMsgID .}}, SourcePeer = "{{GetSourcePeer .}}", TargetPeer = "{{GetTargetPeer .}}", - });{{end}} {{end}} + });{{end}} } } {{end}} From 2ba6a6056fd80079895a4cdf24928f22e3977123 Mon Sep 17 00:00:00 2001 From: davyxu Date: Thu, 29 Oct 2020 15:18:05 +0800 Subject: [PATCH 13/39] =?UTF-8?q?=E4=BF=AE=E6=94=B9C#=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=81=8D=E5=8E=86=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen/csharp/text.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gen/csharp/text.go b/gen/csharp/text.go index 79051ab..99b3e8f 100644 --- a/gen/csharp/text.go +++ b/gen/csharp/text.go @@ -58,11 +58,11 @@ namespace {{.PackageName}} {{end}} {{if .RegEntry}} - public static class MessageMetaRegister + public static class MessageVisitor { - public static void RegisterGeneratedMeta(MessageMeta meta) + public static void Visit(Action callback) { {{range .Structs}} - meta.RegisterMeta(new MetaInfo + callback(new MetaInfo { Type = typeof({{.Name}}), ID = {{StructMsgID .}}, From 610dd1dfebd99bf59add5bb854ad8ee8b7385973 Mon Sep 17 00:00:00 2001 From: davyxu Date: Thu, 29 Oct 2020 17:33:57 +0800 Subject: [PATCH 14/39] =?UTF-8?q?=E5=B1=8F=E8=94=BDCS0162=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen/csharp/text.go | 1 + 1 file changed, 1 insertion(+) diff --git a/gen/csharp/text.go b/gen/csharp/text.go index 99b3e8f..8b775cc 100644 --- a/gen/csharp/text.go +++ b/gen/csharp/text.go @@ -6,6 +6,7 @@ const TemplateText = `// Generated by github.com/davyxu/protoplus using System; using System.Collections.Generic; using ProtoPlus; +#pragma warning disable 162 namespace {{.PackageName}} { From d3e6d57574c33dd87be185d897022a5c35b9072c Mon Sep 17 00:00:00 2001 From: davyxu Date: Fri, 30 Oct 2020 23:06:30 +0800 Subject: [PATCH 15/39] =?UTF-8?q?=E6=B6=88=E6=81=AFid=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=97=B6,=20=E4=BD=BF=E7=94=A8=E5=85=A8=E5=B0=8F=E5=86=99?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=90=8D,=20=E9=81=BF=E5=85=8D=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E5=B9=B3=E5=8F=B0=E7=94=9F=E6=88=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- msgidutil/msgid.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/msgidutil/msgid.go b/msgidutil/msgid.go index c08ce10..cd0e966 100644 --- a/msgidutil/msgid.go +++ b/msgidutil/msgid.go @@ -9,6 +9,7 @@ import ( "github.com/davyxu/protoplus/model" "io/ioutil" "os" + "strings" ) var skipDupCacheMsgIDTips bool // 跳过重复缓存消息ID的警告提示 @@ -174,7 +175,7 @@ func StructMsgID(d *model.Descriptor) (msgid int) { if *flagAutoMsgIDCacheFile != "" { msgid = autogenMsgIDByCacheFile(*flagAutoMsgIDCacheFile, d) } else if msgid == 0 { - msgid = int(StringHash(d.DescriptorSet.PackageName + d.Name + *flagMsgIDSalt)) + msgid = int(StringHash(strings.ToLower(d.DescriptorSet.PackageName + d.Name + *flagMsgIDSalt))) } if *flagCheckDuplicateMsgID { From e4c9a6d0044f765ce1f7ac93b10d14771908c73f Mon Sep 17 00:00:00 2001 From: davyxu Date: Mon, 9 Nov 2020 11:07:54 +0800 Subject: [PATCH 16/39] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/csharp/ProtoPlus/InputStream.cs | 49 +++++++++++++++------ api/csharp/ProtoPlus/MessageMeta.cs | 64 ++++++++++++++++++++++++++-- api/csharp/ProtoPlus/OutputStream.cs | 48 ++++++++++++++++++--- 3 files changed, 140 insertions(+), 21 deletions(-) diff --git a/api/csharp/ProtoPlus/InputStream.cs b/api/csharp/ProtoPlus/InputStream.cs index becbf0d..7631162 100644 --- a/api/csharp/ProtoPlus/InputStream.cs +++ b/api/csharp/ProtoPlus/InputStream.cs @@ -12,7 +12,7 @@ public class InputStream public int Position => _pos; - public int SpaceLeft => _len - _pos; + public int BufferLeft => _len - _pos; public static Func CreateStructFunc = new Func(CreateStruct); @@ -23,7 +23,7 @@ public static T CreateStruct() where T: IProtoStruct public static IProtoStruct CreateStruct(Type t) { - return MessageMeta.NewStruct(t ); + return MessageMeta.NewStruct(t); } @@ -136,7 +136,7 @@ public void ReadEnum(WireFormat.WireType wt, ref List value) where T : str value = new List(); } - while (stream.SpaceLeft > 0) + while (stream.BufferLeft > 0) { int element = 0; stream.ReadInt32(WireFormat.WireType.Varint, ref element); @@ -180,7 +180,7 @@ public void ReadInt32(WireFormat.WireType wt, ref List value) value = new List(); } - while(stream.SpaceLeft > 0 ) + while(stream.BufferLeft > 0 ) { int element = 0; stream.ReadInt32(WireFormat.WireType.Varint, ref element); @@ -220,7 +220,7 @@ public void ReadUInt32(WireFormat.WireType wt, ref List value) value = new List(); } - while (stream.SpaceLeft > 0) + while (stream.BufferLeft > 0) { uint element = 0; stream.ReadUInt32(WireFormat.WireType.Varint, ref element); @@ -264,7 +264,7 @@ public void ReadInt64(WireFormat.WireType wt, ref List value) value = new List(); } - while (stream.SpaceLeft > 0) + while (stream.BufferLeft > 0) { long element = 0; stream.ReadInt64(WireFormat.WireType.Varint, ref element); @@ -304,7 +304,7 @@ public void ReadUInt64(WireFormat.WireType wt, ref List value) value = new List(); } - while (stream.SpaceLeft > 0) + while (stream.BufferLeft > 0) { ulong element = 0; stream.ReadUInt64(WireFormat.WireType.Varint, ref element); @@ -345,7 +345,7 @@ public void ReadFloat(WireFormat.WireType wt, ref List value) value = new List(size/4); } - while (stream.SpaceLeft > 0) + while (stream.BufferLeft > 0) { float element = 0; stream.ReadFloat(WireFormat.WireType.Fixed32, ref element); @@ -386,7 +386,7 @@ public void ReadDouble(WireFormat.WireType wt, ref List value) value = new List(size / 8); } - while (stream.SpaceLeft > 0) + while (stream.BufferLeft > 0) { double element = 0; stream.ReadDouble(WireFormat.WireType.Fixed64, ref element); @@ -483,7 +483,7 @@ public void ReadStruct(WireFormat.WireType wt, ref T value) where T:IProtoStr public void Unmarshal(IProtoStruct s) { - while(SpaceLeft > 0 ) + while(BufferLeft > 0 ) { var tag = ReadVarint32(); @@ -578,7 +578,7 @@ uint SlowReadRawVarint32() return (uint)result; } - uint ReadFixed32() + public uint ReadFixed32() { CheckBuffer(4); @@ -589,8 +589,18 @@ uint ReadFixed32() return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24); } + + public ushort ReadFixed16() + { + CheckBuffer(2); + + uint b1 = _buffer[_pos++]; + uint b2 = _buffer[_pos++]; + + return (ushort)(b1 | (b2 << 8)); + } - ulong ReadFixed64() + public ulong ReadFixed64() { CheckBuffer(8); @@ -607,6 +617,20 @@ ulong ReadFixed64() | (b5 << 32) | (b6 << 40) | (b7 << 48) | (b8 << 56); } + public string ReadFixedString() + { + int len = (int)ReadFixed16(); + if (len > 0) + { + + var ret = Encoding.UTF8.GetString(_buffer, _pos, len); + _pos += len; + return ret; + } + + return string.Empty; + } + ulong ReadVarint64() { int shift = 0; @@ -624,6 +648,7 @@ ulong ReadVarint64() throw new Exception("MalformedVarint"); } + uint ReadVarint32() { diff --git a/api/csharp/ProtoPlus/MessageMeta.cs b/api/csharp/ProtoPlus/MessageMeta.cs index 311631e..74a769d 100644 --- a/api/csharp/ProtoPlus/MessageMeta.cs +++ b/api/csharp/ProtoPlus/MessageMeta.cs @@ -12,19 +12,42 @@ public class MetaInfo // 在proto中添加[MsgDir: "client -> game" ], 左边为源, 右边为目标 public string SourcePeer; // 消息发起的源 public string TargetPeer; // 消息的目标 + + public string Name; } // 消息扩展信息集合 public partial class MessageMeta { - private Dictionary metaByID = new Dictionary(); - private Dictionary metaByType = new Dictionary(); + readonly Dictionary metaByID = new Dictionary(); + readonly Dictionary metaByType = new Dictionary(); + readonly Dictionary metaByName = new Dictionary(); + + static MessageMeta _ins; + + public static MessageMeta Instance + { + get + { + if (_ins == null) + { + _ins = new MessageMeta(); + } + + return _ins; + } + } // 注册消息的扩展信息 public void RegisterMeta(MetaInfo info) { - metaByID.Add(info.ID, info); + if (info.ID != 0) + { + metaByID.Add(info.ID, info); + } + metaByType.Add(info.Type, info); + metaByName.Add(info.Name, info); } // 通过ID取信息 @@ -37,6 +60,16 @@ public MetaInfo GetMetaByID(ushort msgid) return null; } + + public MetaInfo GetMetaByName(string msgName) + { + if (metaByName.TryGetValue(msgName, out var value)) + { + return value; + } + + return null; + } // 通过类型取信息 public MetaInfo GetMetaByType(Type t) @@ -58,9 +91,18 @@ public ushort GetMsgIDByType(Type t) return meta.ID; } + + public string GetMsgNameByType(Type t) + { + var meta = GetMetaByType(t); + if (meta == null) + return string.Empty; + + return meta.Type.FullName; + } // 通过消息ID创建消息 - public IProtoStruct CreateMessageByID(ushort msgid) + public IProtoStruct NewStruct(ushort msgid) { var meta = GetMetaByID(msgid); if (meta == null) @@ -68,6 +110,15 @@ public IProtoStruct CreateMessageByID(ushort msgid) return NewStruct(meta.Type); } + + public IProtoStruct NewStruct(string msgName) + { + var meta = GetMetaByName(msgName); + if (meta == null) + return null; + + return NewStruct(meta.Type); + } // 通过类型创建消息 public static IProtoStruct NewStruct(Type t) @@ -83,6 +134,11 @@ public static IProtoStruct NewStruct(Type t) return s; } + public static T NewStruct( ) where T: IProtoStruct + { + return (T)NewStruct(typeof(T)); + } + } } diff --git a/api/csharp/ProtoPlus/OutputStream.cs b/api/csharp/ProtoPlus/OutputStream.cs index c47545d..2f219b7 100644 --- a/api/csharp/ProtoPlus/OutputStream.cs +++ b/api/csharp/ProtoPlus/OutputStream.cs @@ -13,8 +13,13 @@ public partial class OutputStream public int Position => _pos; - public int SpaceLeft => _len - _pos; + public int BufferLeft => _len - _pos; + public OutputStream() + { + + } + public OutputStream(byte[] buffer ) { Init(buffer, 0, buffer.Length, false); @@ -28,7 +33,10 @@ public void Init(byte[] buffer, int offset, int length, bool extend) _extend = extend; } - + public void SetPos(int pos) + { + _pos = pos; + } void CheckBuffer(int requireSize) { @@ -488,9 +496,14 @@ internal void WriteVarint64(ulong value) WriteByte((byte) value); } } + public void WriteFixed16(ushort value) + { + CheckBuffer(2); + _buffer[_pos++] = ((byte)value); + _buffer[_pos++] = ((byte)(value >> 8)); + } - - internal void WriteFixed32(uint value) + public void WriteFixed32(uint value) { CheckBuffer(4); _buffer[_pos++] = ((byte)value); @@ -499,7 +512,7 @@ internal void WriteFixed32(uint value) _buffer[_pos++] = ((byte)(value >> 24)); } - internal void WriteFixed64(ulong value) + public void WriteFixed64(ulong value) { CheckBuffer(8); _buffer[_pos++] = ((byte)value); @@ -511,6 +524,31 @@ internal void WriteFixed64(ulong value) _buffer[_pos++] = ((byte)(value >> 48)); _buffer[_pos++] = ((byte)(value >> 56)); } + + public void WriteFixedString(string value ) + { + int strLen = Encoding.UTF8.GetByteCount(value); + + WriteFixed16((ushort)strLen); + + CheckBuffer(strLen); + + // 全ASCII + if (strLen == value.Length) + { + for (int i = 0; i < strLen; i++) + { + _buffer[_pos + i] = (byte)value[i]; + } + } + else + { + Encoding.UTF8.GetBytes(value, 0, value.Length, _buffer, _pos); + + } + + _pos += strLen; + } internal void WriteRawBytes(byte[] value, int length ) { From 0198c16128e7dc8097f160b1ff0ec53116d64ad3 Mon Sep 17 00:00:00 2001 From: xubo Date: Thu, 31 Dec 2020 15:47:52 +0800 Subject: [PATCH 17/39] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E7=BC=96=E7=A0=81,=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=8B=AC=E7=AB=8Bgo=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/protoplus/main.go | 13 +++++++++++++ gen/gogopb/gen_proto.go | 2 ++ gen/golang/func.go | 2 +- gen/golang/gen_go.go | 16 ++++++++++++++++ gen/golang/text.go | 20 ++++++++++++++++++++ model/descriptorset.go | 1 + 6 files changed, 53 insertions(+), 1 deletion(-) diff --git a/cmd/protoplus/main.go b/cmd/protoplus/main.go index 485d83d..b663d97 100644 --- a/cmd/protoplus/main.go +++ b/cmd/protoplus/main.go @@ -23,9 +23,11 @@ var ( flagGoOut = flag.String("go_out", "", "output golang source file") flagCSOut = flag.String("cs_out", "", "output csharp source file") flagJsonOut = flag.String("json_out", "", "output json file") + flagGoRegOut = flag.String("goreg_out", "", "output golang message register source file") flagJson = flag.Bool("json", false, "output json to std out") flagGenReg = flag.Bool("genreg", false, "gen message register entry") flagStructBase = flag.String("structbase", "IProtoStruct", "struct inherite class type name in c#") + flagCodec = flag.String("codec", "protoplus", "default codec in register entry") ) const Version = "2.0.0" @@ -46,6 +48,7 @@ func main() { ctx.PackageName = *flagPackage ctx.StructBase = *flagStructBase ctx.RegEntry = *flagGenReg + ctx.Codec = *flagCodec err = util.ParseFileList(ctx.DescriptorSet) @@ -63,6 +66,16 @@ func main() { } } + if *flagGoRegOut != "" { + ctx.OutputFileName = *flagGoRegOut + + err = golang.GenGoReg(&ctx) + + if err != nil { + goto OnError + } + } + if *flagCSOut != "" { ctx.OutputFileName = *flagCSOut diff --git a/gen/gogopb/gen_proto.go b/gen/gogopb/gen_proto.go index 0266934..32a15b1 100644 --- a/gen/gogopb/gen_proto.go +++ b/gen/gogopb/gen_proto.go @@ -11,6 +11,8 @@ const protoCodeTemplate = `// Generated by github.com/davyxu/protoplus // DO NOT EDIT! syntax = "proto3"; +option go_package= ".;proto"; + package {{.PackageName}}; {{range $a, $enumobj := .Enums}} diff --git a/gen/golang/func.go b/gen/golang/func.go index eac6b0d..15cbfa1 100644 --- a/gen/golang/func.go +++ b/gen/golang/func.go @@ -18,7 +18,7 @@ func init() { UsefulFunc["StructCodec"] = func(d *model.Descriptor) string { codecName := d.TagValueString("Codec") if codecName == "" { - return "protoplus" + return d.DescriptorSet.Codec } return codecName diff --git a/gen/golang/gen_go.go b/gen/golang/gen_go.go index 3631318..0b760c1 100644 --- a/gen/golang/gen_go.go +++ b/gen/golang/gen_go.go @@ -22,3 +22,19 @@ func GenGo(ctx *gen.Context) error { return gen.WriteOutputFile(ctx.OutputFileName).Error() } + +func GenGoReg(ctx *gen.Context) error { + + gen := codegen.NewCodeGen("goreg"). + RegisterTemplateFunc(codegen.UsefulFunc). + RegisterTemplateFunc(UsefulFunc). + ParseTemplate(RegTemplateText, ctx). + FormatGoCode() + + if gen.Error() != nil { + fmt.Println(string(gen.Code())) + return gen.Error() + } + + return gen.WriteOutputFile(ctx.OutputFileName).Error() +} diff --git a/gen/golang/text.go b/gen/golang/text.go index 7b19b34..e99b223 100644 --- a/gen/golang/text.go +++ b/gen/golang/text.go @@ -137,3 +137,23 @@ func init() { } ` + +const RegTemplateText = `// Generated by github.com/davyxu/protoplus +package {{.PackageName}} + +import ( + "github.com/davyxu/cellnet" + "github.com/davyxu/cellnet/codec" + "reflect" +) + +func init() { + {{range .Structs}} + cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ + Codec: codec.MustGetCodec("{{StructCodec .}}"), + Type: reflect.TypeOf((*{{.Name}})(nil)).Elem(), + ID: {{StructMsgID .}}, + New: func() interface{} { return &{{.Name}}{} }, + }) {{end}} +} +` diff --git a/model/descriptorset.go b/model/descriptorset.go index bc9db8f..96dcf37 100644 --- a/model/descriptorset.go +++ b/model/descriptorset.go @@ -3,6 +3,7 @@ package model type DescriptorSet struct { Objects []*Descriptor `json:",omitempty"` PackageName string + Codec string } func (self *DescriptorSet) Services() (ret []*Descriptor) { From 24d0c0bb281b1404463f1275e13f28c8afc4e236 Mon Sep 17 00:00:00 2001 From: xubo Date: Fri, 12 Feb 2021 23:21:04 +0800 Subject: [PATCH 18/39] =?UTF-8?q?=E6=95=B4=E5=90=88=E9=80=82=E9=85=8DMsgDi?= =?UTF-8?q?r=E7=9A=84=E8=B7=AF=E7=94=B1=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/protoplus/main.go | 40 +++++++++++++---- gen/route/msgdir.go | 100 ++++++++++++++++++++++++++++++++++++++++++ gen/route/route.go | 62 ++++++++++++++++++++++++++ model/route.go | 14 ++++++ 4 files changed, 208 insertions(+), 8 deletions(-) create mode 100644 gen/route/msgdir.go create mode 100644 gen/route/route.go create mode 100644 model/route.go diff --git a/cmd/protoplus/main.go b/cmd/protoplus/main.go index b663d97..bf3a6db 100644 --- a/cmd/protoplus/main.go +++ b/cmd/protoplus/main.go @@ -10,6 +10,7 @@ import ( "github.com/davyxu/protoplus/gen/golang" "github.com/davyxu/protoplus/gen/json" _ "github.com/davyxu/protoplus/gen/json" + "github.com/davyxu/protoplus/gen/route" "github.com/davyxu/protoplus/model" "github.com/davyxu/protoplus/util" "os" @@ -17,14 +18,18 @@ import ( // 显示版本号 var ( - flagVersion = flag.Bool("version", false, "Show version") - flagPackage = flag.String("package", "", "package name in source files") - flagPbOut = flag.String("pb_out", "", "output google protobuf schema file") - flagGoOut = flag.String("go_out", "", "output golang source file") - flagCSOut = flag.String("cs_out", "", "output csharp source file") - flagJsonOut = flag.String("json_out", "", "output json file") - flagGoRegOut = flag.String("goreg_out", "", "output golang message register source file") - flagJson = flag.Bool("json", false, "output json to std out") + flagVersion = flag.Bool("version", false, "Show version") + flagPackage = flag.String("package", "", "package name in source files") + flagPbOut = flag.String("pb_out", "", "output google protobuf schema file") + flagGoOut = flag.String("go_out", "", "output golang source file") + flagCSOut = flag.String("cs_out", "", "output csharp source file") + flagJsonOut = flag.String("json_out", "", "output descriptor json file") + flagGoRegOut = flag.String("goreg_out", "", "output golang message register source file") + flagRouteOut = flag.String("route_out", "", "output route table json file") + + flagRoute = flag.Bool("route", false, "output route table json to std out") + + flagJson = flag.Bool("json", false, "output descriptor json to std out") flagGenReg = flag.Bool("genreg", false, "gen message register entry") flagStructBase = flag.String("structbase", "IProtoStruct", "struct inherite class type name in c#") flagCodec = flag.String("codec", "protoplus", "default codec in register entry") @@ -106,6 +111,16 @@ func main() { } } + if *flagRouteOut != "" { + ctx.OutputFileName = *flagRouteOut + + err = route.GenJson(&ctx) + + if err != nil { + goto OnError + } + } + if *flagJson { err = json.OutputJson(&ctx) @@ -115,6 +130,15 @@ func main() { } } + if *flagRoute { + + err = route.OutputJson(&ctx) + + if err != nil { + goto OnError + } + } + return OnError: diff --git a/gen/route/msgdir.go b/gen/route/msgdir.go new file mode 100644 index 0000000..3972a8d --- /dev/null +++ b/gen/route/msgdir.go @@ -0,0 +1,100 @@ +package route + +import ( + "fmt" + "github.com/davyxu/protoplus/model" + "strings" +) + +type MsgDir struct { + From, Mid, To string + Name string +} + +func (self *MsgDir) Valid() bool { + return self.From != "" && self.To != "" +} + +func (self *MsgDir) HasStar() bool { + if self.From == "*" { + return true + } + + if self.Mid == "*" { + return true + } + + if self.To == "*" { + return true + } + + return false +} + +func (self *MsgDir) Less(Other MsgDir) bool { + + if self.From != Other.From { + return self.From < Other.From + } + + if self.Mid != Other.Mid { + return self.Mid < Other.Mid + } + + if self.To != Other.To { + return self.To < Other.To + } + + return self.Name < Other.Name +} + +func parseMessage(d *model.Descriptor) (rm MsgDir) { + + msgdir := d.TagValueString("MsgDir") + if msgdir == "" { + return + } + + // 上行 + if strings.Contains(msgdir, "->") { + endPoints := strings.Split(msgdir, "->") + rm.Name = d.Name + + switch len(endPoints) { + case 3: + rm.From = strings.TrimSpace(endPoints[0]) + + rm.Mid = strings.TrimSpace(endPoints[1]) + + rm.To = strings.TrimSpace(endPoints[2]) + return + case 2: + rm.From = strings.TrimSpace(endPoints[0]) + + rm.To = strings.TrimSpace(endPoints[1]) + return + } + } else if strings.Contains(msgdir, "<-") { // 下行 + endPoints := strings.Split(msgdir, "<-") + rm.Name = d.Name + + switch len(endPoints) { + case 3: + rm.From = strings.TrimSpace(endPoints[2]) + + rm.Mid = strings.TrimSpace(endPoints[1]) + + rm.To = strings.TrimSpace(endPoints[0]) + return + case 2: + rm.From = strings.TrimSpace(endPoints[1]) + + rm.To = strings.TrimSpace(endPoints[0]) + return + } + } else { + fmt.Println("unknown msg dir", d.Name, msgdir) + } + + return +} diff --git a/gen/route/route.go b/gen/route/route.go new file mode 100644 index 0000000..6d25754 --- /dev/null +++ b/gen/route/route.go @@ -0,0 +1,62 @@ +package route + +import ( + "encoding/json" + "fmt" + "github.com/davyxu/protoplus/gen" + "github.com/davyxu/protoplus/model" + "github.com/davyxu/protoplus/msgidutil" + "io/ioutil" +) + +// 输出到文件 +func GenJson(ctx *gen.Context) error { + + data, err := genJsonData(ctx) + + if err != nil { + return err + } + + return ioutil.WriteFile(ctx.OutputFileName, data, 0666) +} + +// 将json输出到标准输出 +func OutputJson(ctx *gen.Context) error { + + data, err := genJsonData(ctx) + + if err != nil { + return err + } + + fmt.Println(string(data)) + return nil +} + +func genJsonData(ctx *gen.Context) ([]byte, error) { + + var rt model.RouteTable + + for _, d := range ctx.Structs() { + + msgDir := parseMessage(d) + msgID := msgidutil.StructMsgID(d) + + if msgDir.Valid() { + rt.Rule = append(rt.Rule, &model.RouteRule{ + MsgName: ctx.PackageName + "." + d.Name, + SvcName: msgDir.To, + MsgID: msgID, + }) + } + } + + data, err := json.MarshalIndent(&rt, "", "\t") + + if err != nil { + return nil, err + } + + return data, nil +} diff --git a/model/route.go b/model/route.go new file mode 100644 index 0000000..ab1973c --- /dev/null +++ b/model/route.go @@ -0,0 +1,14 @@ +package model + +// 路由规则 +type RouteRule struct { + MsgName string + MsgID int + + SvcName string +} + +// 路由表,包含多条路由规则 +type RouteTable struct { + Rule []*RouteRule +} From 711940a2f331c5d155d8cc5f0fa80e59af2e5883 Mon Sep 17 00:00:00 2001 From: davyxu Date: Mon, 15 Feb 2021 16:54:09 +0800 Subject: [PATCH 19/39] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=B8=8E=E8=A7=84?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 197 ++++++++++++++++++------- cmd/protoplus/main.go | 177 ++++++++++------------- codegen/codegen.go | 2 - codegen/msgid.go | 37 +++++ example/csharp/Example/ProtoGen.cs | 22 +-- gen/gen.go | 2 +- gen/{gogopb => pbscheme}/func.go | 2 +- gen/{gogopb => pbscheme}/gen_proto.go | 2 +- gen/{csharp => ppcs}/func.go | 2 +- gen/{csharp => ppcs}/gen_cs.go | 3 +- gen/{csharp => ppcs}/text.go | 4 +- gen/{golang => ppgo}/func.go | 2 +- gen/{golang => ppgo}/gen_go.go | 23 ++- gen/{golang => ppgo}/text.go | 16 +-- gen/{json => ppscheme}/json.go | 6 +- gen/route/route.go | 4 +- go.mod | 4 + go.sum | 26 +++- msgidutil/flag.go | 13 -- msgidutil/msgid.go | 198 -------------------------- msgidutil/suggest.go | 43 ------ tests/Make.sh | 8 +- tests/code.proto | 8 +- tests/code_gen.go | 4 - tests/code_test.go | 5 +- tests/pb_gen.proto | 2 + tests/reg_gen.go | 42 ++++++ tests/route.json | 9 ++ 28 files changed, 373 insertions(+), 490 deletions(-) create mode 100644 codegen/msgid.go rename gen/{gogopb => pbscheme}/func.go (96%) rename gen/{gogopb => pbscheme}/gen_proto.go (98%) rename gen/{csharp => ppcs}/func.go (99%) rename gen/{csharp => ppcs}/gen_cs.go (88%) rename gen/{csharp => ppcs}/text.go (96%) rename gen/{golang => ppgo}/func.go (99%) rename gen/{golang => ppgo}/gen_go.go (53%) rename gen/{golang => ppgo}/text.go (92%) rename gen/{json => ppscheme}/json.go (85%) delete mode 100644 msgidutil/flag.go delete mode 100644 msgidutil/msgid.go delete mode 100644 msgidutil/suggest.go create mode 100644 tests/reg_gen.go create mode 100644 tests/route.json diff --git a/README.md b/README.md index 762bbf5..6998277 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,29 @@ # protoplus -通用的描述文件及代码生成器及工具集 +适用于游戏开发的协议格式、代码生成器及相关开发API +# Why ProtoPlus? +Protobuf作为行业通用的协议格式已经存在多年,各种历史遗留问题及语言设计上的缺陷对游戏开发阻碍非常大。 -# 特性 +为了提高协议编写效率,增加协议使用灵活度,急需一套强于Protobuf的工具集提高开发效率和使用便捷性,ProtoPlus应运而生! -* 提供比Protobuf描述文件更加友好的格式 +# 特性对比 -* 支持插件架构,可以使用任何语言开发自己的协议runtime和代码生成器 +___ | ProtoPlus | Protobuf +---|---|--- +生成字段Tag | 自动/手动 | 手动 +生成枚举值 | 自动/手动 | 手动 +注释扩展 | API简单 | API复杂 +字段扩展 | 专属API支持 | 手动解析注释 +结构扩展 | 专属API支持 | 手动解析注释 +消息ID生成 | 自动/手动 | 不支持 +路由表生成 | 支持 | 不支持 +扩展方式 | 描述文件输出JSON | 复杂的插件格式,调试复杂 -* 插件信息交换使用JSON格式(Protobuf使用pb二进制格式) +注: +* ProtoPlus中的枚举值,不再需要为了兼容C++而必须加上前缀,保证全局枚举值唯一 + +* ProtoPlus二进制编码格式与Protobuf一致,方便调试、分析、优化 # 描述文件格式 @@ -50,100 +64,173 @@ struct AddressBook { ``` -## 特性 -* 自动生成tag序列号(base0),也可以手动指定 -* 自动生成枚举序号(base0),也可以手动指定 +# 协议类型及输出语言类型对应 -* 类go结构体字段命名方式 +描述 |ProtoPlus | Go | C# | Protobuf +---|---|---|---|--- +32位整形| int32 | int32 | int | int32 +64位整形 | int64|int64 | long | int64 +无符号32位整形| uint32|uint32 | uint | uint32 +无符号64位整形| uint64|uint64 | ulong|uint64 +字符串| string|string|string | string +单精度浮点数| float32|float32 | float | float +双精度浮点数|float64|float64| double | double +二进制数据 | bytes | []byte | byte[] |repeated byte +枚举| enum | int32类型常量封装| enum | enum +布尔| bool | bool| bool | bool +结构体| struct | struct| class | message -* 比Protobuf更方便的导出注释内容做协议扩充 -# 支持类型 +# 编译 -* int32: 32位整形 -* int64: 64位整形 -* uint32: 无符号32位整形 -* uint64: 无符号64位整形 -* string: 字符串 -* float32: 单精度浮点数 -* float64: 双精度浮点数 -* bytes: 二进制数据 -* enum: int32封装 -* bool: 布尔 -* struct 结构体 +``` + go get -u -v github.com/davyxu/protoplus/cmd/protoplus +``` -所有类型前添加[]表示数组 +# 功能 -# 编译 +## 输出ProtoPlus编码的Go源码 -``` - go get -u -v github.com/davyxu/protoplus +命令行示例: +```bash +protoplus --ppgo_out=msg_gen.go --package=proto proto1.proto proto2.proto ``` +参数说明: +* ppgo_out -# 命令行参数 + Go源码文件名 + +* package -- go_out + 指定输出时的Go包名 - 生成protoplus协议的go源码文件 +* codec + + 生成消息注册的默认编码,如在消息中指定编码时,优先使用指定的编码 + +## 输出ProtoPlus编码的C#源码 -- pb_out +输出的C#源码, 需要配合[ProtoPlus C# SDK](https://github.com/davyxu/protoplus/tree/master/api/csharp/ProtoPlus) 使用 - 生成protobuf 3.0协议文件 +命令行示例: +```bash +protoplus --ppcs_out=MsgGen.cs --package=Proto proto1.proto proto2.proto +``` -- cs_out +参数说明: +* ppcs_out - 生成protoplus协议的C#源码文件 + C#源码文件名 + +* package -- json_out + 指定输出时的C#命名空间 + +* classbase - 生成protoplus协议的json格式描述内容到文件 + C#代码生成时,消息类默认基类名称, 默认基类为IProtoStruct -- json +## 输出Protobuf协议描述文件 - 生成protoplus协议的json格式描述内容到标准输出 +输出的Protobuf协议描述文件,可使用protoc编译器编译 -- package +命令行示例: +```bash +protoplus --pbscheme_out=pb.proto --package=proto proto1.proto proto2.proto +``` - 指定生成源码的包,C#对应命名空间 +参数说明: +* pbscheme_out -- structbase + 生成protobuf 3.0协议文件 + +* package - C#代码生成时,消息类默认基类名称 + 指定输出时的Protobuf包名 -# 使用方法 -* 生成go源码 +## 输出ProtoPlus描述文件 -``` - protoplus -package=YourPackageName -go_out=YourMsg_gen.go a.proto b.proto +ProtoPlus协议描述文件可输出为JSON格式, 方便插件及工具链获取ProtoPlus的格式信息 + +命令行示例: +```bash +protoplus --ppscheme_out=pp.json proto1.proto proto2.proto ``` -* 生成类型信息 +参数说明: +* ppscheme_out -默认生成的go,C#源码文件不带消息ID绑定,可以使用以下命令行输出类型后,再结合自己的生成器生成绑定代码 + JSON格式的ProtoPlus协议描述文件, 格式参见 [协议描述定义](https://github.com/davyxu/protoplus/tree/master/model/descriptorset.go) +也可将描述文件的JSON直接输出,示例如下: + +```bash +protoplus --ppscheme proto1.proto proto2.proto ``` - protoplus -json_out=YourMsg_gen.go a.proto b.proto +## 输出路由配置 + +在结构体上添加MsgDir字段,标记结构体作为消息时的消息流转方向, 格式范例: +```protoplus +[MsgDir: "client -> game"] +struct LoginREQ { +} ``` +路由信息将输出为JSON格式: +```json +{ + "Rule": [ + { + "MsgName": "proto.LoginREQ", + "SvcName": "game" + } + ] +} +``` +### MsgDir格式说明 + +MsgDir的格式包含3个部分 +``` + MsgDir: From -> Mid -> To +``` + +* From + 消息的发起方,路由一般忽略此部分信息 + +* Mid -# 注意协议区别 + 消息的中间处理, 一般为网关或者路由等 + +* To -1. 文档中标注的"protoplus协议"和"Protobuf协议"为两种不同的协议 + 消息的目标送达点,消息处理最终方, 一般为某种消息服务, 路由表的SvcName字段读取该字段 -2. protoplus协议在很大程度上接近Protobuf协议,但并不是100%兼容, 也没有考虑兼容pb协议 +命令行示例: +```bash +protoplus --route_out=route.json --package=proto proto1.proto proto2.proto +``` + +参数说明: +* route_out + + JSON格式的ProtoPlus路由配置, 格式参见 [路由定义](https://github.com/davyxu/protoplus/tree/master/model/route.go) -3. go_out,cs_out等语言直接输出支持的是protoplus协议, -如需要pb协议的C#或go语言, 请使用pb_out参数输出proto文件后, 用pb的工具链生成对应语言的源码 +* package + 指定输出时消息的包名 + +也可将路由信息的JSON直接输出,示例如下: + +```bash +protoplus --route --package=proto proto1.proto proto2.proto +``` # 备注 感觉不错请star, 谢谢! -知乎: [http://www.zhihu.com/people/sunicdavy](http://www.zhihu.com/people/sunicdavy) - 提交bug及特性: https://github.com/davyxu/protoplus/issues diff --git a/cmd/protoplus/main.go b/cmd/protoplus/main.go index bf3a6db..fd3d88f 100644 --- a/cmd/protoplus/main.go +++ b/cmd/protoplus/main.go @@ -5,143 +5,116 @@ import ( "fmt" _ "github.com/davyxu/protoplus/codegen" "github.com/davyxu/protoplus/gen" - "github.com/davyxu/protoplus/gen/csharp" - "github.com/davyxu/protoplus/gen/gogopb" - "github.com/davyxu/protoplus/gen/golang" - "github.com/davyxu/protoplus/gen/json" - _ "github.com/davyxu/protoplus/gen/json" + "github.com/davyxu/protoplus/gen/pbscheme" + "github.com/davyxu/protoplus/gen/ppcs" + "github.com/davyxu/protoplus/gen/ppgo" + "github.com/davyxu/protoplus/gen/ppscheme" + _ "github.com/davyxu/protoplus/gen/ppscheme" "github.com/davyxu/protoplus/gen/route" "github.com/davyxu/protoplus/model" "github.com/davyxu/protoplus/util" "os" ) -// 显示版本号 var ( - flagVersion = flag.Bool("version", false, "Show version") - flagPackage = flag.String("package", "", "package name in source files") - flagPbOut = flag.String("pb_out", "", "output google protobuf schema file") - flagGoOut = flag.String("go_out", "", "output golang source file") - flagCSOut = flag.String("cs_out", "", "output csharp source file") - flagJsonOut = flag.String("json_out", "", "output descriptor json file") - flagGoRegOut = flag.String("goreg_out", "", "output golang message register source file") - flagRouteOut = flag.String("route_out", "", "output route table json file") - - flagRoute = flag.Bool("route", false, "output route table json to std out") - - flagJson = flag.Bool("json", false, "output descriptor json to std out") - flagGenReg = flag.Bool("genreg", false, "gen message register entry") - flagStructBase = flag.String("structbase", "IProtoStruct", "struct inherite class type name in c#") - flagCodec = flag.String("codec", "protoplus", "default codec in register entry") + flagVersion = flag.Bool("version", false, "show version") + + flagPackage = flag.String("package", "", "package name in source files") + flagClassBase = flag.String("classbase", "IProtoStruct", "struct inherite class type name in c#") + flagCodec = flag.String("codec", "protoplus", "default codec in register entry") ) const Version = "2.0.0" -func main() { - - flag.Parse() +type GenEntry struct { + name string + usage string + flagOutFile *string + flagExecute *bool - // 版本 - if *flagVersion { - fmt.Println(Version) - return - } - - var err error - var ctx gen.Context - ctx.DescriptorSet = new(model.DescriptorSet) - ctx.PackageName = *flagPackage - ctx.StructBase = *flagStructBase - ctx.RegEntry = *flagGenReg - ctx.Codec = *flagCodec - - err = util.ParseFileList(ctx.DescriptorSet) + outfile func(ctx *gen.Context) error + execute func(ctx *gen.Context) error +} - if err != nil { - goto OnError +var ( + genEntryList = []*GenEntry{ + {name: "ppgo_out", usage: "output protoplus message serialize golang source file", outfile: ppgo.GenGo}, + {name: "ppgoreg_out", usage: "output protoplus message register entry", outfile: ppgo.GenGoReg}, + {name: "ppcs_out", usage: "output protoplus message serialize csharp source file", outfile: ppcs.GenCSharp}, + {name: "pbscheme_out", usage: "output google protobuf schema file", outfile: pbscheme.GenProto}, + {name: "ppscheme_out", usage: "output protoplus scheme json file", outfile: ppscheme.GenJson}, + {name: "route_out", usage: "output route table json file", outfile: route.GenJson}, + + {name: "ppscheme", usage: "output protoplus scheme json to std out", execute: ppscheme.OutputJson}, + {name: "route", usage: "output route table json to std out", execute: route.OutputJson}, } +) - if *flagGoOut != "" { - ctx.OutputFileName = *flagGoOut - - err = golang.GenGo(&ctx) - - if err != nil { - goto OnError +func defineEntryFlag() { + for _, entry := range genEntryList { + if entry.outfile != nil { + entry.flagOutFile = flag.String(entry.name, "", entry.usage) } - } - - if *flagGoRegOut != "" { - ctx.OutputFileName = *flagGoRegOut - - err = golang.GenGoReg(&ctx) - - if err != nil { - goto OnError + if entry.execute != nil { + entry.flagExecute = flag.Bool(entry.name, false, entry.usage) } - } - - if *flagCSOut != "" { - ctx.OutputFileName = *flagCSOut - err = csharp.GenCSharp(&ctx) - - if err != nil { - goto OnError - } } +} - if *flagPbOut != "" { - ctx.OutputFileName = *flagPbOut - - err = gogopb.GenProto(&ctx) +func runEntry(ctx *gen.Context) error { + for _, entry := range genEntryList { + if entry.flagOutFile != nil && *entry.flagOutFile != "" { + ctx.OutputFileName = *entry.flagOutFile - if err != nil { - goto OnError + fmt.Printf("[%s] %s\n", entry.name, ctx.OutputFileName) + err := entry.outfile(ctx) + if err != nil { + return err + } } - } - - if *flagJsonOut != "" { - ctx.OutputFileName = *flagJsonOut - - err = json.GenJson(&ctx) - if err != nil { - goto OnError + if entry.flagExecute != nil && *entry.flagExecute { + err := entry.execute(ctx) + if err != nil { + return err + } } } - if *flagRouteOut != "" { - ctx.OutputFileName = *flagRouteOut - - err = route.GenJson(&ctx) + return nil +} - if err != nil { - goto OnError - } - } +func main() { - if *flagJson { + defineEntryFlag() - err = json.OutputJson(&ctx) + flag.Parse() - if err != nil { - goto OnError - } + // 版本 + if *flagVersion { + fmt.Println(Version) + return } - if *flagRoute { + var err error + var ctx gen.Context + ctx.DescriptorSet = new(model.DescriptorSet) + ctx.PackageName = *flagPackage + ctx.ClassBase = *flagClassBase + ctx.Codec = *flagCodec - err = route.OutputJson(&ctx) + err = util.ParseFileList(ctx.DescriptorSet) - if err != nil { - goto OnError - } + if err != nil { + fmt.Println(err) + os.Exit(1) } - return + err = runEntry(&ctx) + if err != nil { + fmt.Println(err) + os.Exit(1) + } -OnError: - fmt.Println(err) - os.Exit(1) } diff --git a/codegen/codegen.go b/codegen/codegen.go index c065422..52c30d5 100644 --- a/codegen/codegen.go +++ b/codegen/codegen.go @@ -129,8 +129,6 @@ func (self *CodeGen) WriteOutputFile(outputFileName string) *CodeGen { return self } - fmt.Printf("%s\n", outputFileName) - return self } diff --git a/codegen/msgid.go b/codegen/msgid.go new file mode 100644 index 0000000..ab630bf --- /dev/null +++ b/codegen/msgid.go @@ -0,0 +1,37 @@ +package codegen + +import ( + "github.com/davyxu/protoplus/model" + "strings" +) + +// 字符串转为16位整形值 +func stringHash(s string) (hash uint16) { + + for _, c := range s { + ch := uint16(c) + hash = hash + ((hash) << 5) + ch + (ch << 7) + } + + return +} + +func StructMsgID(d *model.Descriptor) (msgid int) { + if !IsMessage(d) { + return 0 + } + + if d.Kind == model.Kind_Struct { + msgid = d.TagValueInt("MsgID") + } + + if msgid == 0 { + msgid = int(stringHash(strings.ToLower(d.DescriptorSet.PackageName + d.Name))) + } + + return +} + +func init() { + UsefulFunc["StructMsgID"] = StructMsgID +} diff --git a/example/csharp/Example/ProtoGen.cs b/example/csharp/Example/ProtoGen.cs index 35bb8c4..d74839d 100644 --- a/example/csharp/Example/ProtoGen.cs +++ b/example/csharp/Example/ProtoGen.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using ProtoPlus; +#pragma warning disable 162 namespace Proto { @@ -483,25 +484,4 @@ public bool Unmarshal(InputStream stream, int fieldNumber, WireFormat.WireType w - public static class MessageMetaRegister - { - public static void RegisterGeneratedMeta(MessageMeta meta) - { - meta.RegisterMeta(new MetaInfo - { - Type = typeof(MySubType), - ID = 16166, - SourcePeer = "client", - TargetPeer = "game", - }); - meta.RegisterMeta(new MetaInfo - { - Type = typeof(MyType), - ID = 28380, - SourcePeer = "client", - TargetPeer = "game", - }); - } - } - } diff --git a/gen/gen.go b/gen/gen.go index 0b93be0..f82b5e4 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -7,6 +7,6 @@ import ( type Context struct { *model.DescriptorSet OutputFileName string - StructBase string + ClassBase string RegEntry bool } diff --git a/gen/gogopb/func.go b/gen/pbscheme/func.go similarity index 96% rename from gen/gogopb/func.go rename to gen/pbscheme/func.go index 2cdd964..859c2f0 100644 --- a/gen/gogopb/func.go +++ b/gen/pbscheme/func.go @@ -1,4 +1,4 @@ -package gogopb +package pbscheme import ( "github.com/davyxu/protoplus/model" diff --git a/gen/gogopb/gen_proto.go b/gen/pbscheme/gen_proto.go similarity index 98% rename from gen/gogopb/gen_proto.go rename to gen/pbscheme/gen_proto.go index 32a15b1..ec61361 100644 --- a/gen/gogopb/gen_proto.go +++ b/gen/pbscheme/gen_proto.go @@ -1,4 +1,4 @@ -package gogopb +package pbscheme import ( "fmt" diff --git a/gen/csharp/func.go b/gen/ppcs/func.go similarity index 99% rename from gen/csharp/func.go rename to gen/ppcs/func.go index c992d26..c60a14f 100644 --- a/gen/csharp/func.go +++ b/gen/ppcs/func.go @@ -1,4 +1,4 @@ -package csharp +package ppcs import ( "fmt" diff --git a/gen/csharp/gen_cs.go b/gen/ppcs/gen_cs.go similarity index 88% rename from gen/csharp/gen_cs.go rename to gen/ppcs/gen_cs.go index cc0e69e..ed27899 100644 --- a/gen/csharp/gen_cs.go +++ b/gen/ppcs/gen_cs.go @@ -1,10 +1,9 @@ -package csharp +package ppcs import ( "fmt" "github.com/davyxu/protoplus/codegen" "github.com/davyxu/protoplus/gen" - _ "github.com/davyxu/protoplus/msgidutil" ) func GenCSharp(ctx *gen.Context) error { diff --git a/gen/csharp/text.go b/gen/ppcs/text.go similarity index 96% rename from gen/csharp/text.go rename to gen/ppcs/text.go index 8b775cc..e500875 100644 --- a/gen/csharp/text.go +++ b/gen/ppcs/text.go @@ -1,4 +1,4 @@ -package csharp +package ppcs // 报错行号+7 const TemplateText = `// Generated by github.com/davyxu/protoplus @@ -18,7 +18,7 @@ namespace {{.PackageName}} } {{end}} {{range $a, $obj := .Structs}} {{ObjectLeadingComment .}} - public partial class {{$obj.Name}} : {{$.StructBase}} + public partial class {{$obj.Name}} : {{$.ClassBase}} { {{range .Fields}}public {{CSTypeNameFull .}} {{.Name}}; {{end}} diff --git a/gen/golang/func.go b/gen/ppgo/func.go similarity index 99% rename from gen/golang/func.go rename to gen/ppgo/func.go index 15cbfa1..92b64c1 100644 --- a/gen/golang/func.go +++ b/gen/ppgo/func.go @@ -1,4 +1,4 @@ -package golang +package ppgo import ( "github.com/davyxu/protoplus/codegen" diff --git a/gen/golang/gen_go.go b/gen/ppgo/gen_go.go similarity index 53% rename from gen/golang/gen_go.go rename to gen/ppgo/gen_go.go index 0b760c1..6898480 100644 --- a/gen/golang/gen_go.go +++ b/gen/ppgo/gen_go.go @@ -1,40 +1,39 @@ -package golang +package ppgo import ( "fmt" "github.com/davyxu/protoplus/codegen" "github.com/davyxu/protoplus/gen" - _ "github.com/davyxu/protoplus/msgidutil" ) func GenGo(ctx *gen.Context) error { - gen := codegen.NewCodeGen("go"). + codeGen := codegen.NewCodeGen("go"). RegisterTemplateFunc(codegen.UsefulFunc). RegisterTemplateFunc(UsefulFunc). ParseTemplate(TemplateText, ctx). FormatGoCode() - if gen.Error() != nil { - fmt.Println(string(gen.Code())) - return gen.Error() + if codeGen.Error() != nil { + fmt.Println(string(codeGen.Code())) + return codeGen.Error() } - return gen.WriteOutputFile(ctx.OutputFileName).Error() + return codeGen.WriteOutputFile(ctx.OutputFileName).Error() } func GenGoReg(ctx *gen.Context) error { - gen := codegen.NewCodeGen("goreg"). + codeGen := codegen.NewCodeGen("goreg"). RegisterTemplateFunc(codegen.UsefulFunc). RegisterTemplateFunc(UsefulFunc). ParseTemplate(RegTemplateText, ctx). FormatGoCode() - if gen.Error() != nil { - fmt.Println(string(gen.Code())) - return gen.Error() + if codeGen.Error() != nil { + fmt.Println(codeGen.Code()) + return codeGen.Error() } - return gen.WriteOutputFile(ctx.OutputFileName).Error() + return codeGen.WriteOutputFile(ctx.OutputFileName).Error() } diff --git a/gen/golang/text.go b/gen/ppgo/text.go similarity index 92% rename from gen/golang/text.go rename to gen/ppgo/text.go index e99b223..4660e68 100644 --- a/gen/golang/text.go +++ b/gen/ppgo/text.go @@ -1,4 +1,4 @@ -package golang +package ppgo // 报错行号+7 const TemplateText = `// Generated by github.com/davyxu/protoplus @@ -122,20 +122,6 @@ func (self *{{.Name}}) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire return wire.ErrUnknownField } {{end}} - - -func init() { -{{if .RegEntry}} - {{range .Structs}} {{ if GenEntry . }} - cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ - Codec: codec.MustGetCodec("{{StructCodec .}}"), - Type: reflect.TypeOf((*{{.Name}})(nil)).Elem(), - ID: {{StructMsgID .}}, - New: func() interface{} { return &{{.Name}}{} }, - }) {{end}} {{end}} -{{end}} -} - ` const RegTemplateText = `// Generated by github.com/davyxu/protoplus diff --git a/gen/json/json.go b/gen/ppscheme/json.go similarity index 85% rename from gen/json/json.go rename to gen/ppscheme/json.go index 6a6eace..c7d745c 100644 --- a/gen/json/json.go +++ b/gen/ppscheme/json.go @@ -1,10 +1,10 @@ -package json +package ppscheme import ( "encoding/json" "fmt" + "github.com/davyxu/protoplus/codegen" "github.com/davyxu/protoplus/gen" - "github.com/davyxu/protoplus/msgidutil" "io/ioutil" "strconv" ) @@ -13,7 +13,7 @@ func genJsonData(ctx *gen.Context) (error, []byte) { for _, obj := range ctx.DescriptorSet.Objects { if obj.TagExists("AutoMsgID") { - obj.SetTagValue("AutoMsgID", strconv.Itoa(msgidutil.StructMsgID(obj))) + obj.SetTagValue("AutoMsgID", strconv.Itoa(codegen.StructMsgID(obj))) } } diff --git a/gen/route/route.go b/gen/route/route.go index 6d25754..2e15f4e 100644 --- a/gen/route/route.go +++ b/gen/route/route.go @@ -3,9 +3,9 @@ package route import ( "encoding/json" "fmt" + "github.com/davyxu/protoplus/codegen" "github.com/davyxu/protoplus/gen" "github.com/davyxu/protoplus/model" - "github.com/davyxu/protoplus/msgidutil" "io/ioutil" ) @@ -41,7 +41,7 @@ func genJsonData(ctx *gen.Context) ([]byte, error) { for _, d := range ctx.Structs() { msgDir := parseMessage(d) - msgID := msgidutil.StructMsgID(d) + msgID := codegen.StructMsgID(d) if msgDir.Valid() { rt.Rule = append(rt.Rule, &model.RouteRule{ diff --git a/go.mod b/go.mod index 9b95afd..d77d21d 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,13 @@ module github.com/davyxu/protoplus go 1.12 require ( + github.com/davyxu/x v0.0.0 + github.com/davyxu/cellnet v4.1.0+incompatible github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200 github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50 github.com/stretchr/testify v1.6.1 ) replace github.com/davyxu/ulexer => ../ulexer +replace github.com/davyxu/cellnet => ../cellnet +replace github.com/davyxu/x => ../x diff --git a/go.sum b/go.sum index 0af858b..32ab9a9 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,35 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davyxu/cellnet v4.1.0+incompatible h1:zDRqhkFRhBTD7ajra2888aoRLN1qlv8LV8+qHg/emO4= +github.com/davyxu/cellnet v4.1.0+incompatible/go.mod h1:YyjRD4BinuDQmXWX7iHjPtnVf3qp2EzVN2/7P/8GKXE= github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200 h1:qLWlQBFg5c7HUOK+UdoGouLzRaYBQr2WwoAqixU+eik= github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200/go.mod h1:K/1PVWqaQEwMs+N+VvaoS66o1BAAwso+jEgXKBIa8QY= -github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50 h1:LhNcRLxSnxoE6nfEEBdNib+r932OtQoea7ZUZNh27zs= -github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50/go.mod h1:0aiydOTmjo/kWslAOerN4nz9Mlia75fwDs9LXp+Ed1c= -github.com/go-test/deep v1.0.6 h1:UHSEyLZUwX9Qoi99vVwvewiMC8mM2bf7XEM2nqvzEn8= -github.com/go-test/deep v1.0.6/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8= +github.com/davyxu/goobjfmt v0.1.0/go.mod h1:KKrytCtCXny2sEg3ojQfJ4NThhBP8hKw/qM9vhDwgog= +github.com/davyxu/protoplus v0.1.0/go.mod h1:WzmNYPvYsyks3G81jCJ/vGY2ljs49qFMfCmXGwvxFLA= +github.com/davyxu/ulog v1.0.0 h1:CfKRT2yK1JStZH5Yeal3BtF3kj/OETt1gTchuAbekBU= +github.com/davyxu/ulog v1.0.0/go.mod h1:kg3w8bI/8AOFX/NyNVHBAUBcvX7dDHrTfxdnk1sef18= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= +github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/mediocregopher/radix.v2 v0.0.0-20181115013041-b67df6e626f9/go.mod h1:fLRUbhbSd5Px2yKUaGYYPltlyxi1guJz1vCmo1RQL50= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/msgidutil/flag.go b/msgidutil/flag.go deleted file mode 100644 index ff0edcf..0000000 --- a/msgidutil/flag.go +++ /dev/null @@ -1,13 +0,0 @@ -package msgidutil - -import "flag" - -var ( - flagAutoMsgIDCacheFile = flag.String("AutoMsgIDCacheFile", "", "Specifies auto msgid cache file") - flagShowOverWriteCacheFileWarning = flag.Bool("ShowOverWriteCacheFileWarning", false, "Show warning when over write auto msgid cahce file, default is false") - flagSuggestMsgIDStart = flag.Int("SuggestMsgIDStart", 0, "Suggest msgid start, default is 0") - flagCheckDuplicateMsgID = flag.Bool("CheckDuplicateMsgID", false, "Check duplicate msgid, default is false") - - // 消息号发生重复时,添加一个自定义的字符串可以错开 - flagMsgIDSalt = flag.String("MsgIDSalt", "", "extra string add to input msgname in order to prevent hash collide") -) diff --git a/msgidutil/msgid.go b/msgidutil/msgid.go deleted file mode 100644 index cd0e966..0000000 --- a/msgidutil/msgid.go +++ /dev/null @@ -1,198 +0,0 @@ -package msgidutil - -import ( - "bufio" - "encoding/json" - "errors" - "fmt" - "github.com/davyxu/protoplus/codegen" - "github.com/davyxu/protoplus/model" - "io/ioutil" - "os" - "strings" -) - -var skipDupCacheMsgIDTips bool // 跳过重复缓存消息ID的警告提示 - -var msgNameByMsgID = map[int]string{} - -type MsgInfo struct { - Name string - MsgID int -} - -type AutoMsgIDCacheFile struct { - Caches []MsgInfo -} - -func (self *AutoMsgIDCacheFile) Load(cacheFileName string) { - existsFileData, _ := ioutil.ReadFile(cacheFileName) - - json.Unmarshal(existsFileData, self) -} - -func (self *AutoMsgIDCacheFile) Save(cacheFileName string) { - data, _ := json.MarshalIndent(self, "", "\t") - - ioutil.WriteFile(cacheFileName, data, 0666) -} - -func (self *AutoMsgIDCacheFile) ExistsMsgID(name string) int { - for _, m := range self.Caches { - if m.Name == name { - return m.MsgID - } - } - - return 0 -} - -func (self *AutoMsgIDCacheFile) GetNameByID(msgid int) string { - - for _, m := range self.Caches { - if m.MsgID == msgid { - return m.Name - } - } - - return "" -} - -func (self *AutoMsgIDCacheFile) AddNewMsg(name string, msgid int) { - - self.Caches = append(self.Caches, MsgInfo{name, msgid}) -} - -func (self *AutoMsgIDCacheFile) ModifyByMsgID(msgid int, name string) { - - for index, m := range self.Caches { - if m.MsgID == msgid { - self.Caches[index].Name = name - return - } - } - -} - -// MsgId:100 Descriptor FileA -// Descriptor <- auto gen 101 -// MsgID:200 Descriptor FileB -// Descriptor <- auto gen 201 - -func genMsgID(d *model.Descriptor, cacheFileName string, cachedMsgIDs *AutoMsgIDCacheFile) int { - - var msgid = 0 - for _, obj := range d.DescriptorSet.Objects { - - userMsgID := obj.TagValueInt("MsgID") - - if userMsgID == 0 && !obj.TagExists("AutoMsgID") { - continue - } - - if userMsgID > 0 { - msgid = userMsgID - } else { - msgid++ - } - - if obj == d { - - if existsName := cachedMsgIDs.GetNameByID(msgid); existsName != "" { - - if !skipDupCacheMsgIDTips && *flagShowOverWriteCacheFileWarning { - - fmt.Println("Warning: auto generate msg id has exists in automsgidcache file, the file will be overwrited.") - bufio.NewReader(os.Stdin).ReadString('\n') - - skipDupCacheMsgIDTips = true - } - - // msgid已存在,msgid拿给该消息使用 - cachedMsgIDs.ModifyByMsgID(msgid, d.Name) - } else { - // msgid不存在,添加 - cachedMsgIDs.AddNewMsg(d.Name, msgid) - } - - cachedMsgIDs.Save(cacheFileName) - - return msgid - } - } - - // 不会运行到这里的 - return 0 -} - -func autogenMsgIDByCacheFile(cacheFileName string, d *model.Descriptor) (newMsgID int) { - - var cachedMsgIDs AutoMsgIDCacheFile - cachedMsgIDs.Load(cacheFileName) - - // 协议里用户指定的ID - userMsgID := d.TagValueInt("MsgID") - - // 文件中,这个消息已经记忆的ID - existsMsgID := cachedMsgIDs.ExistsMsgID(d.Name) - - switch { - case userMsgID == 0 && existsMsgID == 0: // 缓冲无记录,用户没有指定ID,生成新ID - newMsgID = genMsgID(d, cacheFileName, &cachedMsgIDs) - case userMsgID != 0 && existsMsgID == 0: // 缓冲无记录,用户指定ID,用用户指定的ID - return userMsgID - case userMsgID == 0 && existsMsgID != 0: // 缓冲有记录ID,用户没有指定ID,用缓冲ID - return existsMsgID - case userMsgID != 0 && existsMsgID != 0: // 缓冲有记录ID,用户指定ID, 优先使用用户ID - return userMsgID - } - - return -} - -// 字符串转为16位整形值 -func StringHash(s string) (hash uint16) { - - for _, c := range s { - - ch := uint16(c) - - hash = hash + ((hash) << 5) + ch + (ch << 7) - } - - return -} - -func StructMsgID(d *model.Descriptor) (msgid int) { - if !codegen.IsMessage(d) { - return 0 - } - - if d.Kind == model.Kind_Struct { - msgid = d.TagValueInt("MsgID") - } - - if *flagAutoMsgIDCacheFile != "" { - msgid = autogenMsgIDByCacheFile(*flagAutoMsgIDCacheFile, d) - } else if msgid == 0 { - msgid = int(StringHash(strings.ToLower(d.DescriptorSet.PackageName + d.Name + *flagMsgIDSalt))) - } - - if *flagCheckDuplicateMsgID { - - oldName, exists := msgNameByMsgID[msgid] - if exists && d.Name != oldName { - panic(errors.New(fmt.Sprintf("%s's msgid(%d) has used by %s", d.Name, msgid, oldName))) - } - - msgNameByMsgID[msgid] = d.Name - - } - - return -} - -func init() { - - codegen.UsefulFunc["StructMsgID"] = StructMsgID -} diff --git a/msgidutil/suggest.go b/msgidutil/suggest.go deleted file mode 100644 index 8b88d38..0000000 --- a/msgidutil/suggest.go +++ /dev/null @@ -1,43 +0,0 @@ -package msgidutil - -import ( - "fmt" - "github.com/davyxu/protoplus/model" -) - -const sugguestMsgIDInterval = 100 - -func GenSuggestMsgID(dset *model.DescriptorSet) { - - // 段: MsgID/100 - - sectionMap := make(map[int]bool) - - for _, d := range dset.Objects { - - if d.Kind != model.Kind_Struct { - continue - } - userMsgID := d.TagValueInt("MsgID") - - if userMsgID == 0 { - continue - } - - sectionMap[userMsgID/sugguestMsgIDInterval] = true - } - - var section = *flagSuggestMsgIDStart / sugguestMsgIDInterval - - for ; ; section++ { - - if _, ok := sectionMap[section]; ok { - continue - } - - fmt.Println("Suggest msgid:", section*sugguestMsgIDInterval+1) - - return - } - -} diff --git a/tests/Make.sh b/tests/Make.sh index accbf94..8bf43b0 100644 --- a/tests/Make.sh +++ b/tests/Make.sh @@ -2,6 +2,8 @@ go build -v -o=${GOPATH}/bin/protoplus github.com/davyxu/protoplus/cmd/protoplus # code.proto为输入文件 -${GOPATH}/bin/protoplus -go_out=code_gen.go -package=tests code.proto -${GOPATH}/bin/protoplus -cs_out=../example/csharp/Example/ProtoGen.cs -genreg -package=Proto code.proto -${GOPATH}/bin/protoplus -pb_out=pb_gen.proto -package=proto code.proto \ No newline at end of file +${GOPATH}/bin/protoplus -ppgo_out=code_gen.go -package=tests code.proto +${GOPATH}/bin/protoplus -ppgoreg_out=reg_gen.go -package=tests code.proto +${GOPATH}/bin/protoplus -ppcs_out=../example/csharp/Example/ProtoGen.cs -package=Proto code.proto +${GOPATH}/bin/protoplus -pbscheme_out=pb_gen.proto -package=proto code.proto +${GOPATH}/bin/protoplus -route_out=route.json -package=proto code.proto \ No newline at end of file diff --git a/tests/code.proto b/tests/code.proto index 517d9fe..419a1e1 100644 --- a/tests/code.proto +++ b/tests/code.proto @@ -19,7 +19,6 @@ enum MyEnum Two } -[AutoMsgID MsgDir: "client -> game"] struct MySubType { Bool bool @@ -56,7 +55,7 @@ struct MySubType EnumSlice []MyEnum } -[AutoMsgID MsgDir: "client -> game"] + struct MyType { Bool bool @@ -95,6 +94,7 @@ struct MyType EnumSlice []MyEnum } +[MsgDir: "client -> game"] struct LoginREQ { } @@ -104,6 +104,10 @@ struct LoginACK { } + + + + service login { LoginStd(LoginREQ) LoginACK diff --git a/tests/code_gen.go b/tests/code_gen.go index 4aa377f..5231d87 100644 --- a/tests/code_gen.go +++ b/tests/code_gen.go @@ -598,7 +598,3 @@ func (self *LoginACK) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire. return wire.ErrUnknownField } - -func init() { - -} diff --git a/tests/code_test.go b/tests/code_test.go index 1bfc5d0..11b9ca6 100644 --- a/tests/code_test.go +++ b/tests/code_test.go @@ -2,6 +2,7 @@ package tests import ( "encoding/json" + _ "github.com/davyxu/cellnet/codec/protoplus" "github.com/davyxu/protoplus/proto" "github.com/davyxu/protoplus/wire" "github.com/stretchr/testify/assert" @@ -17,8 +18,8 @@ func TestOptional(t *testing.T) { var output MyTypeMini assert.Equal(t, proto.Unmarshal(data, &output), nil) - t.Logf("%+v", output) - assert.Equal(t, bigData, output) + //t.Logf("%+v", output) + //assert.Equal(t, bigData, output) } diff --git a/tests/pb_gen.proto b/tests/pb_gen.proto index 33f2a8b..d512b8a 100644 --- a/tests/pb_gen.proto +++ b/tests/pb_gen.proto @@ -2,6 +2,8 @@ // DO NOT EDIT! syntax = "proto3"; +option go_package= ".;proto"; + package proto; diff --git a/tests/reg_gen.go b/tests/reg_gen.go new file mode 100644 index 0000000..adfe1d9 --- /dev/null +++ b/tests/reg_gen.go @@ -0,0 +1,42 @@ +// Generated by github.com/davyxu/protoplus +package tests + +import ( + "github.com/davyxu/cellnet" + "github.com/davyxu/cellnet/codec" + "reflect" +) + +func init() { + + cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ + Codec: codec.MustGetCodec("protoplus"), + Type: reflect.TypeOf((*MyTypeMini)(nil)).Elem(), + ID: 0, + New: func() interface{} { return &MyTypeMini{} }, + }) + cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ + Codec: codec.MustGetCodec("protoplus"), + Type: reflect.TypeOf((*MySubType)(nil)).Elem(), + ID: 0, + New: func() interface{} { return &MySubType{} }, + }) + cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ + Codec: codec.MustGetCodec("protoplus"), + Type: reflect.TypeOf((*MyType)(nil)).Elem(), + ID: 0, + New: func() interface{} { return &MyType{} }, + }) + cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ + Codec: codec.MustGetCodec("protoplus"), + Type: reflect.TypeOf((*LoginREQ)(nil)).Elem(), + ID: 0, + New: func() interface{} { return &LoginREQ{} }, + }) + cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ + Codec: codec.MustGetCodec("protoplus"), + Type: reflect.TypeOf((*LoginACK)(nil)).Elem(), + ID: 0, + New: func() interface{} { return &LoginACK{} }, + }) +} diff --git a/tests/route.json b/tests/route.json new file mode 100644 index 0000000..8b37a33 --- /dev/null +++ b/tests/route.json @@ -0,0 +1,9 @@ +{ + "Rule": [ + { + "MsgName": "proto.LoginREQ", + "MsgID": 0, + "SvcName": "game" + } + ] +} \ No newline at end of file From d480aebff8249a5e82ae4e87530e48361e090156 Mon Sep 17 00:00:00 2001 From: xubo Date: Thu, 18 Feb 2021 15:22:04 +0800 Subject: [PATCH 20/39] =?UTF-8?q?=E8=B0=83=E6=95=B4go=20api=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 46 +++++++++++++++-- {proto => api/golang}/api.go | 4 +- {proto => api/golang}/text_marshaler.go | 2 +- {proto => api/golang}/text_marshaler_test.go | 2 +- {proto => api/golang}/text_parser.go | 2 +- {proto => api/golang}/text_writer.go | 2 +- {wire => api/golang/wire}/buffer.go | 0 {wire => api/golang/wire}/err.go | 0 {wire => api/golang/wire}/field_marshal.go | 0 {wire => api/golang/wire}/field_size.go | 0 {wire => api/golang/wire}/field_unmarshal.go | 0 {wire => api/golang/wire}/slice_marshal.go | 0 {wire => api/golang/wire}/slice_size.go | 0 {wire => api/golang/wire}/slice_unmarshal.go | 0 {wire => api/golang/wire}/struct.go | 0 {wire => api/golang/wire}/variant.go | 0 {wire => api/golang/wire}/wiretype.go | 0 cmd/protoplus/main.go | 5 +- example/csharp/Example/ProtoGen.cs | 2 - example/csharp/Example/ProtoGenReg.cs | 52 ++++++++++++++++++++ example/csharp/Example/Test.cs | 13 ----- gen/gen.go | 1 - gen/ppcs/gen_cs.go | 17 ++++++- gen/ppcs/text.go | 14 +++++- gen/ppgo/func.go | 5 ++ gen/ppgo/text.go | 39 ++++++++------- tests/Make.sh | 1 + tests/code_gen.go | 34 +++++++------ tests/code_test.go | 31 ++++++------ tests/reg_gen.go | 6 +++ 30 files changed, 197 insertions(+), 81 deletions(-) rename {proto => api/golang}/api.go (95%) rename {proto => api/golang}/text_marshaler.go (99%) rename {proto => api/golang}/text_marshaler_test.go (99%) rename {proto => api/golang}/text_parser.go (99%) rename {proto => api/golang}/text_writer.go (99%) rename {wire => api/golang/wire}/buffer.go (100%) rename {wire => api/golang/wire}/err.go (100%) rename {wire => api/golang/wire}/field_marshal.go (100%) rename {wire => api/golang/wire}/field_size.go (100%) rename {wire => api/golang/wire}/field_unmarshal.go (100%) rename {wire => api/golang/wire}/slice_marshal.go (100%) rename {wire => api/golang/wire}/slice_size.go (100%) rename {wire => api/golang/wire}/slice_unmarshal.go (100%) rename {wire => api/golang/wire}/struct.go (100%) rename {wire => api/golang/wire}/variant.go (100%) rename {wire => api/golang/wire}/wiretype.go (100%) create mode 100644 example/csharp/Example/ProtoGenReg.cs diff --git a/README.md b/README.md index 6998277..ce22a8c 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ struct AddressBook { # 功能 -## 输出ProtoPlus编码的Go源码 +## 输出ProtoPlus编码消息序列化的Go源码 命令行示例: ```bash @@ -107,11 +107,29 @@ protoplus --ppgo_out=msg_gen.go --package=proto proto1.proto proto2.proto 指定输出时的Go包名 -* codec - +## 输出消息绑定的Go源码 + +输出源码被引用时, 自动注册到cellnet的消息Registry中 + +命令行示例: +```bash +protoplus --ppgoreg_out=msg_gen.go --package=proto proto1.proto proto2.proto +``` + +参数说明: +* ppgoreg_out + + Go源码文件名 + +* package + + 指定输出时的Go包名 + +* codec 生成消息注册的默认编码,如在消息中指定编码时,优先使用指定的编码 + -## 输出ProtoPlus编码的C#源码 +## 输出ProtoPlus编码的消息序列化C#源码 输出的C#源码, 需要配合[ProtoPlus C# SDK](https://github.com/davyxu/protoplus/tree/master/api/csharp/ProtoPlus) 使用 @@ -133,6 +151,26 @@ protoplus --ppcs_out=MsgGen.cs --package=Proto proto1.proto proto2.proto C#代码生成时,消息类默认基类名称, 默认基类为IProtoStruct + +## 输出消息绑定的C#源码 + +输出的C#源码, 需要配合[ProtoPlus C# SDK](https://github.com/davyxu/protoplus/tree/master/api/csharp/ProtoPlus) 使用 + +命令行示例: +```bash +protoplus --ppcsreg_out=MsgGen.cs --package=Proto proto1.proto proto2.proto +``` + +参数说明: +* ppcsreg_out + + C#源码文件名 + +* package + + 指定输出时的C#命名空间 + + ## 输出Protobuf协议描述文件 输出的Protobuf协议描述文件,可使用protoc编译器编译 diff --git a/proto/api.go b/api/golang/api.go similarity index 95% rename from proto/api.go rename to api/golang/api.go index a70e282..4808a16 100644 --- a/proto/api.go +++ b/api/golang/api.go @@ -1,7 +1,7 @@ -package proto +package ppgo import ( - "github.com/davyxu/protoplus/wire" + "github.com/davyxu/protoplus/api/golang/wire" "github.com/davyxu/ulexer" ) diff --git a/proto/text_marshaler.go b/api/golang/text_marshaler.go similarity index 99% rename from proto/text_marshaler.go rename to api/golang/text_marshaler.go index b8a46ec..f3e92dd 100644 --- a/proto/text_marshaler.go +++ b/api/golang/text_marshaler.go @@ -1,4 +1,4 @@ -package proto +package ppgo import ( "bufio" diff --git a/proto/text_marshaler_test.go b/api/golang/text_marshaler_test.go similarity index 99% rename from proto/text_marshaler_test.go rename to api/golang/text_marshaler_test.go index dd32a67..6d9be76 100644 --- a/proto/text_marshaler_test.go +++ b/api/golang/text_marshaler_test.go @@ -1,4 +1,4 @@ -package proto +package ppgo import ( "math" diff --git a/proto/text_parser.go b/api/golang/text_parser.go similarity index 99% rename from proto/text_parser.go rename to api/golang/text_parser.go index 0d16ed5..104b1d8 100644 --- a/proto/text_parser.go +++ b/api/golang/text_parser.go @@ -1,4 +1,4 @@ -package proto +package ppgo import ( "github.com/davyxu/ulexer" diff --git a/proto/text_writer.go b/api/golang/text_writer.go similarity index 99% rename from proto/text_writer.go rename to api/golang/text_writer.go index c8e859a..eeabffb 100644 --- a/proto/text_writer.go +++ b/api/golang/text_writer.go @@ -1,4 +1,4 @@ -package proto +package ppgo import ( "bytes" diff --git a/wire/buffer.go b/api/golang/wire/buffer.go similarity index 100% rename from wire/buffer.go rename to api/golang/wire/buffer.go diff --git a/wire/err.go b/api/golang/wire/err.go similarity index 100% rename from wire/err.go rename to api/golang/wire/err.go diff --git a/wire/field_marshal.go b/api/golang/wire/field_marshal.go similarity index 100% rename from wire/field_marshal.go rename to api/golang/wire/field_marshal.go diff --git a/wire/field_size.go b/api/golang/wire/field_size.go similarity index 100% rename from wire/field_size.go rename to api/golang/wire/field_size.go diff --git a/wire/field_unmarshal.go b/api/golang/wire/field_unmarshal.go similarity index 100% rename from wire/field_unmarshal.go rename to api/golang/wire/field_unmarshal.go diff --git a/wire/slice_marshal.go b/api/golang/wire/slice_marshal.go similarity index 100% rename from wire/slice_marshal.go rename to api/golang/wire/slice_marshal.go diff --git a/wire/slice_size.go b/api/golang/wire/slice_size.go similarity index 100% rename from wire/slice_size.go rename to api/golang/wire/slice_size.go diff --git a/wire/slice_unmarshal.go b/api/golang/wire/slice_unmarshal.go similarity index 100% rename from wire/slice_unmarshal.go rename to api/golang/wire/slice_unmarshal.go diff --git a/wire/struct.go b/api/golang/wire/struct.go similarity index 100% rename from wire/struct.go rename to api/golang/wire/struct.go diff --git a/wire/variant.go b/api/golang/wire/variant.go similarity index 100% rename from wire/variant.go rename to api/golang/wire/variant.go diff --git a/wire/wiretype.go b/api/golang/wire/wiretype.go similarity index 100% rename from wire/wiretype.go rename to api/golang/wire/wiretype.go diff --git a/cmd/protoplus/main.go b/cmd/protoplus/main.go index fd3d88f..c90e373 100644 --- a/cmd/protoplus/main.go +++ b/cmd/protoplus/main.go @@ -39,8 +39,9 @@ type GenEntry struct { var ( genEntryList = []*GenEntry{ {name: "ppgo_out", usage: "output protoplus message serialize golang source file", outfile: ppgo.GenGo}, - {name: "ppgoreg_out", usage: "output protoplus message register entry", outfile: ppgo.GenGoReg}, - {name: "ppcs_out", usage: "output protoplus message serialize csharp source file", outfile: ppcs.GenCSharp}, + {name: "ppgoreg_out", usage: "output protoplus message register entry in golang", outfile: ppgo.GenGoReg}, + {name: "ppcs_out", usage: "output protoplus message serialize csharp source file", outfile: ppcs.GenCS}, + {name: "ppcsreg_out", usage: "output protoplus message register entry in csharp", outfile: ppcs.GenCSReg}, {name: "pbscheme_out", usage: "output google protobuf schema file", outfile: pbscheme.GenProto}, {name: "ppscheme_out", usage: "output protoplus scheme json file", outfile: ppscheme.GenJson}, {name: "route_out", usage: "output route table json file", outfile: route.GenJson}, diff --git a/example/csharp/Example/ProtoGen.cs b/example/csharp/Example/ProtoGen.cs index d74839d..f73a018 100644 --- a/example/csharp/Example/ProtoGen.cs +++ b/example/csharp/Example/ProtoGen.cs @@ -482,6 +482,4 @@ public bool Unmarshal(InputStream stream, int fieldNumber, WireFormat.WireType w #endregion } - - } diff --git a/example/csharp/Example/ProtoGenReg.cs b/example/csharp/Example/ProtoGenReg.cs new file mode 100644 index 0000000..feafab9 --- /dev/null +++ b/example/csharp/Example/ProtoGenReg.cs @@ -0,0 +1,52 @@ +// Generated by github.com/davyxu/protoplus +// DO NOT EDIT! +using System; +using System.Collections.Generic; +using ProtoPlus; +#pragma warning disable 162 + +namespace Proto +{ + + public static class MessageVisitor + { + public static void Visit(Action callback) + { + callback(new MetaInfo + { + Type = typeof(MyTypeMini), + ID = 0, + SourcePeer = "", + TargetPeer = "", + }); + callback(new MetaInfo + { + Type = typeof(MySubType), + ID = 0, + SourcePeer = "", + TargetPeer = "", + }); + callback(new MetaInfo + { + Type = typeof(MyType), + ID = 0, + SourcePeer = "", + TargetPeer = "", + }); + callback(new MetaInfo + { + Type = typeof(LoginREQ), + ID = 0, + SourcePeer = "client", + TargetPeer = "game", + }); + callback(new MetaInfo + { + Type = typeof(LoginACK), + ID = 0, + SourcePeer = "", + TargetPeer = "", + }); + } + } +} diff --git a/example/csharp/Example/Test.cs b/example/csharp/Example/Test.cs index 483e3b2..210cc4e 100644 --- a/example/csharp/Example/Test.cs +++ b/example/csharp/Example/Test.cs @@ -151,23 +151,10 @@ static void TestFull() Debug.Assert(myType.Equals(myType2)); } - static void TestMessage() - { - var mm = new MessageMeta(); - MessageMetaRegister.RegisterGeneratedMeta(mm); - var msg = mm.CreateMessageByID(28380); - - var meta = mm.GetMetaByType(msg.GetType()); - - Debug.Assert(meta.ID == 28380); - - Debug.Assert(meta.SourcePeer == "client"); - } static void Main(string[] args) { TestFull(); - TestMessage(); TestSkipField(); } } diff --git a/gen/gen.go b/gen/gen.go index f82b5e4..029bae0 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -8,5 +8,4 @@ type Context struct { *model.DescriptorSet OutputFileName string ClassBase string - RegEntry bool } diff --git a/gen/ppcs/gen_cs.go b/gen/ppcs/gen_cs.go index ed27899..9df5804 100644 --- a/gen/ppcs/gen_cs.go +++ b/gen/ppcs/gen_cs.go @@ -6,7 +6,7 @@ import ( "github.com/davyxu/protoplus/gen" ) -func GenCSharp(ctx *gen.Context) error { +func GenCS(ctx *gen.Context) error { gen := codegen.NewCodeGen("cs"). RegisterTemplateFunc(codegen.UsefulFunc). @@ -20,3 +20,18 @@ func GenCSharp(ctx *gen.Context) error { return gen.WriteOutputFile(ctx.OutputFileName).Error() } + +func GenCSReg(ctx *gen.Context) error { + + gen := codegen.NewCodeGen("csreg"). + RegisterTemplateFunc(codegen.UsefulFunc). + RegisterTemplateFunc(UsefulFunc). + ParseTemplate(RegTemplateText, ctx) + + if gen.Error() != nil { + fmt.Println(string(gen.Code())) + return gen.Error() + } + + return gen.WriteOutputFile(ctx.OutputFileName).Error() +} diff --git a/gen/ppcs/text.go b/gen/ppcs/text.go index e500875..f7360e9 100644 --- a/gen/ppcs/text.go +++ b/gen/ppcs/text.go @@ -57,8 +57,19 @@ namespace {{.PackageName}} #endregion } {{end}} +} +` + +const RegTemplateText = `// Generated by github.com/davyxu/protoplus +// DO NOT EDIT! +using System; +using System.Collections.Generic; +using ProtoPlus; +#pragma warning disable 162 + +namespace {{.PackageName}} +{ -{{if .RegEntry}} public static class MessageVisitor { public static void Visit(Action callback) @@ -72,6 +83,5 @@ namespace {{.PackageName}} });{{end}} } } -{{end}} } ` diff --git a/gen/ppgo/func.go b/gen/ppgo/func.go index 92b64c1..ebd8ae0 100644 --- a/gen/ppgo/func.go +++ b/gen/ppgo/func.go @@ -31,6 +31,11 @@ func init() { ret += "[]" } + // 默认指针 + if fd.Kind == model.Kind_Struct { + ret += "*" + } + ret += codegen.GoTypeName(fd) return } diff --git a/gen/ppgo/text.go b/gen/ppgo/text.go index 4660e68..1502eb2 100644 --- a/gen/ppgo/text.go +++ b/gen/ppgo/text.go @@ -6,20 +6,14 @@ const TemplateText = `// Generated by github.com/davyxu/protoplus package {{.PackageName}} import ( - "github.com/davyxu/protoplus/proto" - "github.com/davyxu/protoplus/wire" - "unsafe" {{if .RegEntry}} - "reflect" - "github.com/davyxu/cellnet" - "github.com/davyxu/cellnet/codec" {{end}} + "github.com/davyxu/protoplus/api/golang" + "github.com/davyxu/protoplus/api/golang/wire" + "unsafe" ) var ( _ *wire.Buffer - _ = proto.Marshal - _ unsafe.Pointer {{if .RegEntry}} - _ cellnet.MessageMeta - _ codec.CodecRecycler - _ reflect.Kind {{end}} + _ = ppgo.Marshal + _ unsafe.Pointer ) {{range $a, $enumobj := .Enums}} @@ -49,18 +43,18 @@ type {{.Name}} struct{ {{range .Fields}} {{GoFieldName .}} {{ProtoTypeName .}} {{GoStructTag .}}{{FieldTrailingComment .}} {{end}} } -func (self *{{.Name}}) String() string { return proto.CompactTextString(self) } +func (self *{{.Name}}) String() string { return ppgo.CompactTextString(self) } func (self *{{.Name}}) Size() (ret int) { {{range .Fields}} {{if IsStructSlice .}} if len(self.{{GoFieldName .}}) > 0 { for _, elm := range self.{{GoFieldName .}} { - ret += wire.SizeStruct({{PbTagNumber $obj .}}, &elm) + ret += wire.SizeStruct({{PbTagNumber $obj .}}, elm) } } {{else if IsStruct .}} - ret += wire.Size{{CodecName .}}({{PbTagNumber $obj .}}, &self.{{GoFieldName .}}) + ret += wire.Size{{CodecName .}}({{PbTagNumber $obj .}}, self.{{GoFieldName .}}) {{else if IsEnum .}} ret += wire.Size{{CodecName .}}({{PbTagNumber $obj .}}, int32(self.{{GoFieldName .}})) {{else if IsEnumSlice .}} @@ -76,10 +70,10 @@ func (self *{{.Name}}) Marshal(buffer *wire.Buffer) error { {{range .Fields}} {{if IsStructSlice .}} for _, elm := range self.{{GoFieldName .}} { - wire.MarshalStruct(buffer, {{PbTagNumber $obj .}}, &elm) + wire.MarshalStruct(buffer, {{PbTagNumber $obj .}}, elm) } {{else if IsStruct .}} - wire.Marshal{{CodecName .}}(buffer, {{PbTagNumber $obj .}}, &self.{{GoFieldName .}}) + wire.Marshal{{CodecName .}}(buffer, {{PbTagNumber $obj .}}, self.{{GoFieldName .}}) {{else if IsEnum .}} wire.Marshal{{CodecName .}}(buffer, {{PbTagNumber $obj .}}, int32(self.{{GoFieldName .}})) {{else if IsEnumSlice .}} @@ -98,13 +92,15 @@ func (self *{{.Name}}) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire if err := wire.UnmarshalStruct(buffer, wt, &elm); err != nil { return err } else { - self.{{GoFieldName .}} = append(self.{{GoFieldName .}}, elm) + self.{{GoFieldName .}} = append(self.{{GoFieldName .}}, &elm) return nil }{{else if IsEnum .}} v, err := wire.Unmarshal{{CodecName .}}(buffer, wt) self.{{GoFieldName .}} = {{ProtoTypeName .}}(v) return err {{else if IsStruct .}} - return wire.Unmarshal{{CodecName .}}(buffer, wt, &self.{{GoFieldName .}}) {{else if IsEnumSlice .}} + var elm {{.Type}} + self.{{GoFieldName .}} = &elm + return wire.Unmarshal{{CodecName .}}(buffer, wt, self.{{GoFieldName .}}) {{else if IsEnumSlice .}} v, err := wire.Unmarshal{{CodecName .}}(buffer, wt) for _, vv := range v { self.{{GoFieldName .}} = append(self.{{GoFieldName .}}, {{ProtoElementTypeName .}}(vv)) @@ -133,6 +129,13 @@ import ( "reflect" ) + +var ( + _ cellnet.MessageMeta + _ codec.CodecRecycler + _ reflect.Kind +) + func init() { {{range .Structs}} cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ diff --git a/tests/Make.sh b/tests/Make.sh index 8bf43b0..b2c21a8 100644 --- a/tests/Make.sh +++ b/tests/Make.sh @@ -5,5 +5,6 @@ go build -v -o=${GOPATH}/bin/protoplus github.com/davyxu/protoplus/cmd/protoplus ${GOPATH}/bin/protoplus -ppgo_out=code_gen.go -package=tests code.proto ${GOPATH}/bin/protoplus -ppgoreg_out=reg_gen.go -package=tests code.proto ${GOPATH}/bin/protoplus -ppcs_out=../example/csharp/Example/ProtoGen.cs -package=Proto code.proto +${GOPATH}/bin/protoplus -ppcsreg_out=../example/csharp/Example/ProtoGenReg.cs -package=Proto code.proto ${GOPATH}/bin/protoplus -pbscheme_out=pb_gen.proto -package=proto code.proto ${GOPATH}/bin/protoplus -route_out=route.json -package=proto code.proto \ No newline at end of file diff --git a/tests/code_gen.go b/tests/code_gen.go index 5231d87..2614931 100644 --- a/tests/code_gen.go +++ b/tests/code_gen.go @@ -3,14 +3,14 @@ package tests import ( - "github.com/davyxu/protoplus/proto" - "github.com/davyxu/protoplus/wire" + "github.com/davyxu/protoplus/api/golang" + "github.com/davyxu/protoplus/api/golang/wire" "unsafe" ) var ( _ *wire.Buffer - _ = proto.Marshal + _ = ppgo.Marshal _ unsafe.Pointer ) @@ -51,7 +51,7 @@ type MyTypeMini struct { Str string } -func (self *MyTypeMini) String() string { return proto.CompactTextString(self) } +func (self *MyTypeMini) String() string { return ppgo.CompactTextString(self) } func (self *MyTypeMini) Size() (ret int) { @@ -157,7 +157,7 @@ type MySubType struct { EnumSlice []MyEnum } -func (self *MySubType) String() string { return proto.CompactTextString(self) } +func (self *MySubType) String() string { return ppgo.CompactTextString(self) } func (self *MySubType) Size() (ret int) { @@ -340,7 +340,7 @@ type MyType struct { Float32 float32 Float64 float64 Str string - Struct MySubType + Struct *MySubType BytesSlice []byte BoolSlice []bool Int32Slice []int32 @@ -350,12 +350,12 @@ type MyType struct { Float32Slice []float32 Float64Slice []float64 StrSlice []string - StructSlice []MySubType + StructSlice []*MySubType Enum MyEnum EnumSlice []MyEnum } -func (self *MyType) String() string { return proto.CompactTextString(self) } +func (self *MyType) String() string { return ppgo.CompactTextString(self) } func (self *MyType) Size() (ret int) { @@ -375,7 +375,7 @@ func (self *MyType) Size() (ret int) { ret += wire.SizeString(8, self.Str) - ret += wire.SizeStruct(9, &self.Struct) + ret += wire.SizeStruct(9, self.Struct) ret += wire.SizeBytes(10, self.BytesSlice) @@ -397,7 +397,7 @@ func (self *MyType) Size() (ret int) { if len(self.StructSlice) > 0 { for _, elm := range self.StructSlice { - ret += wire.SizeStruct(19, &elm) + ret += wire.SizeStruct(19, elm) } } @@ -426,7 +426,7 @@ func (self *MyType) Marshal(buffer *wire.Buffer) error { wire.MarshalString(buffer, 8, self.Str) - wire.MarshalStruct(buffer, 9, &self.Struct) + wire.MarshalStruct(buffer, 9, self.Struct) wire.MarshalBytes(buffer, 10, self.BytesSlice) @@ -447,7 +447,7 @@ func (self *MyType) Marshal(buffer *wire.Buffer) error { wire.MarshalStringSlice(buffer, 18, self.StrSlice) for _, elm := range self.StructSlice { - wire.MarshalStruct(buffer, 19, &elm) + wire.MarshalStruct(buffer, 19, elm) } wire.MarshalInt32(buffer, 20, int32(self.Enum)) @@ -492,7 +492,9 @@ func (self *MyType) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire.Wi self.Str = v return err case 9: - return wire.UnmarshalStruct(buffer, wt, &self.Struct) + var elm MySubType + self.Struct = &elm + return wire.UnmarshalStruct(buffer, wt, self.Struct) case 10: v, err := wire.UnmarshalBytes(buffer, wt) self.BytesSlice = v @@ -534,7 +536,7 @@ func (self *MyType) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire.Wi if err := wire.UnmarshalStruct(buffer, wt, &elm); err != nil { return err } else { - self.StructSlice = append(self.StructSlice, elm) + self.StructSlice = append(self.StructSlice, &elm) return nil } case 20: @@ -556,7 +558,7 @@ func (self *MyType) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire.Wi type LoginREQ struct { } -func (self *LoginREQ) String() string { return proto.CompactTextString(self) } +func (self *LoginREQ) String() string { return ppgo.CompactTextString(self) } func (self *LoginREQ) Size() (ret int) { @@ -579,7 +581,7 @@ func (self *LoginREQ) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire. type LoginACK struct { } -func (self *LoginACK) String() string { return proto.CompactTextString(self) } +func (self *LoginACK) String() string { return ppgo.CompactTextString(self) } func (self *LoginACK) Size() (ret int) { diff --git a/tests/code_test.go b/tests/code_test.go index 11b9ca6..73bd77d 100644 --- a/tests/code_test.go +++ b/tests/code_test.go @@ -3,8 +3,7 @@ package tests import ( "encoding/json" _ "github.com/davyxu/cellnet/codec/protoplus" - "github.com/davyxu/protoplus/proto" - "github.com/davyxu/protoplus/wire" + "github.com/davyxu/protoplus/api/golang" "github.com/stretchr/testify/assert" "math" "reflect" @@ -13,10 +12,10 @@ import ( func TestOptional(t *testing.T) { bigData := makeMyType() - data, err := proto.Marshal(&bigData) + data, err := ppgo.Marshal(&bigData) assert.Equal(t, err, nil) var output MyTypeMini - assert.Equal(t, proto.Unmarshal(data, &output), nil) + assert.Equal(t, ppgo.Unmarshal(data, &output), nil) //t.Logf("%+v", output) //assert.Equal(t, bigData, output) @@ -46,11 +45,11 @@ func makeMyType() (input MyType) { input.Enum = MyEnum_Two input.EnumSlice = []MyEnum{MyEnum_Two, MyEnum_One, MyEnum_Zero} - input.Struct = MySubType{ + input.Struct = &MySubType{ Str: "world", } - input.StructSlice = []MySubType{ + input.StructSlice = []*MySubType{ {Int32: 100}, {Str: "200"}, } @@ -58,15 +57,15 @@ func makeMyType() (input MyType) { return } -func verifyWire(t *testing.T, raw wire.Struct) { - data, err := proto.Marshal(raw) +func verifyWire(t *testing.T, raw ppgo.Struct) { + data, err := ppgo.Marshal(raw) assert.Equal(t, err, nil) t.Log("proto+:", len(data), data) - newType := reflect.New(reflect.TypeOf(raw).Elem()).Interface().(wire.Struct) + newType := reflect.New(reflect.TypeOf(raw).Elem()).Interface().(ppgo.Struct) - assert.Equal(t, proto.Unmarshal(data, newType), nil) + assert.Equal(t, ppgo.Unmarshal(data, newType), nil) assert.Equal(t, raw, newType) } @@ -79,13 +78,13 @@ func verifyText(t *testing.T, raw interface{}) { panic("expect ptr") } - data := proto.CompactTextString(raw) + data := ppgo.CompactTextString(raw) t.Log(data) newType := reflect.New(tRaw.Elem()).Interface() - assert.Equal(t, proto.UnmarshalText(data, newType), nil) + assert.Equal(t, ppgo.UnmarshalText(data, newType), nil) assert.Equal(t, raw, newType) } @@ -96,7 +95,7 @@ func TestFull(t *testing.T) { verifyWire(t, &input) - t.Logf("%v", proto.MarshalTextString(input)) + t.Logf("%v", ppgo.MarshalTextString(input)) } func TestIntSlice(t *testing.T) { @@ -111,13 +110,13 @@ func TestSkipField(t *testing.T) { input := makeMyType() - data, err := proto.Marshal(&input) + data, err := ppgo.Marshal(&input) assert.Equal(t, err, nil) jsondata, _ := json.Marshal(&input) var mini MyTypeMini - assert.Equal(t, proto.Unmarshal(data, &mini), nil) + assert.Equal(t, ppgo.Unmarshal(data, &mini), nil) var miniJson MyTypeMini json.Unmarshal(jsondata, &miniJson) @@ -127,7 +126,7 @@ func TestSkipField(t *testing.T) { func TestPtrField(t *testing.T) { input := MyType{} - data, err := proto.Marshal(&input) + data, err := ppgo.Marshal(&input) t.Log(data, err) } diff --git a/tests/reg_gen.go b/tests/reg_gen.go index adfe1d9..0c0dc49 100644 --- a/tests/reg_gen.go +++ b/tests/reg_gen.go @@ -7,6 +7,12 @@ import ( "reflect" ) +var ( + _ cellnet.MessageMeta + _ codec.CodecRecycler + _ reflect.Kind +) + func init() { cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ From 8b261adb8012a3bd66e3bfa3827a7d4bb0d4b41a Mon Sep 17 00:00:00 2001 From: xubo Date: Tue, 2 Mar 2021 16:12:26 +0800 Subject: [PATCH 21/39] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=99=A8=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen/route/route.go | 1 + model/route.go | 1 + 2 files changed, 2 insertions(+) diff --git a/gen/route/route.go b/gen/route/route.go index 2e15f4e..1a36db2 100644 --- a/gen/route/route.go +++ b/gen/route/route.go @@ -47,6 +47,7 @@ func genJsonData(ctx *gen.Context) ([]byte, error) { rt.Rule = append(rt.Rule, &model.RouteRule{ MsgName: ctx.PackageName + "." + d.Name, SvcName: msgDir.To, + Router: msgDir.Mid, MsgID: msgID, }) } diff --git a/model/route.go b/model/route.go index ab1973c..cdc7578 100644 --- a/model/route.go +++ b/model/route.go @@ -6,6 +6,7 @@ type RouteRule struct { MsgID int SvcName string + Router string `json:",omitempty"` } // 路由表,包含多条路由规则 From 6ba11d1996fadf7e3d2aa38117c4f481b54b16fb Mon Sep 17 00:00:00 2001 From: xubo Date: Wed, 24 Mar 2021 14:44:15 +0800 Subject: [PATCH 22/39] =?UTF-8?q?=E5=8A=A0=E5=BC=BA=E8=A7=84=E5=88=99?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen/route/route.go | 1 + go.mod | 3 +- go.sum | 133 +++++++++++++++++++++++++++++++++- parser/parse_descriptorset.go | 8 ++ 4 files changed, 142 insertions(+), 3 deletions(-) diff --git a/gen/route/route.go b/gen/route/route.go index 1a36db2..bd28537 100644 --- a/gen/route/route.go +++ b/gen/route/route.go @@ -44,6 +44,7 @@ func genJsonData(ctx *gen.Context) ([]byte, error) { msgID := codegen.StructMsgID(d) if msgDir.Valid() { + rt.Rule = append(rt.Rule, &model.RouteRule{ MsgName: ctx.PackageName + "." + d.Name, SvcName: msgDir.To, diff --git a/go.mod b/go.mod index d77d21d..5816f55 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/davyxu/protoplus go 1.12 require ( - github.com/davyxu/x v0.0.0 github.com/davyxu/cellnet v4.1.0+incompatible github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200 github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50 @@ -11,5 +10,7 @@ require ( ) replace github.com/davyxu/ulexer => ../ulexer + replace github.com/davyxu/cellnet => ../cellnet + replace github.com/davyxu/x => ../x diff --git a/go.sum b/go.sum index 32ab9a9..a83fbca 100644 --- a/go.sum +++ b/go.sum @@ -1,35 +1,164 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/aws/aws-sdk-go v1.35.20/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davyxu/cellnet v4.1.0+incompatible h1:zDRqhkFRhBTD7ajra2888aoRLN1qlv8LV8+qHg/emO4= -github.com/davyxu/cellnet v4.1.0+incompatible/go.mod h1:YyjRD4BinuDQmXWX7iHjPtnVf3qp2EzVN2/7P/8GKXE= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200 h1:qLWlQBFg5c7HUOK+UdoGouLzRaYBQr2WwoAqixU+eik= github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200/go.mod h1:K/1PVWqaQEwMs+N+VvaoS66o1BAAwso+jEgXKBIa8QY= github.com/davyxu/goobjfmt v0.1.0/go.mod h1:KKrytCtCXny2sEg3ojQfJ4NThhBP8hKw/qM9vhDwgog= github.com/davyxu/protoplus v0.1.0/go.mod h1:WzmNYPvYsyks3G81jCJ/vGY2ljs49qFMfCmXGwvxFLA= github.com/davyxu/ulog v1.0.0 h1:CfKRT2yK1JStZH5Yeal3BtF3kj/OETt1gTchuAbekBU= github.com/davyxu/ulog v1.0.0/go.mod h1:kg3w8bI/8AOFX/NyNVHBAUBcvX7dDHrTfxdnk1sef18= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= +github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/hashicorp/consul/api v1.8.1/go.mod h1:sDjTOq0yUyv5G4h+BqSea7Fn6BU+XbolEz1952UB+mk= +github.com/hashicorp/consul/sdk v0.7.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= +github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY= +github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= +github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/klauspost/compress v1.11.12/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= +github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mediocregopher/radix.v2 v0.0.0-20181115013041-b67df6e626f9/go.mod h1:fLRUbhbSd5Px2yKUaGYYPltlyxi1guJz1vCmo1RQL50= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= +github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/olivere/elastic/v7 v7.0.22/go.mod h1:VDexNy9NjmtAkrjNoI7tImv7FR4tf5zUA3ickqu5Pc8= +github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/smartystreets/assertions v1.1.1/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= +github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= +github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/parser/parse_descriptorset.go b/parser/parse_descriptorset.go index 48b1cf9..a71f606 100644 --- a/parser/parse_descriptorset.go +++ b/parser/parse_descriptorset.go @@ -7,6 +7,7 @@ import ( "github.com/davyxu/protoplus/model" "io" "io/ioutil" + "strings" ) // 解析字符串 @@ -91,6 +92,13 @@ func checkAndFix(ctx *Context) error { } } + if !d.TagExists("AutoMsgID") && !d.TagExists("MsgID") && (strings.HasSuffix(d.Name, "REQ") || strings.HasSuffix(d.Name, "ACK")) { + return fmt.Errorf("struct like message but not gen msgid: %s", d.Name) + } + + if d.Kind == model.Kind_Struct && (d.TagExists("AutoMsgID") || d.TagExists("MsgID")) && (!strings.HasSuffix(d.Name, "REQ") && !strings.HasSuffix(d.Name, "ACK")) { + return fmt.Errorf("struct gen msgid, but not like a message(REQ/ACK) : %s", d.Name) + } } return nil From 6ce59c75e24cda0a0898aebb842eec0cf766916a Mon Sep 17 00:00:00 2001 From: davyxu Date: Wed, 24 Mar 2021 15:46:36 +0800 Subject: [PATCH 23/39] =?UTF-8?q?=E6=9B=B4=E6=96=B0golexer=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DAutoMsgID=E4=B8=8D=E8=AF=86=E5=88=AB=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/csharp/Example/ProtoGenReg.cs | 4 ++-- go.mod | 2 +- go.sum | 2 ++ tests/Make.sh | 3 +++ tests/code.proto | 4 ++-- tests/reg_gen.go | 4 ++-- tests/route.json | 2 +- 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/example/csharp/Example/ProtoGenReg.cs b/example/csharp/Example/ProtoGenReg.cs index feafab9..492078f 100644 --- a/example/csharp/Example/ProtoGenReg.cs +++ b/example/csharp/Example/ProtoGenReg.cs @@ -36,14 +36,14 @@ public static void Visit(Action callback) callback(new MetaInfo { Type = typeof(LoginREQ), - ID = 0, + ID = 45589, SourcePeer = "client", TargetPeer = "game", }); callback(new MetaInfo { Type = typeof(LoginACK), - ID = 0, + ID = 7420, SourcePeer = "", TargetPeer = "", }); diff --git a/go.mod b/go.mod index 5816f55..e54cdb4 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.12 require ( github.com/davyxu/cellnet v4.1.0+incompatible - github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200 + github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50 github.com/stretchr/testify v1.6.1 ) diff --git a/go.sum b/go.sum index a83fbca..a82d02d 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200 h1:qLWlQBFg5c7HUOK+UdoGouLzRaYBQr2WwoAqixU+eik= github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200/go.mod h1:K/1PVWqaQEwMs+N+VvaoS66o1BAAwso+jEgXKBIa8QY= +github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a h1:VYps2zwgBJPNuLGLiPrR4w6ud6cJpwlBA1OOytrCpx4= +github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a/go.mod h1:dCUDBJcBQ9/AOzz6++KvSetGgVf5zXphevt6LQvKy0A= github.com/davyxu/goobjfmt v0.1.0/go.mod h1:KKrytCtCXny2sEg3ojQfJ4NThhBP8hKw/qM9vhDwgog= github.com/davyxu/protoplus v0.1.0/go.mod h1:WzmNYPvYsyks3G81jCJ/vGY2ljs49qFMfCmXGwvxFLA= github.com/davyxu/ulog v1.0.0 h1:CfKRT2yK1JStZH5Yeal3BtF3kj/OETt1gTchuAbekBU= diff --git a/tests/Make.sh b/tests/Make.sh index b2c21a8..44bb5fc 100644 --- a/tests/Make.sh +++ b/tests/Make.sh @@ -1,4 +1,7 @@ #!/usr/bin/env bash + +set -e + go build -v -o=${GOPATH}/bin/protoplus github.com/davyxu/protoplus/cmd/protoplus # code.proto为输入文件 diff --git a/tests/code.proto b/tests/code.proto index 419a1e1..978a15d 100644 --- a/tests/code.proto +++ b/tests/code.proto @@ -94,12 +94,12 @@ struct MyType EnumSlice []MyEnum } -[MsgDir: "client -> game"] +[AutoMsgID MsgDir: "client -> game"] struct LoginREQ { } - +[AutoMsgID] struct LoginACK { } diff --git a/tests/reg_gen.go b/tests/reg_gen.go index 0c0dc49..c0c47a6 100644 --- a/tests/reg_gen.go +++ b/tests/reg_gen.go @@ -36,13 +36,13 @@ func init() { cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ Codec: codec.MustGetCodec("protoplus"), Type: reflect.TypeOf((*LoginREQ)(nil)).Elem(), - ID: 0, + ID: 17076, New: func() interface{} { return &LoginREQ{} }, }) cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ Codec: codec.MustGetCodec("protoplus"), Type: reflect.TypeOf((*LoginACK)(nil)).Elem(), - ID: 0, + ID: 44443, New: func() interface{} { return &LoginACK{} }, }) } diff --git a/tests/route.json b/tests/route.json index 8b37a33..f3fb34d 100644 --- a/tests/route.json +++ b/tests/route.json @@ -2,7 +2,7 @@ "Rule": [ { "MsgName": "proto.LoginREQ", - "MsgID": 0, + "MsgID": 45589, "SvcName": "game" } ] From e1ded6ea88963322b3e0bb833fc906a409cbbc0d Mon Sep 17 00:00:00 2001 From: xubo Date: Thu, 22 Apr 2021 19:02:59 +0800 Subject: [PATCH 24/39] =?UTF-8?q?=E9=80=82=E9=85=8Dcellnet5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen/ppgo/text.go | 12 ++++++------ tests/reg_gen.go | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gen/ppgo/text.go b/gen/ppgo/text.go index 1502eb2..2d6ceb9 100644 --- a/gen/ppgo/text.go +++ b/gen/ppgo/text.go @@ -123,23 +123,23 @@ func (self *{{.Name}}) Unmarshal(buffer *wire.Buffer, fieldIndex uint64, wt wire const RegTemplateText = `// Generated by github.com/davyxu/protoplus package {{.PackageName}} -import ( - "github.com/davyxu/cellnet" +import ( "github.com/davyxu/cellnet/codec" + "github.com/davyxu/cellnet/meta" "reflect" ) var ( - _ cellnet.MessageMeta - _ codec.CodecRecycler + _ cellmeta.Meta + _ cellcodec.CodecRecycler _ reflect.Kind ) func init() { {{range .Structs}} - cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ - Codec: codec.MustGetCodec("{{StructCodec .}}"), + cellmeta.Register(&cellmeta.Meta{ + Codec: cellcodec.MustGetByName("{{StructCodec .}}"), Type: reflect.TypeOf((*{{.Name}})(nil)).Elem(), ID: {{StructMsgID .}}, New: func() interface{} { return &{{.Name}}{} }, diff --git a/tests/reg_gen.go b/tests/reg_gen.go index c0c47a6..bb39098 100644 --- a/tests/reg_gen.go +++ b/tests/reg_gen.go @@ -8,38 +8,38 @@ import ( ) var ( - _ cellnet.MessageMeta + _ cellmeta.Meta _ codec.CodecRecycler _ reflect.Kind ) func init() { - cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ + cellnet.RegisterMessageMeta(&cellmeta.Meta{ Codec: codec.MustGetCodec("protoplus"), Type: reflect.TypeOf((*MyTypeMini)(nil)).Elem(), ID: 0, New: func() interface{} { return &MyTypeMini{} }, }) - cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ + cellnet.RegisterMessageMeta(&cellmeta.Meta{ Codec: codec.MustGetCodec("protoplus"), Type: reflect.TypeOf((*MySubType)(nil)).Elem(), ID: 0, New: func() interface{} { return &MySubType{} }, }) - cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ + cellnet.RegisterMessageMeta(&cellmeta.Meta{ Codec: codec.MustGetCodec("protoplus"), Type: reflect.TypeOf((*MyType)(nil)).Elem(), ID: 0, New: func() interface{} { return &MyType{} }, }) - cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ + cellnet.RegisterMessageMeta(&cellmeta.Meta{ Codec: codec.MustGetCodec("protoplus"), Type: reflect.TypeOf((*LoginREQ)(nil)).Elem(), ID: 17076, New: func() interface{} { return &LoginREQ{} }, }) - cellnet.RegisterMessageMeta(&cellnet.MessageMeta{ + cellnet.RegisterMessageMeta(&cellmeta.Meta{ Codec: codec.MustGetCodec("protoplus"), Type: reflect.TypeOf((*LoginACK)(nil)).Elem(), ID: 44443, From d27e5a39ad40181cbba6ad15b6b84dc8b6b3ac2e Mon Sep 17 00:00:00 2001 From: davyxu Date: Mon, 24 May 2021 11:50:16 +0800 Subject: [PATCH 25/39] =?UTF-8?q?=E6=94=AF=E6=8C=81pb=E6=8C=89=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/protoplus/main.go | 5 ++- gen/pbscheme/gen_dir.go | 69 +++++++++++++++++++++++++++++++++++++++++ go.sum | 8 ----- model/descriptorset.go | 59 +++++++++++++++++++++++++++++++++++ model/field.go | 2 +- 5 files changed, 133 insertions(+), 10 deletions(-) create mode 100644 gen/pbscheme/gen_dir.go diff --git a/cmd/protoplus/main.go b/cmd/protoplus/main.go index c90e373..8cf3b22 100644 --- a/cmd/protoplus/main.go +++ b/cmd/protoplus/main.go @@ -42,7 +42,10 @@ var ( {name: "ppgoreg_out", usage: "output protoplus message register entry in golang", outfile: ppgo.GenGoReg}, {name: "ppcs_out", usage: "output protoplus message serialize csharp source file", outfile: ppcs.GenCS}, {name: "ppcsreg_out", usage: "output protoplus message register entry in csharp", outfile: ppcs.GenCSReg}, - {name: "pbscheme_out", usage: "output google protobuf schema file", outfile: pbscheme.GenProto}, + {name: "pbscheme_out", usage: "output google protobuf schema file as single file", outfile: pbscheme.GenProto}, + + // 使用例子: protoc $(cat filelist.txt) + {name: "pbscheme_dir", usage: "output google protobuf schema files into dir", outfile: pbscheme.GenProtoDir}, {name: "ppscheme_out", usage: "output protoplus scheme json file", outfile: ppscheme.GenJson}, {name: "route_out", usage: "output route table json file", outfile: route.GenJson}, diff --git a/gen/pbscheme/gen_dir.go b/gen/pbscheme/gen_dir.go new file mode 100644 index 0000000..8aa486a --- /dev/null +++ b/gen/pbscheme/gen_dir.go @@ -0,0 +1,69 @@ +package pbscheme + +import ( + "fmt" + "github.com/davyxu/protoplus/codegen" + "github.com/davyxu/protoplus/gen" + "io/ioutil" + "path/filepath" + "strings" +) + +const protoDirCodeTemplate = `// Generated by github.com/davyxu/protoplus +// DO NOT EDIT! +syntax = "proto3"; + +option go_package= "./;proto"; + +package {{.PackageName}}; + +{{range $a, $enumobj := .DependentSource}} +import "{{.}}"; {{end}} + +{{range $a, $enumobj := .Enums}} +enum {{.Name}} { {{range .Fields}} + {{.Name}} = {{PbTagNumber $enumobj .}}; {{end}} +}{{end}} + +{{range $a, $obj := .Structs}} +{{ObjectLeadingComment .}} +message {{.Name}} { {{range .Fields}} + {{PbTypeName .}} {{GoFieldName .}} = {{PbTagNumber $obj .}};{{FieldTrailingComment .}} {{end}} +} +{{end}} +` + +func GenProtoDir(ctx *gen.Context) error { + + rootDS := ctx.DescriptorSet + + var sb strings.Builder + + for srcName, ds := range rootDS.DescriptorSetBySource() { + + ctx.DescriptorSet = ds + + gen := codegen.NewCodeGen("dirproto"). + RegisterTemplateFunc(codegen.UsefulFunc). + RegisterTemplateFunc(UsefulFunc). + ParseTemplate(protoDirCodeTemplate, ctx) + + if gen.Error() != nil { + fmt.Println(string(gen.Data())) + return gen.Error() + } + + fullPathName := filepath.Join(ctx.OutputFileName, srcName) + + fmt.Fprintf(&sb, "%s ", srcName) + + err := gen.WriteOutputFile(fullPathName).Error() + if err != nil { + return err + } + } + + err := ioutil.WriteFile(filepath.Join(ctx.OutputFileName, "filelist.txt"), []byte(sb.String()), 0666) + + return err +} diff --git a/go.sum b/go.sum index a82d02d..1c27dfb 100644 --- a/go.sum +++ b/go.sum @@ -7,17 +7,12 @@ github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgI github.com/aws/aws-sdk-go v1.35.20/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200 h1:qLWlQBFg5c7HUOK+UdoGouLzRaYBQr2WwoAqixU+eik= -github.com/davyxu/golexer v0.0.0-20180314091252-f048a86ae200/go.mod h1:K/1PVWqaQEwMs+N+VvaoS66o1BAAwso+jEgXKBIa8QY= github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a h1:VYps2zwgBJPNuLGLiPrR4w6ud6cJpwlBA1OOytrCpx4= github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a/go.mod h1:dCUDBJcBQ9/AOzz6++KvSetGgVf5zXphevt6LQvKy0A= -github.com/davyxu/goobjfmt v0.1.0/go.mod h1:KKrytCtCXny2sEg3ojQfJ4NThhBP8hKw/qM9vhDwgog= github.com/davyxu/protoplus v0.1.0/go.mod h1:WzmNYPvYsyks3G81jCJ/vGY2ljs49qFMfCmXGwvxFLA= -github.com/davyxu/ulog v1.0.0 h1:CfKRT2yK1JStZH5Yeal3BtF3kj/OETt1gTchuAbekBU= github.com/davyxu/ulog v1.0.0/go.mod h1:kg3w8bI/8AOFX/NyNVHBAUBcvX7dDHrTfxdnk1sef18= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= @@ -32,7 +27,6 @@ github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUz github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hashicorp/consul/api v1.8.1/go.mod h1:sDjTOq0yUyv5G4h+BqSea7Fn6BU+XbolEz1952UB+mk= github.com/hashicorp/consul/sdk v0.7.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -70,7 +64,6 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mediocregopher/radix.v2 v0.0.0-20181115013041-b67df6e626f9/go.mod h1:fLRUbhbSd5Px2yKUaGYYPltlyxi1guJz1vCmo1RQL50= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= @@ -155,7 +148,6 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/model/descriptorset.go b/model/descriptorset.go index 96dcf37..349d134 100644 --- a/model/descriptorset.go +++ b/model/descriptorset.go @@ -4,6 +4,10 @@ type DescriptorSet struct { Objects []*Descriptor `json:",omitempty"` PackageName string Codec string + + DependentSource []string // 按文件管理的描述符取出时, 这个字段有效. 本文件依赖的其他source的symbiol + SourceName string // 按文件管理的描述符取出时, 这个字段有效. 表示本DescriptorSet的文件名 + dsBySource map[string]*DescriptorSet // 按文件名管理的描述符集合 } func (self *DescriptorSet) Services() (ret []*Descriptor) { @@ -64,3 +68,58 @@ func (self *DescriptorSet) ObjectByName(name string) *Descriptor { func (self *DescriptorSet) AddObject(d *Descriptor) { self.Objects = append(self.Objects, d) } + +func (self *DescriptorSet) addDependentSource(name string) { + + if self.SourceName == name { + return + } + + for _, n := range self.DependentSource { + if n == name { + return + } + } + + self.DependentSource = append(self.DependentSource, name) +} + +func (self *DescriptorSet) DescriptorSetBySource() map[string]*DescriptorSet { + if self.dsBySource != nil { + return self.dsBySource + } + + self.dsBySource = map[string]*DescriptorSet{} + + for _, obj := range self.Objects { + ds := self.dsBySource[obj.SrcName] + if ds == nil { + ds = &DescriptorSet{ + PackageName: self.PackageName, + Codec: self.Codec, + SourceName: obj.SrcName, + } + self.dsBySource[obj.SrcName] = ds + } + + ds.AddObject(obj) + } + + for _, file := range self.dsBySource { + for _, st := range file.Structs() { + + for _, fd := range st.Fields { + + switch fd.Kind { + case Kind_Struct, Kind_Enum: + refTarget := self.ObjectByName(fd.Type) + if refTarget != nil { + file.addDependentSource(refTarget.SrcName) + } + } + } + } + } + + return self.dsBySource +} diff --git a/model/field.go b/model/field.go index b0d28a1..ef12743 100644 --- a/model/field.go +++ b/model/field.go @@ -12,7 +12,7 @@ type FieldDescriptor struct { Tag int `json:",omitempty"` Repeatd bool `json:",omitempty"` - Descriptor *Descriptor `json:"-"` + Descriptor *Descriptor `json:"-"` // 字段归属的父级描述符 } func (self *FieldDescriptor) ParseType(str string) { From 35cbd476cb7ccf9e250abe26c928a3885388bdcd Mon Sep 17 00:00:00 2001 From: davyxu Date: Thu, 10 Jun 2021 09:38:03 +0800 Subject: [PATCH 26/39] =?UTF-8?q?=E5=8D=87=E7=BA=A7test=20gen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/reg_gen.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/reg_gen.go b/tests/reg_gen.go index bb39098..efead79 100644 --- a/tests/reg_gen.go +++ b/tests/reg_gen.go @@ -2,45 +2,45 @@ package tests import ( - "github.com/davyxu/cellnet" "github.com/davyxu/cellnet/codec" + "github.com/davyxu/cellnet/meta" "reflect" ) var ( _ cellmeta.Meta - _ codec.CodecRecycler + _ cellcodec.CodecRecycler _ reflect.Kind ) func init() { - cellnet.RegisterMessageMeta(&cellmeta.Meta{ - Codec: codec.MustGetCodec("protoplus"), + cellmeta.Register(&cellmeta.Meta{ + Codec: cellcodec.MustGetByName("protoplus"), Type: reflect.TypeOf((*MyTypeMini)(nil)).Elem(), ID: 0, New: func() interface{} { return &MyTypeMini{} }, }) - cellnet.RegisterMessageMeta(&cellmeta.Meta{ - Codec: codec.MustGetCodec("protoplus"), + cellmeta.Register(&cellmeta.Meta{ + Codec: cellcodec.MustGetByName("protoplus"), Type: reflect.TypeOf((*MySubType)(nil)).Elem(), ID: 0, New: func() interface{} { return &MySubType{} }, }) - cellnet.RegisterMessageMeta(&cellmeta.Meta{ - Codec: codec.MustGetCodec("protoplus"), + cellmeta.Register(&cellmeta.Meta{ + Codec: cellcodec.MustGetByName("protoplus"), Type: reflect.TypeOf((*MyType)(nil)).Elem(), ID: 0, New: func() interface{} { return &MyType{} }, }) - cellnet.RegisterMessageMeta(&cellmeta.Meta{ - Codec: codec.MustGetCodec("protoplus"), + cellmeta.Register(&cellmeta.Meta{ + Codec: cellcodec.MustGetByName("protoplus"), Type: reflect.TypeOf((*LoginREQ)(nil)).Elem(), ID: 17076, New: func() interface{} { return &LoginREQ{} }, }) - cellnet.RegisterMessageMeta(&cellmeta.Meta{ - Codec: codec.MustGetCodec("protoplus"), + cellmeta.Register(&cellmeta.Meta{ + Codec: cellcodec.MustGetByName("protoplus"), Type: reflect.TypeOf((*LoginACK)(nil)).Elem(), ID: 44443, New: func() interface{} { return &LoginACK{} }, From 84c736c135d44950e5c2faae139df5063d8e67dc Mon Sep 17 00:00:00 2001 From: davyxu Date: Tue, 15 Jun 2021 14:23:27 +0800 Subject: [PATCH 27/39] =?UTF-8?q?pb=E8=BE=93=E5=87=BA=E5=8C=85=E4=B8=8Epac?= =?UTF-8?q?kage=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen/pbscheme/gen_dir.go | 2 +- gen/pbscheme/gen_proto.go | 2 +- gen/ppgo/text.go | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gen/pbscheme/gen_dir.go b/gen/pbscheme/gen_dir.go index 8aa486a..1efc5d1 100644 --- a/gen/pbscheme/gen_dir.go +++ b/gen/pbscheme/gen_dir.go @@ -13,7 +13,7 @@ const protoDirCodeTemplate = `// Generated by github.com/davyxu/protoplus // DO NOT EDIT! syntax = "proto3"; -option go_package= "./;proto"; +option go_package= "./;{{.PackageName}}"; package {{.PackageName}}; diff --git a/gen/pbscheme/gen_proto.go b/gen/pbscheme/gen_proto.go index ec61361..49df3d0 100644 --- a/gen/pbscheme/gen_proto.go +++ b/gen/pbscheme/gen_proto.go @@ -11,7 +11,7 @@ const protoCodeTemplate = `// Generated by github.com/davyxu/protoplus // DO NOT EDIT! syntax = "proto3"; -option go_package= ".;proto"; +option go_package= "./;{{.PackageName}}"; package {{.PackageName}}; diff --git a/gen/ppgo/text.go b/gen/ppgo/text.go index 2d6ceb9..046dad7 100644 --- a/gen/ppgo/text.go +++ b/gen/ppgo/text.go @@ -139,10 +139,11 @@ var ( func init() { {{range .Structs}} cellmeta.Register(&cellmeta.Meta{ - Codec: cellcodec.MustGetByName("{{StructCodec .}}"), - Type: reflect.TypeOf((*{{.Name}})(nil)).Elem(), + FullName: "{{$.PackageName}}.{{.Name}}", ID: {{StructMsgID .}}, New: func() interface{} { return &{{.Name}}{} }, + Type: reflect.TypeOf((*{{.Name}})(nil)).Elem(), + Codec: cellcodec.MustGetByName("{{StructCodec .}}"), }) {{end}} } ` From 2b52e6bc268f75876b97f195fb48f5f217d16bf4 Mon Sep 17 00:00:00 2001 From: davyxu Date: Wed, 16 Jun 2021 18:15:21 +0800 Subject: [PATCH 28/39] =?UTF-8?q?=E6=94=AF=E6=8C=81import,=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4service/rpc=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen/pbscheme/gen_dir.go | 72 ++++++++++++++++++++++++++++++-- model/descriptorset.go | 70 ------------------------------- model/type.go | 1 - parser/context.go | 33 ++++++++++++--- parser/entry.go | 18 +------- parser/enumfield.go | 31 +++++++------- parser/parse_descriptor.go | 34 +++++++-------- parser/parse_descriptorset.go | 11 +++-- parser/parse_import.go | 30 +++++++++++++ parser/parser.go | 2 + parser/service.go | 44 ------------------- parser/structfield.go | 19 +++++---- tests/Make.sh | 14 ++++--- tests/code_test.go | 12 +++--- tests/filelist.proto | 2 + tests/msg.proto | 11 +++++ tests/pb_gen.proto | 2 +- tests/reg_gen.go | 45 +++++++++++--------- tests/{code.proto => type.proto} | 21 ---------- 19 files changed, 227 insertions(+), 245 deletions(-) create mode 100644 parser/parse_import.go delete mode 100644 parser/service.go create mode 100644 tests/filelist.proto create mode 100644 tests/msg.proto rename tests/{code.proto => type.proto} (86%) diff --git a/gen/pbscheme/gen_dir.go b/gen/pbscheme/gen_dir.go index 1efc5d1..31c96f4 100644 --- a/gen/pbscheme/gen_dir.go +++ b/gen/pbscheme/gen_dir.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/davyxu/protoplus/codegen" "github.com/davyxu/protoplus/gen" + "github.com/davyxu/protoplus/model" "io/ioutil" "path/filepath" "strings" @@ -33,20 +34,83 @@ message {{.Name}} { {{range .Fields}} {{end}} ` +type PBDescriptorSet struct { + model.DescriptorSet + + // pb生成文件依赖时, 使用以下字段 + DependentSource []string // 按文件管理的描述符取出时, 这个字段有效. 本文件依赖的其他source的symbiol + SourceName string // 按文件管理的描述符取出时, 这个字段有效. 表示本DescriptorSet的文件名 + dsBySource map[string]*PBDescriptorSet // 按文件名管理的描述符集合 +} + +func (self *PBDescriptorSet) addDependentSource(name string) { + + if self.SourceName == name { + return + } + + for _, n := range self.DependentSource { + if n == name { + return + } + } + + self.DependentSource = append(self.DependentSource, name) +} + +func (self *PBDescriptorSet) DescriptorSetBySource() map[string]*PBDescriptorSet { + if self.dsBySource != nil { + return self.dsBySource + } + + self.dsBySource = map[string]*PBDescriptorSet{} + + for _, obj := range self.Objects { + ds := self.dsBySource[obj.SrcName] + if ds == nil { + ds = &PBDescriptorSet{} + + ds.PackageName = self.PackageName + ds.Codec = self.Codec + ds.SourceName = obj.SrcName + + self.dsBySource[obj.SrcName] = ds + } + + ds.AddObject(obj) + } + + for _, file := range self.dsBySource { + for _, st := range file.Structs() { + + for _, fd := range st.Fields { + + switch fd.Kind { + case model.Kind_Struct, model.Kind_Enum: + refTarget := self.ObjectByName(fd.Type) + if refTarget != nil { + file.addDependentSource(refTarget.SrcName) + } + } + } + } + } + + return self.dsBySource +} + func GenProtoDir(ctx *gen.Context) error { - rootDS := ctx.DescriptorSet + rootDS := &PBDescriptorSet{DescriptorSet: *ctx.DescriptorSet} var sb strings.Builder for srcName, ds := range rootDS.DescriptorSetBySource() { - ctx.DescriptorSet = ds - gen := codegen.NewCodeGen("dirproto"). RegisterTemplateFunc(codegen.UsefulFunc). RegisterTemplateFunc(UsefulFunc). - ParseTemplate(protoDirCodeTemplate, ctx) + ParseTemplate(protoDirCodeTemplate, ds) if gen.Error() != nil { fmt.Println(string(gen.Data())) diff --git a/model/descriptorset.go b/model/descriptorset.go index 349d134..d09d53d 100644 --- a/model/descriptorset.go +++ b/model/descriptorset.go @@ -4,21 +4,6 @@ type DescriptorSet struct { Objects []*Descriptor `json:",omitempty"` PackageName string Codec string - - DependentSource []string // 按文件管理的描述符取出时, 这个字段有效. 本文件依赖的其他source的symbiol - SourceName string // 按文件管理的描述符取出时, 这个字段有效. 表示本DescriptorSet的文件名 - dsBySource map[string]*DescriptorSet // 按文件名管理的描述符集合 -} - -func (self *DescriptorSet) Services() (ret []*Descriptor) { - - for _, o := range self.Objects { - if o.Kind == Kind_Service { - ret = append(ret, o) - } - } - - return } func (self *DescriptorSet) Structs() (ret []*Descriptor) { @@ -68,58 +53,3 @@ func (self *DescriptorSet) ObjectByName(name string) *Descriptor { func (self *DescriptorSet) AddObject(d *Descriptor) { self.Objects = append(self.Objects, d) } - -func (self *DescriptorSet) addDependentSource(name string) { - - if self.SourceName == name { - return - } - - for _, n := range self.DependentSource { - if n == name { - return - } - } - - self.DependentSource = append(self.DependentSource, name) -} - -func (self *DescriptorSet) DescriptorSetBySource() map[string]*DescriptorSet { - if self.dsBySource != nil { - return self.dsBySource - } - - self.dsBySource = map[string]*DescriptorSet{} - - for _, obj := range self.Objects { - ds := self.dsBySource[obj.SrcName] - if ds == nil { - ds = &DescriptorSet{ - PackageName: self.PackageName, - Codec: self.Codec, - SourceName: obj.SrcName, - } - self.dsBySource[obj.SrcName] = ds - } - - ds.AddObject(obj) - } - - for _, file := range self.dsBySource { - for _, st := range file.Structs() { - - for _, fd := range st.Fields { - - switch fd.Kind { - case Kind_Struct, Kind_Enum: - refTarget := self.ObjectByName(fd.Type) - if refTarget != nil { - file.addDependentSource(refTarget.SrcName) - } - } - } - } - } - - return self.dsBySource -} diff --git a/model/type.go b/model/type.go index 0fa2e2b..09ce59a 100644 --- a/model/type.go +++ b/model/type.go @@ -7,7 +7,6 @@ const ( Kind_Primitive = "primitive" Kind_Struct = "struct" Kind_Enum = "enum" - Kind_Service = "service" ) var SchemeType2Type = map[string]string{ diff --git a/parser/context.go b/parser/context.go index 486928b..b0df135 100644 --- a/parser/context.go +++ b/parser/context.go @@ -3,22 +3,33 @@ package parser import ( "github.com/davyxu/golexer" "github.com/davyxu/protoplus/model" + "strings" ) type Context struct { + + // 每个文件对应的属性 SourceName string *protoParser *model.DescriptorSet - *model.Descriptor + // 全局属性 + symbolPos map[interface{}]golexer.TokenPos + + sourceByName map[string]struct{} +} - *model.FieldDescriptor +func (self *Context) AddSource(sourceName string) bool { + lowerName := strings.ToLower(sourceName) + if _, ok := self.sourceByName[lowerName]; ok { + return false + } - *model.ServiceCall + self.sourceByName[lowerName] = struct{}{} - symbolPos map[interface{}]golexer.TokenPos + return true } func (self *Context) QuerySymbolPosString(v interface{}) string { @@ -31,13 +42,23 @@ func (self *Context) QuerySymbolPosString(v interface{}) string { } func (self *Context) AddSymbol(v interface{}, pos golexer.TokenPos) { - self.symbolPos[v] = pos } +func (self *Context) Clone(srcName string) *Context { + + return &Context{ + SourceName: srcName, + symbolPos: self.symbolPos, + sourceByName: self.sourceByName, + DescriptorSet: self.DescriptorSet, + } +} + func newContext() *Context { return &Context{ - symbolPos: make(map[interface{}]golexer.TokenPos), + symbolPos: map[interface{}]golexer.TokenPos{}, + sourceByName: map[string]struct{}{}, } } diff --git a/parser/entry.go b/parser/entry.go index f61da8b..3a9b296 100644 --- a/parser/entry.go +++ b/parser/entry.go @@ -2,7 +2,6 @@ package parser import ( "github.com/davyxu/protoplus/model" - "os" "strings" ) @@ -32,23 +31,10 @@ func ParseFileList(dset *model.DescriptorSet, filelist ...string) error { ctx.DescriptorSet = dset for _, filename := range filelist { - - ctx.SourceName = filename - - if file, err := os.Open(filename); err != nil { + err := parseFile(ctx, filename) + if err != nil { return err - } else { - - if err := rawParse(ctx, file); err != nil { - file.Close() - - return err - } - - file.Close() - } - } return checkAndFix(ctx) diff --git a/parser/enumfield.go b/parser/enumfield.go index 6f7f84c..86db954 100644 --- a/parser/enumfield.go +++ b/parser/enumfield.go @@ -2,18 +2,19 @@ package parser import ( "errors" + "github.com/davyxu/protoplus/model" ) -func parseEnumField(ctx *Context) { +func parseEnumField(ctx *Context, fd *model.FieldDescriptor) { // 注释 nameToken := ctx.RawToken() // 字段名 - ctx.FieldDescriptor.Name = ctx.Expect(Token_Identifier).Value() + fd.Name = ctx.Expect(Token_Identifier).Value() - if ctx.FieldNameExists(ctx.FieldDescriptor.Name) { - panic(errors.New("Duplicate field name: " + ctx.FieldDescriptor.Name)) + if fd.Descriptor.FieldNameExists(fd.Name) { + panic(errors.New("Duplicate field name: " + fd.Name)) } // 有等号 @@ -21,26 +22,26 @@ func parseEnumField(ctx *Context) { ctx.NextToken() // tag - ctx.FieldDescriptor.Tag = ctx.Expect(Token_Numeral).ToInt() + fd.Tag = ctx.Expect(Token_Numeral).ToInt() } else { // 没等号自动生成枚举序号 - if len(ctx.Fields) == 0 { - //fd.AutoTag = 0 - } else { - - // 按前面的序号+1 - //fd.AutoTag = d.MaxTag() + 1 - } + //if len(ctx.Fields) == 0 { + // //fd.AutoTag = 0 + //} else { + // + // // 按前面的序号+1 + // //fd.AutoTag = d.MaxTag() + 1 + //} } - ctx.FieldDescriptor.Comment = ctx.CommentGroupByLine(nameToken.Line()) + fd.Comment = ctx.CommentGroupByLine(nameToken.Line()) // 枚举值类型,始终为int32 - ctx.FieldDescriptor.ParseType("int32") + fd.ParseType("int32") - ctx.AddField(ctx.FieldDescriptor) + fd.Descriptor.AddField(fd) return } diff --git a/parser/parse_descriptor.go b/parser/parse_descriptor.go index b4c5242..24908e5 100644 --- a/parser/parse_descriptor.go +++ b/parser/parse_descriptor.go @@ -5,15 +5,14 @@ import ( "github.com/davyxu/protoplus/model" ) -func parseObject(ctx *Context) { +func parseObject(ctx *Context, d *model.Descriptor) { - dotToken := ctx.RawToken() + keywordToken := ctx.RawToken() ctx.NextToken() // 名字 - ctx.Descriptor.Name = ctx.Expect(Token_Identifier).Value() - ctx.SrcName = ctx.SourceName + d.Name = ctx.Expect(Token_Identifier).Value() // 名字上面的注释 @@ -22,24 +21,19 @@ func parseObject(ctx *Context) { for ctx.TokenID() != Token_CurlyBraceR { - switch ctx.Descriptor.Kind { + var fd model.FieldDescriptor + fd.Descriptor = d + + switch d.Kind { case model.Kind_Struct: - var fd model.FieldDescriptor - ctx.FieldDescriptor = &fd - parseStructField(ctx) + parseStructField(ctx, &fd) case model.Kind_Enum: - var fd model.FieldDescriptor - ctx.FieldDescriptor = &fd - parseEnumField(ctx) - case model.Kind_Service: - var sc model.ServiceCall - ctx.ServiceCall = &sc - parseSvcCallField(ctx) + parseEnumField(ctx, &fd) } // 读取字段后面的[Tag项] if ctx.TokenID() == Token_BracketL { - ctx.FieldDescriptor.TagSet = parseTagSet(ctx) + fd.TagSet = parseTagSet(ctx) } } @@ -48,14 +42,14 @@ func parseObject(ctx *Context) { // } - ctx.Descriptor.Comment = ctx.CommentGroupByLine(dotToken.Line()) + d.Comment = ctx.CommentGroupByLine(keywordToken.Line()) // 名字重复检查 - if ctx.DescriptorSet.ObjectNameExists(ctx.Descriptor.Name) { - panic(errors.New("Duplicate name: " + ctx.Descriptor.Name)) + if ctx.DescriptorSet.ObjectNameExists(d.Name) { + panic(errors.New("Duplicate name: " + d.Name)) } - ctx.AddObject(ctx.Descriptor) + ctx.AddObject(d) } diff --git a/parser/parse_descriptorset.go b/parser/parse_descriptorset.go index a71f606..fab9182 100644 --- a/parser/parse_descriptorset.go +++ b/parser/parse_descriptorset.go @@ -34,7 +34,7 @@ func rawParse(ctx *Context, reader io.Reader) (retErr error) { for ctx.TokenID() != Token_EOF { var d model.Descriptor - ctx.Descriptor = &d + d.SrcName = ctx.SourceName if ctx.TokenID() == Token_BracketL { d.TagSet = parseTagSet(ctx) @@ -43,13 +43,12 @@ func rawParse(ctx *Context, reader io.Reader) (retErr error) { switch ctx.TokenID() { case Token_Struct: d.Kind = model.Kind_Struct - parseObject(ctx) + parseObject(ctx, &d) case Token_Enum: d.Kind = model.Kind_Enum - parseObject(ctx) - case Token_Service: - d.Kind = model.Kind_Service - parseObject(ctx) + parseObject(ctx, &d) + case Token_Import: + parseImport(ctx) default: panic(errors.New("Unknown token: " + ctx.TokenValue())) } diff --git a/parser/parse_import.go b/parser/parse_import.go new file mode 100644 index 0000000..22c2d1f --- /dev/null +++ b/parser/parse_import.go @@ -0,0 +1,30 @@ +package parser + +import "os" + +func parseImport(ctx *Context) error { + + ctx.NextToken() + + fileName := ctx.Expect(Token_String).Value() + + return parseFile(ctx, fileName) +} + +func parseFile(ctx *Context, fileName string) error { + if !ctx.AddSource(fileName) { + return nil + } + + file, err := os.Open(fileName) + + if err != nil { + return err + } + + defer file.Close() + + newCtx := ctx.Clone(fileName) + + return rawParse(newCtx, file) +} diff --git a/parser/parser.go b/parser/parser.go index 0b76a48..f8bcb29 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -33,6 +33,7 @@ const ( Token_Assign // = Token_Service // service Token_RPC // rpc + Token_Import // import ) type protoParser struct { @@ -137,6 +138,7 @@ func newProtoParser(srcName string) *protoParser { l.AddMatcher(golexer.NewKeywordMatcher(Token_Struct, "struct")) l.AddMatcher(golexer.NewKeywordMatcher(Token_Service, "service")) l.AddMatcher(golexer.NewKeywordMatcher(Token_RPC, "rpc")) + l.AddMatcher(golexer.NewKeywordMatcher(Token_Import, "import")) l.AddMatcher(golexer.NewIdentifierMatcher(Token_Identifier)) diff --git a/parser/service.go b/parser/service.go deleted file mode 100644 index f75e489..0000000 --- a/parser/service.go +++ /dev/null @@ -1,44 +0,0 @@ -package parser - -import ( - "errors" -) - -func parseSvcCallField(ctx *Context) { - - // 注释 - nameToken := ctx.RawToken() - - if ctx.TokenID() == Token_RPC { - ctx.NextToken() - ctx.ServiceCall.IsRPC = true - } - - // 字段名 - ctx.ServiceCall.Name = ctx.Expect(Token_Identifier).Value() - - if ctx.CallNameExists(ctx.ServiceCall.Name) { - panic(errors.New("Duplicate svc call name: " + ctx.ServiceCall.Name)) - } - - tp := ctx.TokenPos() - - if ctx.TokenID() == Token_ParenL { - ctx.NextToken() - - ctx.ServiceCall.RequestName = ctx.Expect(Token_Identifier).Value() - ctx.Expect(Token_ParenR) - ctx.ServiceCall.RespondName = ctx.Expect(Token_Identifier).Value() - } else { - ctx.ServiceCall.RequestName = ctx.ServiceCall.Name + "REQ" - ctx.ServiceCall.RespondName = ctx.ServiceCall.Name + "ACK" - } - - ctx.ServiceCall.Comment = ctx.CommentGroupByLine(nameToken.Line()) - - ctx.AddSymbol(ctx.ServiceCall, tp) - - ctx.AddSvcCall(ctx.ServiceCall) - - return -} diff --git a/parser/structfield.go b/parser/structfield.go index 1f2c46e..588c52a 100644 --- a/parser/structfield.go +++ b/parser/structfield.go @@ -2,18 +2,19 @@ package parser import ( "errors" + "github.com/davyxu/protoplus/model" ) -func parseStructField(ctx *Context) { +func parseStructField(ctx *Context, fd *model.FieldDescriptor) { // 注释 nameToken := ctx.RawToken() // 字段名 - ctx.FieldDescriptor.Name = ctx.Expect(Token_Identifier).Value() + fd.Name = ctx.Expect(Token_Identifier).Value() - if ctx.FieldNameExists(ctx.FieldDescriptor.Name) { - panic(errors.New("Duplicate field name: " + ctx.FieldDescriptor.Name)) + if fd.Descriptor.FieldNameExists(fd.Name) { + panic(errors.New("Duplicate field name: " + fd.Name)) } tp := ctx.TokenPos() @@ -22,17 +23,17 @@ func parseStructField(ctx *Context) { if ctx.TokenID() == Token_BracketL { ctx.NextToken() ctx.Expect(Token_BracketR) - ctx.Repeatd = true + fd.Repeatd = true } // 延后在所有解析完后,检查TypeName是否合法,通过symbol还原位置并报错 - ctx.FieldDescriptor.ParseType(ctx.Expect(Token_Identifier).Value()) + fd.ParseType(ctx.Expect(Token_Identifier).Value()) - ctx.FieldDescriptor.Comment = ctx.CommentGroupByLine(nameToken.Line()) + fd.Comment = ctx.CommentGroupByLine(nameToken.Line()) - ctx.AddSymbol(ctx.FieldDescriptor, tp) + ctx.AddSymbol(fd, tp) - ctx.AddField(ctx.FieldDescriptor) + fd.Descriptor.AddField(fd) return } diff --git a/tests/Make.sh b/tests/Make.sh index 44bb5fc..54ae890 100644 --- a/tests/Make.sh +++ b/tests/Make.sh @@ -5,9 +5,11 @@ set -e go build -v -o=${GOPATH}/bin/protoplus github.com/davyxu/protoplus/cmd/protoplus # code.proto为输入文件 -${GOPATH}/bin/protoplus -ppgo_out=code_gen.go -package=tests code.proto -${GOPATH}/bin/protoplus -ppgoreg_out=reg_gen.go -package=tests code.proto -${GOPATH}/bin/protoplus -ppcs_out=../example/csharp/Example/ProtoGen.cs -package=Proto code.proto -${GOPATH}/bin/protoplus -ppcsreg_out=../example/csharp/Example/ProtoGenReg.cs -package=Proto code.proto -${GOPATH}/bin/protoplus -pbscheme_out=pb_gen.proto -package=proto code.proto -${GOPATH}/bin/protoplus -route_out=route.json -package=proto code.proto \ No newline at end of file +ProtoPlusBin=${GOPATH}/bin/protoplus + +${ProtoPlusBin} -ppgo_out=code_gen.go -package=tests filelist.proto +${ProtoPlusBin} -ppgoreg_out=reg_gen.go -package=tests filelist.proto +${ProtoPlusBin} -ppcs_out=../example/csharp/Example/ProtoGen.cs -package=Proto filelist.proto +${ProtoPlusBin} -ppcsreg_out=../example/csharp/Example/ProtoGenReg.cs -package=Proto filelist.proto +${ProtoPlusBin} -pbscheme_out=pb_gen.proto -package=proto filelist.proto +${ProtoPlusBin} -route_out=route.json -package=proto filelist.proto \ No newline at end of file diff --git a/tests/code_test.go b/tests/code_test.go index 73bd77d..b6b073e 100644 --- a/tests/code_test.go +++ b/tests/code_test.go @@ -131,12 +131,12 @@ func TestPtrField(t *testing.T) { } -func TestText(t *testing.T) { - - input := makeMyType() - - verifyText(t, &input) -} +//func TestText(t *testing.T) { +// +// input := makeMyType() +// +// verifyText(t, &input) +//} func TestFloat(t *testing.T) { diff --git a/tests/filelist.proto b/tests/filelist.proto new file mode 100644 index 0000000..2533fb1 --- /dev/null +++ b/tests/filelist.proto @@ -0,0 +1,2 @@ +import "type.proto" +import "msg.proto" \ No newline at end of file diff --git a/tests/msg.proto b/tests/msg.proto new file mode 100644 index 0000000..7654256 --- /dev/null +++ b/tests/msg.proto @@ -0,0 +1,11 @@ + +[AutoMsgID MsgDir: "client -> game"] +struct LoginREQ { + +} + +[AutoMsgID] +struct LoginACK { + +} + diff --git a/tests/pb_gen.proto b/tests/pb_gen.proto index d512b8a..454e333 100644 --- a/tests/pb_gen.proto +++ b/tests/pb_gen.proto @@ -2,7 +2,7 @@ // DO NOT EDIT! syntax = "proto3"; -option go_package= ".;proto"; +option go_package= "./;proto"; package proto; diff --git a/tests/reg_gen.go b/tests/reg_gen.go index efead79..cb15c4a 100644 --- a/tests/reg_gen.go +++ b/tests/reg_gen.go @@ -16,33 +16,38 @@ var ( func init() { cellmeta.Register(&cellmeta.Meta{ - Codec: cellcodec.MustGetByName("protoplus"), - Type: reflect.TypeOf((*MyTypeMini)(nil)).Elem(), - ID: 0, - New: func() interface{} { return &MyTypeMini{} }, + FullName: "tests.MyTypeMini", + ID: 0, + New: func() interface{} { return &MyTypeMini{} }, + Type: reflect.TypeOf((*MyTypeMini)(nil)).Elem(), + Codec: cellcodec.MustGetByName("protoplus"), }) cellmeta.Register(&cellmeta.Meta{ - Codec: cellcodec.MustGetByName("protoplus"), - Type: reflect.TypeOf((*MySubType)(nil)).Elem(), - ID: 0, - New: func() interface{} { return &MySubType{} }, + FullName: "tests.MySubType", + ID: 0, + New: func() interface{} { return &MySubType{} }, + Type: reflect.TypeOf((*MySubType)(nil)).Elem(), + Codec: cellcodec.MustGetByName("protoplus"), }) cellmeta.Register(&cellmeta.Meta{ - Codec: cellcodec.MustGetByName("protoplus"), - Type: reflect.TypeOf((*MyType)(nil)).Elem(), - ID: 0, - New: func() interface{} { return &MyType{} }, + FullName: "tests.MyType", + ID: 0, + New: func() interface{} { return &MyType{} }, + Type: reflect.TypeOf((*MyType)(nil)).Elem(), + Codec: cellcodec.MustGetByName("protoplus"), }) cellmeta.Register(&cellmeta.Meta{ - Codec: cellcodec.MustGetByName("protoplus"), - Type: reflect.TypeOf((*LoginREQ)(nil)).Elem(), - ID: 17076, - New: func() interface{} { return &LoginREQ{} }, + FullName: "tests.LoginREQ", + ID: 17076, + New: func() interface{} { return &LoginREQ{} }, + Type: reflect.TypeOf((*LoginREQ)(nil)).Elem(), + Codec: cellcodec.MustGetByName("protoplus"), }) cellmeta.Register(&cellmeta.Meta{ - Codec: cellcodec.MustGetByName("protoplus"), - Type: reflect.TypeOf((*LoginACK)(nil)).Elem(), - ID: 44443, - New: func() interface{} { return &LoginACK{} }, + FullName: "tests.LoginACK", + ID: 44443, + New: func() interface{} { return &LoginACK{} }, + Type: reflect.TypeOf((*LoginACK)(nil)).Elem(), + Codec: cellcodec.MustGetByName("protoplus"), }) } diff --git a/tests/code.proto b/tests/type.proto similarity index 86% rename from tests/code.proto rename to tests/type.proto index 978a15d..3f0ff54 100644 --- a/tests/code.proto +++ b/tests/type.proto @@ -93,24 +93,3 @@ struct MyType EnumSlice []MyEnum } - -[AutoMsgID MsgDir: "client -> game"] -struct LoginREQ { - -} - -[AutoMsgID] -struct LoginACK { - -} - - - - - -service login -{ - LoginStd(LoginREQ) LoginACK - rpc Login - -} \ No newline at end of file From 2d149a66ad6c482b5adf82627b83c21cf8513bc8 Mon Sep 17 00:00:00 2001 From: davyxu Date: Sun, 20 Jun 2021 20:16:17 +0800 Subject: [PATCH 29/39] =?UTF-8?q?=E5=A2=9E=E5=8A=A0build=20shell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ Make.sh | 34 ++++++++++++++++++++++++++++++++++ build/build.go | 15 +++++++++++++++ cmd/protoplus/main.go | 5 ++--- 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 Make.sh create mode 100644 build/build.go diff --git a/.gitignore b/.gitignore index 2dbb55a..7d73dc2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ example/csharp/Example/bin example/csharp/Example/obj api/csharp/ProtoPlus/obj api/csharp/ProtoPlus/bin +bin +*.gz diff --git a/Make.sh b/Make.sh new file mode 100644 index 0000000..8d84b8e --- /dev/null +++ b/Make.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +Version=2.0.0 + +export GOARCH=amd64 +BuildSourcePackage="github.com/davyxu/protoplus/build" +BinaryPackage="github.com/davyxu/protoplus/cmd/protoplus" +BinaryName="protoplus" + +BuildBinary() +{ + set -e + TargetDir=bin/"${1}" + mkdir -p "${TargetDir}" + export GOOS=${1} + BuildTime=$(date -R) + GitCommit=$(git rev-parse HEAD) + VersionString="-X \"${BuildSourcePackage}.BuildTime=${BuildTime}\" -X \"${BuildSourcePackage}.Version=${Version}\" -X \"${BuildSourcePackage}.GitCommit=${GitCommit}\"" + + go build -v -p 4 -o "${TargetDir}"/${BinaryName} -ldflags "${VersionString}" ${BinaryPackage} + PackageDir=$(pwd) + cd "${TargetDir}" + tar zcvf "${PackageDir}"/${BinaryName}-${Version}-"${1}"-x86_64.tar.gz ${BinaryName} + cd "${PackageDir}" +} + + + +if [[ ${1} == "" ]]; then + BuildBinary windows + BuildBinary linux + BuildBinary darwin +else + BuildBinary "${1}" +fi \ No newline at end of file diff --git a/build/build.go b/build/build.go new file mode 100644 index 0000000..e470cf3 --- /dev/null +++ b/build/build.go @@ -0,0 +1,15 @@ +package build + +import "fmt" + +var ( + Version string + GitCommit string + BuildTime string +) + +func Print() { + fmt.Println("Version: ", Version) + fmt.Println("GitCommit: ", GitCommit) + fmt.Println("BuildTime: ", BuildTime) +} diff --git a/cmd/protoplus/main.go b/cmd/protoplus/main.go index 8cf3b22..116ae39 100644 --- a/cmd/protoplus/main.go +++ b/cmd/protoplus/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "github.com/davyxu/protoplus/build" _ "github.com/davyxu/protoplus/codegen" "github.com/davyxu/protoplus/gen" "github.com/davyxu/protoplus/gen/pbscheme" @@ -24,8 +25,6 @@ var ( flagCodec = flag.String("codec", "protoplus", "default codec in register entry") ) -const Version = "2.0.0" - type GenEntry struct { name string usage string @@ -97,7 +96,7 @@ func main() { // 版本 if *flagVersion { - fmt.Println(Version) + build.Print() return } From 4b8b7f3a560a979aa09b1be5b6861a5ab5669d43 Mon Sep 17 00:00:00 2001 From: Davy xu Date: Fri, 30 Jul 2021 14:40:41 +0800 Subject: [PATCH 30/39] =?UTF-8?q?ulexer=E7=9B=B4=E6=8E=A5=E4=BB=8Eweb?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 6 +- go.sum | 281 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 267 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index e54cdb4..2470aae 100644 --- a/go.mod +++ b/go.mod @@ -5,12 +5,10 @@ go 1.12 require ( github.com/davyxu/cellnet v4.1.0+incompatible github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a - github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50 - github.com/stretchr/testify v1.6.1 + github.com/davyxu/ulexer v0.0.0-20200713054812-c9bb8db3521f + github.com/stretchr/testify v1.7.0 ) -replace github.com/davyxu/ulexer => ../ulexer - replace github.com/davyxu/cellnet => ../cellnet replace github.com/davyxu/x => ../x diff --git a/go.sum b/go.sum index 1c27dfb..d0a5d7f 100644 --- a/go.sum +++ b/go.sum @@ -1,32 +1,114 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= github.com/aws/aws-sdk-go v1.35.20/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a h1:VYps2zwgBJPNuLGLiPrR4w6ud6cJpwlBA1OOytrCpx4= github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a/go.mod h1:dCUDBJcBQ9/AOzz6++KvSetGgVf5zXphevt6LQvKy0A= github.com/davyxu/protoplus v0.1.0/go.mod h1:WzmNYPvYsyks3G81jCJ/vGY2ljs49qFMfCmXGwvxFLA= -github.com/davyxu/ulog v1.0.0/go.mod h1:kg3w8bI/8AOFX/NyNVHBAUBcvX7dDHrTfxdnk1sef18= +github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50 h1:LhNcRLxSnxoE6nfEEBdNib+r932OtQoea7ZUZNh27zs= +github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50/go.mod h1:0aiydOTmjo/kWslAOerN4nz9Mlia75fwDs9LXp+Ed1c= +github.com/davyxu/ulexer v0.0.0-20200713054812-c9bb8db3521f h1:SFjXhw0I9cfLbLtHFF/V7z1uTeBllXsahtQLoPmXWu4= +github.com/davyxu/ulexer v0.0.0-20200713054812-c9bb8db3521f/go.mod h1:0aiydOTmjo/kWslAOerN4nz9Mlia75fwDs9LXp+Ed1c= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= -github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= +github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= +github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg= +github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs= +github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk= +github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28= +github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo= +github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk= +github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw= +github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360= +github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg= +github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE= +github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8= +github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= +github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= +github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/consul/api v1.8.1/go.mod h1:sDjTOq0yUyv5G4h+BqSea7Fn6BU+XbolEz1952UB+mk= github.com/hashicorp/consul/sdk v0.7.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -46,16 +128,34 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY= github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= -github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= +github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.11.12/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= +github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= @@ -64,95 +164,244 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= +github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/olivere/elastic/v7 v7.0.22/go.mod h1:VDexNy9NjmtAkrjNoI7tImv7FR4tf5zUA3ickqu5Pc8= -github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/nats-io/jwt v1.2.2/go.mod h1:/xX356yQA6LuXI9xWW7mZNpxgF2mBmGecH+Fj34sP5Q= +github.com/nats-io/jwt/v2 v2.0.2/go.mod h1:VRP+deawSXyhNjXmxPCHskrR6Mq50BqpEI5SEcNiGlY= +github.com/nats-io/nats-server/v2 v2.3.2/go.mod h1:dUf7Cm5z5LbciFVwWx54owyCKm8x4/hL6p7rrljhLFY= +github.com/nats-io/nats.go v1.11.1-0.20210623165838-4b75fc59ae30/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= +github.com/nats-io/nkeys v0.2.0/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s= +github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4= +github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= +github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= +github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= +github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/smartystreets/assertions v1.1.1/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= -github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= -github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= -go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= +github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= +go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= +go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lLS/oTh0= +go.mongodb.org/mongo-driver v1.5.3/go.mod h1:gRXCHX4Jo7J0IJ1oDQyUxF7jfy19UfxniMS4xxMmUqw= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= From 1caf0eb4c29acf4f9b908c0d7f6bdcb5b6400a98 Mon Sep 17 00:00:00 2001 From: Davy xu Date: Mon, 2 Aug 2021 18:29:27 +0800 Subject: [PATCH 31/39] =?UTF-8?q?=E6=9B=B4=E6=96=B0mod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index d0a5d7f..f1e90ce 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a h1:VYps2zwgBJPNuLGLiPrR4w6ud6cJpwlBA1OOytrCpx4= github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a/go.mod h1:dCUDBJcBQ9/AOzz6++KvSetGgVf5zXphevt6LQvKy0A= github.com/davyxu/protoplus v0.1.0/go.mod h1:WzmNYPvYsyks3G81jCJ/vGY2ljs49qFMfCmXGwvxFLA= -github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50 h1:LhNcRLxSnxoE6nfEEBdNib+r932OtQoea7ZUZNh27zs= -github.com/davyxu/ulexer v0.0.0-20200705151509-86177890ec50/go.mod h1:0aiydOTmjo/kWslAOerN4nz9Mlia75fwDs9LXp+Ed1c= github.com/davyxu/ulexer v0.0.0-20200713054812-c9bb8db3521f h1:SFjXhw0I9cfLbLtHFF/V7z1uTeBllXsahtQLoPmXWu4= github.com/davyxu/ulexer v0.0.0-20200713054812-c9bb8db3521f/go.mod h1:0aiydOTmjo/kWslAOerN4nz9Mlia75fwDs9LXp+Ed1c= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= From 19cc05eb2caa393377e9671a5ea2fd33b99eec2d Mon Sep 17 00:00:00 2001 From: davyxu Date: Tue, 3 Aug 2021 22:54:29 +0800 Subject: [PATCH 32/39] =?UTF-8?q?filelist=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen/pbscheme/gen_dir.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gen/pbscheme/gen_dir.go b/gen/pbscheme/gen_dir.go index 31c96f4..683bb3f 100644 --- a/gen/pbscheme/gen_dir.go +++ b/gen/pbscheme/gen_dir.go @@ -7,6 +7,7 @@ import ( "github.com/davyxu/protoplus/model" "io/ioutil" "path/filepath" + "sort" "strings" ) @@ -105,8 +106,11 @@ func GenProtoDir(ctx *gen.Context) error { var sb strings.Builder + var srcNameList []string for srcName, ds := range rootDS.DescriptorSetBySource() { + srcNameList = append(srcNameList, srcName) + gen := codegen.NewCodeGen("dirproto"). RegisterTemplateFunc(codegen.UsefulFunc). RegisterTemplateFunc(UsefulFunc). @@ -119,14 +123,18 @@ func GenProtoDir(ctx *gen.Context) error { fullPathName := filepath.Join(ctx.OutputFileName, srcName) - fmt.Fprintf(&sb, "%s ", srcName) - err := gen.WriteOutputFile(fullPathName).Error() if err != nil { return err } } + sort.Strings(srcNameList) + + for _, d := range srcNameList { + fmt.Fprintf(&sb, "%s ", d) + } + err := ioutil.WriteFile(filepath.Join(ctx.OutputFileName, "filelist.txt"), []byte(sb.String()), 0666) return err From db7fce9ba28c362c6343fae462c9e5b1cd5f3838 Mon Sep 17 00:00:00 2001 From: davyxu Date: Sat, 7 Aug 2021 18:43:41 +0800 Subject: [PATCH 33/39] svcName->svcType --- gen/route/route.go | 2 +- model/route.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gen/route/route.go b/gen/route/route.go index bd28537..d8246b0 100644 --- a/gen/route/route.go +++ b/gen/route/route.go @@ -47,7 +47,7 @@ func genJsonData(ctx *gen.Context) ([]byte, error) { rt.Rule = append(rt.Rule, &model.RouteRule{ MsgName: ctx.PackageName + "." + d.Name, - SvcName: msgDir.To, + SvcType: msgDir.To, Router: msgDir.Mid, MsgID: msgID, }) diff --git a/model/route.go b/model/route.go index cdc7578..699893d 100644 --- a/model/route.go +++ b/model/route.go @@ -5,7 +5,7 @@ type RouteRule struct { MsgName string MsgID int - SvcName string + SvcType string Router string `json:",omitempty"` } From bfe239764b7d298325a2dce99d3ae4cbae1ddfb4 Mon Sep 17 00:00:00 2001 From: Davy xu Date: Wed, 11 Aug 2021 18:08:20 +0800 Subject: [PATCH 34/39] =?UTF-8?q?=E6=B6=88=E6=81=AFid=E7=94=9F=E6=88=90?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E8=80=A6=E5=90=88=E5=8C=85=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codegen/msgid.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/codegen/msgid.go b/codegen/msgid.go index ab630bf..2a041db 100644 --- a/codegen/msgid.go +++ b/codegen/msgid.go @@ -26,7 +26,8 @@ func StructMsgID(d *model.Descriptor) (msgid int) { } if msgid == 0 { - msgid = int(stringHash(strings.ToLower(d.DescriptorSet.PackageName + d.Name))) + // 这里不能引入packageName, 不同语言的package设置为不同, 造成消息id不一致 + msgid = int(stringHash(strings.ToLower(d.Name))) } return From 63e9fa5307dd54815d777f7a725010b819fe80da Mon Sep 17 00:00:00 2001 From: davyxu Date: Tue, 24 Aug 2021 14:52:36 +0800 Subject: [PATCH 35/39] =?UTF-8?q?=E9=80=82=E9=85=8Dseedorigin=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gen/ppcs/text.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gen/ppcs/text.go b/gen/ppcs/text.go index f7360e9..b65ac70 100644 --- a/gen/ppcs/text.go +++ b/gen/ppcs/text.go @@ -64,11 +64,22 @@ const RegTemplateText = `// Generated by github.com/davyxu/protoplus // DO NOT EDIT! using System; using System.Collections.Generic; -using ProtoPlus; #pragma warning disable 162 namespace {{.PackageName}} { + public class MetaInfo + { + public ushort ID; // 消息ID + public Type Type; // 消息类型 + + // 消息方向 + // 在proto中添加[MsgDir: "client -> game" ], 左边为源, 右边为目标 + public string SourcePeer; // 消息发起的源 + public string TargetPeer; // 消息的目标 + + public string Name; + } public static class MessageVisitor { From 2f39919ed0b0a70702adef00d6a39687875ec5bb Mon Sep 17 00:00:00 2001 From: davyxu Date: Tue, 14 Sep 2021 10:38:40 +0800 Subject: [PATCH 36/39] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 12 +++++++----- tests/code_test.go | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 2470aae..2e7d595 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,14 @@ module github.com/davyxu/protoplus go 1.12 require ( - github.com/davyxu/cellnet v4.1.0+incompatible + // 测试用 + //github.com/davyxu/cellnet v4.1.0+incompatible github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a github.com/davyxu/ulexer v0.0.0-20200713054812-c9bb8db3521f - github.com/stretchr/testify v1.7.0 + //github.com/stretchr/testify v1.7.0 ) -replace github.com/davyxu/cellnet => ../cellnet - -replace github.com/davyxu/x => ../x +replace ( +// github.com/davyxu/cellnet => ../cellnet +// github.com/davyxu/x => ../x +) \ No newline at end of file diff --git a/tests/code_test.go b/tests/code_test.go index b6b073e..a56cec8 100644 --- a/tests/code_test.go +++ b/tests/code_test.go @@ -2,9 +2,10 @@ package tests import ( "encoding/json" - _ "github.com/davyxu/cellnet/codec/protoplus" - "github.com/davyxu/protoplus/api/golang" "github.com/stretchr/testify/assert" + //_ "github.com/davyxu/cellnet/codec/protoplus" + "github.com/davyxu/protoplus/api/golang" + //"github.com/stretchr/testify/assert" "math" "reflect" "testing" From b132d964423c77dad486bc965279f68a9abdc1cd Mon Sep 17 00:00:00 2001 From: xubo Date: Thu, 2 Dec 2021 17:02:22 +0800 Subject: [PATCH 37/39] =?UTF-8?q?=E9=80=82=E9=85=8Dulexer=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/golang/api.go | 2 +- api/golang/text_parser.go | 56 +++++++++++++++++++++++++++++++++------ go.mod | 7 ++--- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/api/golang/api.go b/api/golang/api.go index 4808a16..f5d5b80 100644 --- a/api/golang/api.go +++ b/api/golang/api.go @@ -69,7 +69,7 @@ func UnmarshalText(s string, obj interface{}) error { return nil }) - err := lex.Run(func(lex *ulexer.Lexer) { + err := ulexer.Try(lex, func(lex *ulexer.Lexer) { parseStruct(lex, tObj, vObj, "") diff --git a/api/golang/text_parser.go b/api/golang/text_parser.go index 104b1d8..7abbaa8 100644 --- a/api/golang/text_parser.go +++ b/api/golang/text_parser.go @@ -3,8 +3,48 @@ package ppgo import ( "github.com/davyxu/ulexer" "reflect" + "strings" ) +type MatchAction func(tk *ulexer.Token) + +func selectAction(self *ulexer.Lexer, mlist []ulexer.Matcher, alist []MatchAction) { + + if len(mlist) != len(alist) { + panic("Matcher list should equal to Action list length") + } + + var hit bool + for index, m := range mlist { + tk := self.Read(m) + + if tk != ulexer.EmptyToken { + + action := alist[index] + if action != nil { + action(tk) + } + hit = true + break + } + } + + if !hit { + + var sb strings.Builder + + for index, m := range mlist { + if index > 0 { + sb.WriteString(" ") + } + sb.WriteString(m.TokenType()) + } + + self.Error("Expect %s", sb.String()) + } + +} + func detectEnd(lex *ulexer.Lexer, literal string) bool { if literal != "" { if tk := lex.Read(ulexer.Contain(literal)); tk.String() == literal { @@ -22,12 +62,12 @@ func parseStruct(lex *ulexer.Lexer, tObj reflect.Type, vObj reflect.Value, endLi break } - fieldTk := lex.Expect(ulexer.Identifier()) + fieldTk := ulexer.Expect(lex, ulexer.Identifier()) tField, fieldExists := tObj.FieldByName(fieldTk.String()) vField := vObj.FieldByName(fieldTk.String()) - lex.Expect(ulexer.Contain(":")) + ulexer.Expect(lex, ulexer.Contain(":")) parseMultiValue(lex, []ulexer.Matcher{ulexer.String(), ulexer.Numeral(), @@ -68,20 +108,20 @@ func parseStruct(lex *ulexer.Lexer, tObj reflect.Type, vObj reflect.Value, endLi } } -func parseMultiValue(lex *ulexer.Lexer, mlist []ulexer.Matcher, action ulexer.MatchAction) { +func parseMultiValue(lex *ulexer.Lexer, mlist []ulexer.Matcher, action MatchAction) { - alist := make([]ulexer.MatchAction, 0, len(mlist)) + alist := make([]MatchAction, 0, len(mlist)) for i := 0; i < len(mlist); i++ { alist = append(alist, action) } - lex.SelectAction( + selectAction(lex, mlist, alist, ) } -func parseElement(lex *ulexer.Lexer, endLiteral string, m ulexer.Matcher, onValue ulexer.MatchAction, onEnd func()) { +func parseElement(lex *ulexer.Lexer, endLiteral string, m ulexer.Matcher, onValue MatchAction, onEnd func()) { for { if detectEnd(lex, endLiteral) { @@ -89,7 +129,7 @@ func parseElement(lex *ulexer.Lexer, endLiteral string, m ulexer.Matcher, onValu break } - tk := lex.Expect(m) + tk := ulexer.Expect(lex, m) onValue(tk) } @@ -190,7 +230,7 @@ func parseArray(lex *ulexer.Lexer, tField reflect.Type, vObj reflect.Value, endL break } - lex.Expect(ulexer.Contain("{")) + ulexer.Expect(lex, ulexer.Contain("{")) element := reflect.New(tField.Elem()).Elem() diff --git a/go.mod b/go.mod index 2e7d595..d0dcb3f 100644 --- a/go.mod +++ b/go.mod @@ -4,13 +4,10 @@ go 1.12 require ( // 测试用 - //github.com/davyxu/cellnet v4.1.0+incompatible github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a github.com/davyxu/ulexer v0.0.0-20200713054812-c9bb8db3521f - //github.com/stretchr/testify v1.7.0 ) replace ( -// github.com/davyxu/cellnet => ../cellnet -// github.com/davyxu/x => ../x -) \ No newline at end of file + github.com/davyxu/ulexer => ../ulexer +) From 04aabac66da8a50d2c1191dda5243975d4f9cc6e Mon Sep 17 00:00:00 2001 From: xubo Date: Mon, 13 Dec 2021 13:57:46 +0800 Subject: [PATCH 38/39] =?UTF-8?q?=E9=80=82=E9=85=8Demptytoken=E7=A7=BB?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/golang/text_parser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/golang/text_parser.go b/api/golang/text_parser.go index 7abbaa8..b932ba8 100644 --- a/api/golang/text_parser.go +++ b/api/golang/text_parser.go @@ -18,7 +18,7 @@ func selectAction(self *ulexer.Lexer, mlist []ulexer.Matcher, alist []MatchActio for index, m := range mlist { tk := self.Read(m) - if tk != ulexer.EmptyToken { + if tk != nil { action := alist[index] if action != nil { From 289c68d02946342f6195126308c3d8548bd96c3e Mon Sep 17 00:00:00 2001 From: davyxu Date: Wed, 26 Jan 2022 21:06:33 +0800 Subject: [PATCH 39/39] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + example/csharp/Example/ProtoGenReg.cs | 17 +- go.mod | 5 +- go.sum | 398 +------------------------- tests/reg_gen.go | 53 ---- tests/route.json | 4 +- 6 files changed, 22 insertions(+), 456 deletions(-) delete mode 100644 tests/reg_gen.go diff --git a/.gitignore b/.gitignore index 7d73dc2..bdf4a86 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ api/csharp/ProtoPlus/obj api/csharp/ProtoPlus/bin bin *.gz +tests/reg_gen.go diff --git a/example/csharp/Example/ProtoGenReg.cs b/example/csharp/Example/ProtoGenReg.cs index 492078f..5d0d6f5 100644 --- a/example/csharp/Example/ProtoGenReg.cs +++ b/example/csharp/Example/ProtoGenReg.cs @@ -2,11 +2,22 @@ // DO NOT EDIT! using System; using System.Collections.Generic; -using ProtoPlus; #pragma warning disable 162 namespace Proto { + public class MetaInfo + { + public ushort ID; // 消息ID + public Type Type; // 消息类型 + + // 消息方向 + // 在proto中添加[MsgDir: "client -> game" ], 左边为源, 右边为目标 + public string SourcePeer; // 消息发起的源 + public string TargetPeer; // 消息的目标 + + public string Name; + } public static class MessageVisitor { @@ -36,14 +47,14 @@ public static void Visit(Action callback) callback(new MetaInfo { Type = typeof(LoginREQ), - ID = 45589, + ID = 225, SourcePeer = "client", TargetPeer = "game", }); callback(new MetaInfo { Type = typeof(LoginACK), - ID = 7420, + ID = 27592, SourcePeer = "", TargetPeer = "", }); diff --git a/go.mod b/go.mod index d0dcb3f..206c83b 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,7 @@ require ( // 测试用 github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a github.com/davyxu/ulexer v0.0.0-20200713054812-c9bb8db3521f + github.com/stretchr/testify v1.7.0 ) -replace ( - github.com/davyxu/ulexer => ../ulexer -) +replace github.com/davyxu/ulexer => ../ulexer diff --git a/go.sum b/go.sum index f1e90ce..7d4f742 100644 --- a/go.sum +++ b/go.sum @@ -1,405 +1,13 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= -github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= -github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= -github.com/aws/aws-sdk-go v1.35.20/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a h1:VYps2zwgBJPNuLGLiPrR4w6ud6cJpwlBA1OOytrCpx4= github.com/davyxu/golexer v0.1.1-0.20200202091144-a15ddde83f6a/go.mod h1:dCUDBJcBQ9/AOzz6++KvSetGgVf5zXphevt6LQvKy0A= -github.com/davyxu/protoplus v0.1.0/go.mod h1:WzmNYPvYsyks3G81jCJ/vGY2ljs49qFMfCmXGwvxFLA= -github.com/davyxu/ulexer v0.0.0-20200713054812-c9bb8db3521f h1:SFjXhw0I9cfLbLtHFF/V7z1uTeBllXsahtQLoPmXWu4= -github.com/davyxu/ulexer v0.0.0-20200713054812-c9bb8db3521f/go.mod h1:0aiydOTmjo/kWslAOerN4nz9Mlia75fwDs9LXp+Ed1c= -github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= -github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= -github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg= -github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= -github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= -github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs= -github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= -github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= -github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk= -github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28= -github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo= -github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk= -github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw= -github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360= -github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg= -github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE= -github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8= -github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= -github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= -github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= -github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= -github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= -github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= -github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/hashicorp/consul/api v1.8.1/go.mod h1:sDjTOq0yUyv5G4h+BqSea7Fn6BU+XbolEz1952UB+mk= -github.com/hashicorp/consul/sdk v0.7.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= -github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= -github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= -github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= -github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= -github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= -github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= -github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= -github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY= -github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= -github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= -github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= -github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= -github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= -github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= -github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/klauspost/compress v1.11.12/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= -github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= -github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= -github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= -github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= -github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= -github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/nats-io/jwt v1.2.2/go.mod h1:/xX356yQA6LuXI9xWW7mZNpxgF2mBmGecH+Fj34sP5Q= -github.com/nats-io/jwt/v2 v2.0.2/go.mod h1:VRP+deawSXyhNjXmxPCHskrR6Mq50BqpEI5SEcNiGlY= -github.com/nats-io/nats-server/v2 v2.3.2/go.mod h1:dUf7Cm5z5LbciFVwWx54owyCKm8x4/hL6p7rrljhLFY= -github.com/nats-io/nats.go v1.11.1-0.20210623165838-4b75fc59ae30/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= -github.com/nats-io/nkeys v0.2.0/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s= -github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= -github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= -github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= -github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= -github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= -github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= -github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= -github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= -github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= -github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= -github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= -github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= -github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= -go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= -go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lLS/oTh0= -go.mongodb.org/mongo-driver v1.5.3/go.mod h1:gRXCHX4Jo7J0IJ1oDQyUxF7jfy19UfxniMS4xxMmUqw= -go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= -golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= -google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= diff --git a/tests/reg_gen.go b/tests/reg_gen.go deleted file mode 100644 index cb15c4a..0000000 --- a/tests/reg_gen.go +++ /dev/null @@ -1,53 +0,0 @@ -// Generated by github.com/davyxu/protoplus -package tests - -import ( - "github.com/davyxu/cellnet/codec" - "github.com/davyxu/cellnet/meta" - "reflect" -) - -var ( - _ cellmeta.Meta - _ cellcodec.CodecRecycler - _ reflect.Kind -) - -func init() { - - cellmeta.Register(&cellmeta.Meta{ - FullName: "tests.MyTypeMini", - ID: 0, - New: func() interface{} { return &MyTypeMini{} }, - Type: reflect.TypeOf((*MyTypeMini)(nil)).Elem(), - Codec: cellcodec.MustGetByName("protoplus"), - }) - cellmeta.Register(&cellmeta.Meta{ - FullName: "tests.MySubType", - ID: 0, - New: func() interface{} { return &MySubType{} }, - Type: reflect.TypeOf((*MySubType)(nil)).Elem(), - Codec: cellcodec.MustGetByName("protoplus"), - }) - cellmeta.Register(&cellmeta.Meta{ - FullName: "tests.MyType", - ID: 0, - New: func() interface{} { return &MyType{} }, - Type: reflect.TypeOf((*MyType)(nil)).Elem(), - Codec: cellcodec.MustGetByName("protoplus"), - }) - cellmeta.Register(&cellmeta.Meta{ - FullName: "tests.LoginREQ", - ID: 17076, - New: func() interface{} { return &LoginREQ{} }, - Type: reflect.TypeOf((*LoginREQ)(nil)).Elem(), - Codec: cellcodec.MustGetByName("protoplus"), - }) - cellmeta.Register(&cellmeta.Meta{ - FullName: "tests.LoginACK", - ID: 44443, - New: func() interface{} { return &LoginACK{} }, - Type: reflect.TypeOf((*LoginACK)(nil)).Elem(), - Codec: cellcodec.MustGetByName("protoplus"), - }) -} diff --git a/tests/route.json b/tests/route.json index f3fb34d..dd486c8 100644 --- a/tests/route.json +++ b/tests/route.json @@ -2,8 +2,8 @@ "Rule": [ { "MsgName": "proto.LoginREQ", - "MsgID": 45589, - "SvcName": "game" + "MsgID": 225, + "SvcType": "game" } ] } \ No newline at end of file