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{