vendor: Update github.com/gogo/protobuf
Also tweaks the proto definitions: - [packed=false] on the block_indexes field to retain compat with v0.14.16 and earlier. - Uses the vendored protobuf package in include paths. And, "build.go setup" will install the vendored protoc-gen-gogofast. This should ensure that a proto rebuild isn't so dependent on whatever version of the compiler and package the developer has installed... GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3864
This commit is contained in:
committed by
Audrius Butkevicius
parent
4fb9c143ac
commit
987718baf8
22
vendor/github.com/gogo/protobuf/plugin/compare/compare.go
generated
vendored
22
vendor/github.com/gogo/protobuf/plugin/compare/compare.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -40,6 +42,7 @@ type plugin struct {
|
||||
fmtPkg generator.Single
|
||||
bytesPkg generator.Single
|
||||
sortkeysPkg generator.Single
|
||||
protoPkg generator.Single
|
||||
}
|
||||
|
||||
func NewPlugin() *plugin {
|
||||
@@ -59,6 +62,7 @@ func (p *plugin) Generate(file *generator.FileDescriptor) {
|
||||
p.fmtPkg = p.NewImport("fmt")
|
||||
p.bytesPkg = p.NewImport("bytes")
|
||||
p.sortkeysPkg = p.NewImport("github.com/gogo/protobuf/sortkeys")
|
||||
p.protoPkg = p.NewImport("github.com/gogo/protobuf/proto")
|
||||
|
||||
for _, msg := range file.Messages() {
|
||||
if msg.DescriptorProto.GetOptions().GetMapEntry() {
|
||||
@@ -431,17 +435,18 @@ func (p *plugin) generateMessage(file *generator.FileDescriptor, message *genera
|
||||
}
|
||||
}
|
||||
if message.DescriptorProto.HasExtension() {
|
||||
fieldname := "XXX_extensions"
|
||||
if gogoproto.HasExtensionsMap(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
p.P(`extkeys := make([]int32, 0, len(this.`, fieldname, `)+len(that1.`, fieldname, `))`)
|
||||
p.P(`for k, _ := range this.`, fieldname, ` {`)
|
||||
p.P(`thismap := `, p.protoPkg.Use(), `.GetUnsafeExtensionsMap(this)`)
|
||||
p.P(`thatmap := `, p.protoPkg.Use(), `.GetUnsafeExtensionsMap(that1)`)
|
||||
p.P(`extkeys := make([]int32, 0, len(thismap)+len(thatmap))`)
|
||||
p.P(`for k, _ := range thismap {`)
|
||||
p.In()
|
||||
p.P(`extkeys = append(extkeys, k)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`for k, _ := range that1.`, fieldname, ` {`)
|
||||
p.P(`for k, _ := range thatmap {`)
|
||||
p.In()
|
||||
p.P(`if _, ok := this.`, fieldname, `[k]; !ok {`)
|
||||
p.P(`if _, ok := thismap[k]; !ok {`)
|
||||
p.In()
|
||||
p.P(`extkeys = append(extkeys, k)`)
|
||||
p.Out()
|
||||
@@ -451,9 +456,9 @@ func (p *plugin) generateMessage(file *generator.FileDescriptor, message *genera
|
||||
p.P(p.sortkeysPkg.Use(), `.Int32s(extkeys)`)
|
||||
p.P(`for _, k := range extkeys {`)
|
||||
p.In()
|
||||
p.P(`if v, ok := this.`, fieldname, `[k]; ok {`)
|
||||
p.P(`if v, ok := thismap[k]; ok {`)
|
||||
p.In()
|
||||
p.P(`if v2, ok := that1.`, fieldname, `[k]; ok {`)
|
||||
p.P(`if v2, ok := thatmap[k]; ok {`)
|
||||
p.In()
|
||||
p.P(`if c := v.Compare(&v2); c != 0 {`)
|
||||
p.In()
|
||||
@@ -475,6 +480,7 @@ func (p *plugin) generateMessage(file *generator.FileDescriptor, message *genera
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else {
|
||||
fieldname := "XXX_extensions"
|
||||
p.P(`if c := `, p.bytesPkg.Use(), `.Compare(this.`, fieldname, `, that1.`, fieldname, `); c != 0 {`)
|
||||
p.In()
|
||||
p.P(`return c`)
|
||||
|
||||
8
vendor/github.com/gogo/protobuf/plugin/compare/comparetest.go
generated
vendored
8
vendor/github.com/gogo/protobuf/plugin/compare/comparetest.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -64,14 +66,14 @@ func (p *test) Generate(imports generator.PluginImports, file *generator.FileDes
|
||||
p.In()
|
||||
p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(`, timePkg.Use(), `.Now().UnixNano()))`)
|
||||
p.P(`p := NewPopulated`, ccTypeName, `(popr, false)`)
|
||||
p.P(`data, err := `, protoPkg.Use(), `.Marshal(p)`)
|
||||
p.P(`dAtA, err := `, protoPkg.Use(), `.Marshal(p)`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`panic(err)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`msg := &`, ccTypeName, `{}`)
|
||||
p.P(`if err := `, protoPkg.Use(), `.Unmarshal(data, msg); err != nil {`)
|
||||
p.P(`if err := `, protoPkg.Use(), `.Unmarshal(dAtA, msg); err != nil {`)
|
||||
p.In()
|
||||
p.P(`panic(err)`)
|
||||
p.Out()
|
||||
|
||||
4
vendor/github.com/gogo/protobuf/plugin/defaultcheck/defaultcheck.go
generated
vendored
4
vendor/github.com/gogo/protobuf/plugin/defaultcheck/defaultcheck.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
|
||||
4
vendor/github.com/gogo/protobuf/plugin/description/description.go
generated
vendored
4
vendor/github.com/gogo/protobuf/plugin/description/description.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
|
||||
4
vendor/github.com/gogo/protobuf/plugin/description/descriptiontest.go
generated
vendored
4
vendor/github.com/gogo/protobuf/plugin/description/descriptiontest.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
|
||||
4
vendor/github.com/gogo/protobuf/plugin/embedcheck/embedcheck.go
generated
vendored
4
vendor/github.com/gogo/protobuf/plugin/embedcheck/embedcheck.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
|
||||
6
vendor/github.com/gogo/protobuf/plugin/enumstringer/enumstringer.go
generated
vendored
6
vendor/github.com/gogo/protobuf/plugin/enumstringer/enumstringer.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -74,7 +76,7 @@ func (p *enumstringer) Generate(file *generator.FileDescriptor) {
|
||||
continue
|
||||
}
|
||||
if gogoproto.IsGoEnumStringer(file.FileDescriptorProto, enum.EnumDescriptorProto) {
|
||||
panic("old enum string method needs to be disabled, please use gogoproto.old_enum_stringer or gogoproto.old_enum_string_all and set it to false")
|
||||
panic("Go enum stringer conflicts with new enumstringer plugin: please use gogoproto.goproto_enum_stringer or gogoproto.goproto_enum_string_all and set it to false")
|
||||
}
|
||||
p.atleastOne = true
|
||||
ccTypeName := generator.CamelCaseSlice(enum.TypeName())
|
||||
|
||||
67
vendor/github.com/gogo/protobuf/plugin/equal/equal.go
generated
vendored
67
vendor/github.com/gogo/protobuf/plugin/equal/equal.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -145,12 +147,12 @@ and the following test code:
|
||||
func TestBVerboseEqual(t *testing8.T) {
|
||||
popr := math_rand8.New(math_rand8.NewSource(time8.Now().UnixNano()))
|
||||
p := NewPopulatedB(popr, false)
|
||||
data, err := github_com_gogo_protobuf_proto2.Marshal(p)
|
||||
dAtA, err := github_com_gogo_protobuf_proto2.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &B{}
|
||||
if err := github_com_gogo_protobuf_proto2.Unmarshal(data, msg); err != nil {
|
||||
if err := github_com_gogo_protobuf_proto2.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
@@ -173,6 +175,7 @@ type plugin struct {
|
||||
generator.PluginImports
|
||||
fmtPkg generator.Single
|
||||
bytesPkg generator.Single
|
||||
protoPkg generator.Single
|
||||
}
|
||||
|
||||
func NewPlugin() *plugin {
|
||||
@@ -191,6 +194,7 @@ func (p *plugin) Generate(file *generator.FileDescriptor) {
|
||||
p.PluginImports = generator.NewPluginImports(p.Generator)
|
||||
p.fmtPkg = p.NewImport("fmt")
|
||||
p.bytesPkg = p.NewImport("bytes")
|
||||
p.protoPkg = p.NewImport("github.com/gogo/protobuf/proto")
|
||||
|
||||
for _, msg := range file.Messages() {
|
||||
if msg.DescriptorProto.GetOptions().GetMapEntry() {
|
||||
@@ -302,9 +306,11 @@ func (p *plugin) generateField(file *generator.FileDescriptor, message *generato
|
||||
repeated := field.IsRepeated()
|
||||
ctype := gogoproto.IsCustomType(field)
|
||||
nullable := gogoproto.IsNullable(field)
|
||||
isDuration := gogoproto.IsStdDuration(field)
|
||||
isTimestamp := gogoproto.IsStdTime(field)
|
||||
// oneof := field.OneofIndex != nil
|
||||
if !repeated {
|
||||
if ctype {
|
||||
if ctype || isTimestamp {
|
||||
if nullable {
|
||||
p.P(`if that1.`, fieldname, ` == nil {`)
|
||||
p.In()
|
||||
@@ -330,6 +336,20 @@ func (p *plugin) generateField(file *generator.FileDescriptor, message *generato
|
||||
}
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if isDuration {
|
||||
if nullable {
|
||||
p.generateNullableField(fieldname, verbose)
|
||||
} else {
|
||||
p.P(`if this.`, fieldname, ` != that1.`, fieldname, `{`)
|
||||
}
|
||||
p.In()
|
||||
if verbose {
|
||||
p.P(`return `, p.fmtPkg.Use(), `.Errorf("`, fieldname, ` this(%v) Not Equal that(%v)", this.`, fieldname, `, that1.`, fieldname, `)`)
|
||||
} else {
|
||||
p.P(`return false`)
|
||||
}
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else {
|
||||
if field.IsMessage() || p.IsGroup(field) {
|
||||
if nullable {
|
||||
@@ -373,8 +393,20 @@ func (p *plugin) generateField(file *generator.FileDescriptor, message *generato
|
||||
p.P(`}`)
|
||||
p.P(`for i := range this.`, fieldname, ` {`)
|
||||
p.In()
|
||||
if ctype {
|
||||
if ctype && !p.IsMap(field) {
|
||||
p.P(`if !this.`, fieldname, `[i].Equal(that1.`, fieldname, `[i]) {`)
|
||||
} else if isTimestamp {
|
||||
if nullable {
|
||||
p.P(`if !this.`, fieldname, `[i].Equal(*that1.`, fieldname, `[i]) {`)
|
||||
} else {
|
||||
p.P(`if !this.`, fieldname, `[i].Equal(that1.`, fieldname, `[i]) {`)
|
||||
}
|
||||
} else if isDuration {
|
||||
if nullable {
|
||||
p.P(`if dthis, dthat := this.`, fieldname, `[i], that1.`, fieldname, `[i]; (dthis != nil && dthat != nil && *dthis != *dthat) || (dthis != nil && dthat == nil) || (dthis == nil && dthat != nil) {`)
|
||||
} else {
|
||||
p.P(`if this.`, fieldname, `[i] != that1.`, fieldname, `[i] {`)
|
||||
}
|
||||
} else {
|
||||
if p.IsMap(field) {
|
||||
m := p.GoMapType(nil, field)
|
||||
@@ -404,7 +436,15 @@ func (p *plugin) generateField(file *generator.FileDescriptor, message *generato
|
||||
}
|
||||
}
|
||||
} else if mapValue.IsBytes() {
|
||||
p.P(`if !`, p.bytesPkg.Use(), `.Equal(this.`, fieldname, `[i], that1.`, fieldname, `[i]) {`)
|
||||
if ctype {
|
||||
if nullable {
|
||||
p.P(`if !this.`, fieldname, `[i].Equal(*that1.`, fieldname, `[i]) { //nullable`)
|
||||
} else {
|
||||
p.P(`if !this.`, fieldname, `[i].Equal(that1.`, fieldname, `[i]) { //not nullable`)
|
||||
}
|
||||
} else {
|
||||
p.P(`if !`, p.bytesPkg.Use(), `.Equal(this.`, fieldname, `[i], that1.`, fieldname, `[i]) {`)
|
||||
}
|
||||
} else if mapValue.IsString() {
|
||||
p.P(`if this.`, fieldname, `[i] != that1.`, fieldname, `[i] {`)
|
||||
} else {
|
||||
@@ -495,16 +535,18 @@ func (p *plugin) generateMessage(file *generator.FileDescriptor, message *genera
|
||||
}
|
||||
}
|
||||
if message.DescriptorProto.HasExtension() {
|
||||
fieldname := "XXX_extensions"
|
||||
if gogoproto.HasExtensionsMap(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
p.P(`for k, v := range this.`, fieldname, ` {`)
|
||||
fieldname := "XXX_InternalExtensions"
|
||||
p.P(`thismap := `, p.protoPkg.Use(), `.GetUnsafeExtensionsMap(this)`)
|
||||
p.P(`thatmap := `, p.protoPkg.Use(), `.GetUnsafeExtensionsMap(that1)`)
|
||||
p.P(`for k, v := range thismap {`)
|
||||
p.In()
|
||||
p.P(`if v2, ok := that1.`, fieldname, `[k]; ok {`)
|
||||
p.P(`if v2, ok := thatmap[k]; ok {`)
|
||||
p.In()
|
||||
p.P(`if !v.Equal(&v2) {`)
|
||||
p.In()
|
||||
if verbose {
|
||||
p.P(`return `, p.fmtPkg.Use(), `.Errorf("`, fieldname, ` this[%v](%v) Not Equal that[%v](%v)", k, this.`, fieldname, `[k], k, that1.`, fieldname, `[k])`)
|
||||
p.P(`return `, p.fmtPkg.Use(), `.Errorf("`, fieldname, ` this[%v](%v) Not Equal that[%v](%v)", k, thismap[k], k, thatmap[k])`)
|
||||
} else {
|
||||
p.P(`return false`)
|
||||
}
|
||||
@@ -523,9 +565,9 @@ func (p *plugin) generateMessage(file *generator.FileDescriptor, message *genera
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
p.P(`for k, _ := range that1.`, fieldname, ` {`)
|
||||
p.P(`for k, _ := range thatmap {`)
|
||||
p.In()
|
||||
p.P(`if _, ok := this.`, fieldname, `[k]; !ok {`)
|
||||
p.P(`if _, ok := thismap[k]; !ok {`)
|
||||
p.In()
|
||||
if verbose {
|
||||
p.P(`return `, p.fmtPkg.Use(), `.Errorf("`, fieldname, `[%v] Not In this", k)`)
|
||||
@@ -537,6 +579,7 @@ func (p *plugin) generateMessage(file *generator.FileDescriptor, message *genera
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else {
|
||||
fieldname := "XXX_extensions"
|
||||
p.P(`if !`, p.bytesPkg.Use(), `.Equal(this.`, fieldname, `, that1.`, fieldname, `) {`)
|
||||
p.In()
|
||||
if verbose {
|
||||
|
||||
8
vendor/github.com/gogo/protobuf/plugin/equal/equaltest.go
generated
vendored
8
vendor/github.com/gogo/protobuf/plugin/equal/equaltest.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -64,14 +66,14 @@ func (p *test) Generate(imports generator.PluginImports, file *generator.FileDes
|
||||
p.In()
|
||||
p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(`, timePkg.Use(), `.Now().UnixNano()))`)
|
||||
p.P(`p := NewPopulated`, ccTypeName, `(popr, false)`)
|
||||
p.P(`data, err := `, protoPkg.Use(), `.Marshal(p)`)
|
||||
p.P(`dAtA, err := `, protoPkg.Use(), `.Marshal(p)`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`panic(err)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`msg := &`, ccTypeName, `{}`)
|
||||
p.P(`if err := `, protoPkg.Use(), `.Unmarshal(data, msg); err != nil {`)
|
||||
p.P(`if err := `, protoPkg.Use(), `.Unmarshal(dAtA, msg); err != nil {`)
|
||||
p.In()
|
||||
p.P(`panic(err)`)
|
||||
p.Out()
|
||||
|
||||
4
vendor/github.com/gogo/protobuf/plugin/face/face.go
generated
vendored
4
vendor/github.com/gogo/protobuf/plugin/face/face.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
|
||||
4
vendor/github.com/gogo/protobuf/plugin/face/facetest.go
generated
vendored
4
vendor/github.com/gogo/protobuf/plugin/face/facetest.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
|
||||
28
vendor/github.com/gogo/protobuf/plugin/gostring/gostring.go
generated
vendored
28
vendor/github.com/gogo/protobuf/plugin/gostring/gostring.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -106,6 +108,7 @@ type gostring struct {
|
||||
generator.PluginImports
|
||||
atleastOne bool
|
||||
localName string
|
||||
overwrite bool
|
||||
}
|
||||
|
||||
func NewGoString() *gostring {
|
||||
@@ -116,6 +119,10 @@ func (p *gostring) Name() string {
|
||||
return "gostring"
|
||||
}
|
||||
|
||||
func (p *gostring) Overwrite() {
|
||||
p.overwrite = true
|
||||
}
|
||||
|
||||
func (p *gostring) Init(g *generator.Generator) {
|
||||
p.Generator = g
|
||||
}
|
||||
@@ -139,7 +146,7 @@ func (p *gostring) Generate(file *generator.FileDescriptor) {
|
||||
sortKeysPkg := p.NewImport("github.com/gogo/protobuf/sortkeys")
|
||||
|
||||
for _, message := range file.Messages() {
|
||||
if !gogoproto.HasGoString(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
if !p.overwrite && !gogoproto.HasGoString(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
continue
|
||||
}
|
||||
if message.DescriptorProto.GetOptions().GetMapEntry() {
|
||||
@@ -255,15 +262,15 @@ func (p *gostring) Generate(file *generator.FileDescriptor) {
|
||||
}
|
||||
}
|
||||
if message.DescriptorProto.HasExtension() {
|
||||
p.P(`if this.XXX_extensions != nil {`)
|
||||
p.In()
|
||||
if gogoproto.HasExtensionsMap(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
p.P(`s = append(s, "XXX_extensions: " + extensionToGoString`, p.localName, `(this.XXX_extensions) + ",\n")`)
|
||||
p.P(`s = append(s, "XXX_InternalExtensions: " + extensionToGoString`, p.localName, `(this) + ",\n")`)
|
||||
} else {
|
||||
p.P(`if this.XXX_extensions != nil {`)
|
||||
p.In()
|
||||
p.P(`s = append(s, "XXX_extensions: " + `, fmtPkg.Use(), `.Sprintf("%#v", this.XXX_extensions) + ",\n")`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
}
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
}
|
||||
if gogoproto.HasUnrecognized(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
p.P(`if this.XXX_unrecognized != nil {`)
|
||||
@@ -331,10 +338,11 @@ func (p *gostring) Generate(file *generator.FileDescriptor) {
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
p.P(`func extensionToGoString`, p.localName, `(e map[int32]`, protoPkg.Use(), `.Extension) string {`)
|
||||
p.P(`func extensionToGoString`, p.localName, `(m `, protoPkg.Use(), `.Message) string {`)
|
||||
p.In()
|
||||
p.P(`e := `, protoPkg.Use(), `.GetUnsafeExtensionsMap(m)`)
|
||||
p.P(`if e == nil { return "nil" }`)
|
||||
p.P(`s := "map[int32]proto.Extension{"`)
|
||||
p.P(`s := "proto.NewUnsafeXXX_InternalExtensions(map[int32]proto.Extension{"`)
|
||||
p.P(`keys := make([]int, 0, len(e))`)
|
||||
p.P(`for k := range e {`)
|
||||
p.In()
|
||||
@@ -348,7 +356,7 @@ func (p *gostring) Generate(file *generator.FileDescriptor) {
|
||||
p.P(`ss = append(ss, `, strconvPkg.Use(), `.Itoa(k) + ": " + e[int32(k)].GoString())`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`s+=`, stringsPkg.Use(), `.Join(ss, ",") + "}"`)
|
||||
p.P(`s+=`, stringsPkg.Use(), `.Join(ss, ",") + "})"`)
|
||||
p.P(`return s`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
4
vendor/github.com/gogo/protobuf/plugin/gostring/gostringtest.go
generated
vendored
4
vendor/github.com/gogo/protobuf/plugin/gostring/gostringtest.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
|
||||
462
vendor/github.com/gogo/protobuf/plugin/grpc/grpc.go
generated
vendored
462
vendor/github.com/gogo/protobuf/plugin/grpc/grpc.go
generated
vendored
@@ -1,462 +0,0 @@
|
||||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// https://github.com/golang/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Package grpc outputs gRPC service descriptions in Go code.
|
||||
// It runs as a plugin for the Go protocol buffer compiler plugin.
|
||||
// It is linked in to protoc-gen-go.
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
pb "github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
|
||||
"github.com/gogo/protobuf/protoc-gen-gogo/generator"
|
||||
)
|
||||
|
||||
// generatedCodeVersion indicates a version of the generated code.
|
||||
// It is incremented whenever an incompatibility between the generated code and
|
||||
// the grpc package is introduced; the generated code references
|
||||
// a constant, grpc.SupportPackageIsVersionN (where N is generatedCodeVersion).
|
||||
const generatedCodeVersion = 2
|
||||
|
||||
// Paths for packages used by code generated in this file,
|
||||
// relative to the import_prefix of the generator.Generator.
|
||||
const (
|
||||
contextPkgPath = "golang.org/x/net/context"
|
||||
grpcPkgPath = "google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func init() {
|
||||
generator.RegisterPlugin(new(grpc))
|
||||
}
|
||||
|
||||
// grpc is an implementation of the Go protocol buffer compiler's
|
||||
// plugin architecture. It generates bindings for gRPC support.
|
||||
type grpc struct {
|
||||
gen *generator.Generator
|
||||
}
|
||||
|
||||
// Name returns the name of this plugin, "grpc".
|
||||
func (g *grpc) Name() string {
|
||||
return "grpc"
|
||||
}
|
||||
|
||||
// The names for packages imported in the generated code.
|
||||
// They may vary from the final path component of the import path
|
||||
// if the name is used by other packages.
|
||||
var (
|
||||
contextPkg string
|
||||
grpcPkg string
|
||||
)
|
||||
|
||||
// Init initializes the plugin.
|
||||
func (g *grpc) Init(gen *generator.Generator) {
|
||||
g.gen = gen
|
||||
contextPkg = generator.RegisterUniquePackageName("context", nil)
|
||||
grpcPkg = generator.RegisterUniquePackageName("grpc", nil)
|
||||
}
|
||||
|
||||
// Given a type name defined in a .proto, return its object.
|
||||
// Also record that we're using it, to guarantee the associated import.
|
||||
func (g *grpc) objectNamed(name string) generator.Object {
|
||||
g.gen.RecordTypeUse(name)
|
||||
return g.gen.ObjectNamed(name)
|
||||
}
|
||||
|
||||
// Given a type name defined in a .proto, return its name as we will print it.
|
||||
func (g *grpc) typeName(str string) string {
|
||||
return g.gen.TypeName(g.objectNamed(str))
|
||||
}
|
||||
|
||||
// P forwards to g.gen.P.
|
||||
func (g *grpc) P(args ...interface{}) { g.gen.P(args...) }
|
||||
|
||||
// Generate generates code for the services in the given file.
|
||||
func (g *grpc) Generate(file *generator.FileDescriptor) {
|
||||
if len(file.FileDescriptorProto.Service) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
g.P("// Reference imports to suppress errors if they are not otherwise used.")
|
||||
g.P("var _ ", contextPkg, ".Context")
|
||||
g.P("var _ ", grpcPkg, ".ClientConn")
|
||||
g.P()
|
||||
|
||||
// Assert version compatibility.
|
||||
g.P("// This is a compile-time assertion to ensure that this generated file")
|
||||
g.P("// is compatible with the grpc package it is being compiled against.")
|
||||
g.P("const _ = ", grpcPkg, ".SupportPackageIsVersion", generatedCodeVersion)
|
||||
g.P()
|
||||
|
||||
for i, service := range file.FileDescriptorProto.Service {
|
||||
g.generateService(file, service, i)
|
||||
}
|
||||
}
|
||||
|
||||
// GenerateImports generates the import declaration for this file.
|
||||
func (g *grpc) GenerateImports(file *generator.FileDescriptor) {
|
||||
if len(file.FileDescriptorProto.Service) == 0 {
|
||||
return
|
||||
}
|
||||
g.P("import (")
|
||||
g.P(contextPkg, " ", strconv.Quote(path.Join(g.gen.ImportPrefix, contextPkgPath)))
|
||||
g.P(grpcPkg, " ", strconv.Quote(path.Join(g.gen.ImportPrefix, grpcPkgPath)))
|
||||
g.P(")")
|
||||
g.P()
|
||||
}
|
||||
|
||||
// reservedClientName records whether a client name is reserved on the client side.
|
||||
var reservedClientName = map[string]bool{
|
||||
// TODO: do we need any in gRPC?
|
||||
}
|
||||
|
||||
func unexport(s string) string { return strings.ToLower(s[:1]) + s[1:] }
|
||||
|
||||
// generateService generates all the code for the named service.
|
||||
func (g *grpc) generateService(file *generator.FileDescriptor, service *pb.ServiceDescriptorProto, index int) {
|
||||
path := fmt.Sprintf("6,%d", index) // 6 means service.
|
||||
|
||||
origServName := service.GetName()
|
||||
fullServName := origServName
|
||||
if pkg := file.GetPackage(); pkg != "" {
|
||||
fullServName = pkg + "." + fullServName
|
||||
}
|
||||
servName := generator.CamelCase(origServName)
|
||||
|
||||
g.P()
|
||||
g.P("// Client API for ", servName, " service")
|
||||
g.P()
|
||||
|
||||
// Client interface.
|
||||
g.P("type ", servName, "Client interface {")
|
||||
for i, method := range service.Method {
|
||||
g.gen.PrintComments(fmt.Sprintf("%s,2,%d", path, i)) // 2 means method in a service.
|
||||
g.P(g.generateClientSignature(servName, method))
|
||||
}
|
||||
g.P("}")
|
||||
g.P()
|
||||
|
||||
// Client structure.
|
||||
g.P("type ", unexport(servName), "Client struct {")
|
||||
g.P("cc *", grpcPkg, ".ClientConn")
|
||||
g.P("}")
|
||||
g.P()
|
||||
|
||||
// NewClient factory.
|
||||
g.P("func New", servName, "Client (cc *", grpcPkg, ".ClientConn) ", servName, "Client {")
|
||||
g.P("return &", unexport(servName), "Client{cc}")
|
||||
g.P("}")
|
||||
g.P()
|
||||
|
||||
var methodIndex, streamIndex int
|
||||
serviceDescVar := "_" + servName + "_serviceDesc"
|
||||
// Client method implementations.
|
||||
for _, method := range service.Method {
|
||||
var descExpr string
|
||||
if !method.GetServerStreaming() && !method.GetClientStreaming() {
|
||||
// Unary RPC method
|
||||
descExpr = fmt.Sprintf("&%s.Methods[%d]", serviceDescVar, methodIndex)
|
||||
methodIndex++
|
||||
} else {
|
||||
// Streaming RPC method
|
||||
descExpr = fmt.Sprintf("&%s.Streams[%d]", serviceDescVar, streamIndex)
|
||||
streamIndex++
|
||||
}
|
||||
g.generateClientMethod(servName, fullServName, serviceDescVar, method, descExpr)
|
||||
}
|
||||
|
||||
g.P("// Server API for ", servName, " service")
|
||||
g.P()
|
||||
|
||||
// Server interface.
|
||||
serverType := servName + "Server"
|
||||
g.P("type ", serverType, " interface {")
|
||||
for i, method := range service.Method {
|
||||
g.gen.PrintComments(fmt.Sprintf("%s,2,%d", path, i)) // 2 means method in a service.
|
||||
g.P(g.generateServerSignature(servName, method))
|
||||
}
|
||||
g.P("}")
|
||||
g.P()
|
||||
|
||||
// Server registration.
|
||||
g.P("func Register", servName, "Server(s *", grpcPkg, ".Server, srv ", serverType, ") {")
|
||||
g.P("s.RegisterService(&", serviceDescVar, `, srv)`)
|
||||
g.P("}")
|
||||
g.P()
|
||||
|
||||
// Server handler implementations.
|
||||
var handlerNames []string
|
||||
for _, method := range service.Method {
|
||||
hname := g.generateServerMethod(servName, fullServName, method)
|
||||
handlerNames = append(handlerNames, hname)
|
||||
}
|
||||
|
||||
// Service descriptor.
|
||||
g.P("var ", serviceDescVar, " = ", grpcPkg, ".ServiceDesc {")
|
||||
g.P("ServiceName: ", strconv.Quote(fullServName), ",")
|
||||
g.P("HandlerType: (*", serverType, ")(nil),")
|
||||
g.P("Methods: []", grpcPkg, ".MethodDesc{")
|
||||
for i, method := range service.Method {
|
||||
if method.GetServerStreaming() || method.GetClientStreaming() {
|
||||
continue
|
||||
}
|
||||
g.P("{")
|
||||
g.P("MethodName: ", strconv.Quote(method.GetName()), ",")
|
||||
g.P("Handler: ", handlerNames[i], ",")
|
||||
g.P("},")
|
||||
}
|
||||
g.P("},")
|
||||
g.P("Streams: []", grpcPkg, ".StreamDesc{")
|
||||
for i, method := range service.Method {
|
||||
if !method.GetServerStreaming() && !method.GetClientStreaming() {
|
||||
continue
|
||||
}
|
||||
g.P("{")
|
||||
g.P("StreamName: ", strconv.Quote(method.GetName()), ",")
|
||||
g.P("Handler: ", handlerNames[i], ",")
|
||||
if method.GetServerStreaming() {
|
||||
g.P("ServerStreams: true,")
|
||||
}
|
||||
if method.GetClientStreaming() {
|
||||
g.P("ClientStreams: true,")
|
||||
}
|
||||
g.P("},")
|
||||
}
|
||||
g.P("},")
|
||||
g.P("}")
|
||||
g.P()
|
||||
}
|
||||
|
||||
// generateClientSignature returns the client-side signature for a method.
|
||||
func (g *grpc) generateClientSignature(servName string, method *pb.MethodDescriptorProto) string {
|
||||
origMethName := method.GetName()
|
||||
methName := generator.CamelCase(origMethName)
|
||||
if reservedClientName[methName] {
|
||||
methName += "_"
|
||||
}
|
||||
reqArg := ", in *" + g.typeName(method.GetInputType())
|
||||
if method.GetClientStreaming() {
|
||||
reqArg = ""
|
||||
}
|
||||
respName := "*" + g.typeName(method.GetOutputType())
|
||||
if method.GetServerStreaming() || method.GetClientStreaming() {
|
||||
respName = servName + "_" + generator.CamelCase(origMethName) + "Client"
|
||||
}
|
||||
return fmt.Sprintf("%s(ctx %s.Context%s, opts ...%s.CallOption) (%s, error)", methName, contextPkg, reqArg, grpcPkg, respName)
|
||||
}
|
||||
|
||||
func (g *grpc) generateClientMethod(servName, fullServName, serviceDescVar string, method *pb.MethodDescriptorProto, descExpr string) {
|
||||
sname := fmt.Sprintf("/%s/%s", fullServName, method.GetName())
|
||||
methName := generator.CamelCase(method.GetName())
|
||||
inType := g.typeName(method.GetInputType())
|
||||
outType := g.typeName(method.GetOutputType())
|
||||
|
||||
g.P("func (c *", unexport(servName), "Client) ", g.generateClientSignature(servName, method), "{")
|
||||
if !method.GetServerStreaming() && !method.GetClientStreaming() {
|
||||
g.P("out := new(", outType, ")")
|
||||
// TODO: Pass descExpr to Invoke.
|
||||
g.P("err := ", grpcPkg, `.Invoke(ctx, "`, sname, `", in, out, c.cc, opts...)`)
|
||||
g.P("if err != nil { return nil, err }")
|
||||
g.P("return out, nil")
|
||||
g.P("}")
|
||||
g.P()
|
||||
return
|
||||
}
|
||||
streamType := unexport(servName) + methName + "Client"
|
||||
g.P("stream, err := ", grpcPkg, ".NewClientStream(ctx, ", descExpr, `, c.cc, "`, sname, `", opts...)`)
|
||||
g.P("if err != nil { return nil, err }")
|
||||
g.P("x := &", streamType, "{stream}")
|
||||
if !method.GetClientStreaming() {
|
||||
g.P("if err := x.ClientStream.SendMsg(in); err != nil { return nil, err }")
|
||||
g.P("if err := x.ClientStream.CloseSend(); err != nil { return nil, err }")
|
||||
}
|
||||
g.P("return x, nil")
|
||||
g.P("}")
|
||||
g.P()
|
||||
|
||||
genSend := method.GetClientStreaming()
|
||||
genRecv := method.GetServerStreaming()
|
||||
genCloseAndRecv := !method.GetServerStreaming()
|
||||
|
||||
// Stream auxiliary types and methods.
|
||||
g.P("type ", servName, "_", methName, "Client interface {")
|
||||
if genSend {
|
||||
g.P("Send(*", inType, ") error")
|
||||
}
|
||||
if genRecv {
|
||||
g.P("Recv() (*", outType, ", error)")
|
||||
}
|
||||
if genCloseAndRecv {
|
||||
g.P("CloseAndRecv() (*", outType, ", error)")
|
||||
}
|
||||
g.P(grpcPkg, ".ClientStream")
|
||||
g.P("}")
|
||||
g.P()
|
||||
|
||||
g.P("type ", streamType, " struct {")
|
||||
g.P(grpcPkg, ".ClientStream")
|
||||
g.P("}")
|
||||
g.P()
|
||||
|
||||
if genSend {
|
||||
g.P("func (x *", streamType, ") Send(m *", inType, ") error {")
|
||||
g.P("return x.ClientStream.SendMsg(m)")
|
||||
g.P("}")
|
||||
g.P()
|
||||
}
|
||||
if genRecv {
|
||||
g.P("func (x *", streamType, ") Recv() (*", outType, ", error) {")
|
||||
g.P("m := new(", outType, ")")
|
||||
g.P("if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err }")
|
||||
g.P("return m, nil")
|
||||
g.P("}")
|
||||
g.P()
|
||||
}
|
||||
if genCloseAndRecv {
|
||||
g.P("func (x *", streamType, ") CloseAndRecv() (*", outType, ", error) {")
|
||||
g.P("if err := x.ClientStream.CloseSend(); err != nil { return nil, err }")
|
||||
g.P("m := new(", outType, ")")
|
||||
g.P("if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err }")
|
||||
g.P("return m, nil")
|
||||
g.P("}")
|
||||
g.P()
|
||||
}
|
||||
}
|
||||
|
||||
// generateServerSignature returns the server-side signature for a method.
|
||||
func (g *grpc) generateServerSignature(servName string, method *pb.MethodDescriptorProto) string {
|
||||
origMethName := method.GetName()
|
||||
methName := generator.CamelCase(origMethName)
|
||||
if reservedClientName[methName] {
|
||||
methName += "_"
|
||||
}
|
||||
|
||||
var reqArgs []string
|
||||
ret := "error"
|
||||
if !method.GetServerStreaming() && !method.GetClientStreaming() {
|
||||
reqArgs = append(reqArgs, contextPkg+".Context")
|
||||
ret = "(*" + g.typeName(method.GetOutputType()) + ", error)"
|
||||
}
|
||||
if !method.GetClientStreaming() {
|
||||
reqArgs = append(reqArgs, "*"+g.typeName(method.GetInputType()))
|
||||
}
|
||||
if method.GetServerStreaming() || method.GetClientStreaming() {
|
||||
reqArgs = append(reqArgs, servName+"_"+generator.CamelCase(origMethName)+"Server")
|
||||
}
|
||||
|
||||
return methName + "(" + strings.Join(reqArgs, ", ") + ") " + ret
|
||||
}
|
||||
|
||||
func (g *grpc) generateServerMethod(servName, fullServName string, method *pb.MethodDescriptorProto) string {
|
||||
methName := generator.CamelCase(method.GetName())
|
||||
hname := fmt.Sprintf("_%s_%s_Handler", servName, methName)
|
||||
inType := g.typeName(method.GetInputType())
|
||||
outType := g.typeName(method.GetOutputType())
|
||||
|
||||
if !method.GetServerStreaming() && !method.GetClientStreaming() {
|
||||
g.P("func ", hname, "(srv interface{}, ctx ", contextPkg, ".Context, dec func(interface{}) error, interceptor ", grpcPkg, ".UnaryServerInterceptor) (interface{}, error) {")
|
||||
g.P("in := new(", inType, ")")
|
||||
g.P("if err := dec(in); err != nil { return nil, err }")
|
||||
g.P("if interceptor == nil { return srv.(", servName, "Server).", methName, "(ctx, in) }")
|
||||
g.P("info := &", grpcPkg, ".UnaryServerInfo{")
|
||||
g.P("Server: srv,")
|
||||
g.P("FullMethod: ", strconv.Quote(fmt.Sprintf("/%s/%s", fullServName, methName)), ",")
|
||||
g.P("}")
|
||||
g.P("handler := func(ctx ", contextPkg, ".Context, req interface{}) (interface{}, error) {")
|
||||
g.P("return srv.(", servName, "Server).", methName, "(ctx, req.(*", inType, "))")
|
||||
g.P("}")
|
||||
g.P("return interceptor(ctx, in, info, handler)")
|
||||
g.P("}")
|
||||
g.P()
|
||||
return hname
|
||||
}
|
||||
streamType := unexport(servName) + methName + "Server"
|
||||
g.P("func ", hname, "(srv interface{}, stream ", grpcPkg, ".ServerStream) error {")
|
||||
if !method.GetClientStreaming() {
|
||||
g.P("m := new(", inType, ")")
|
||||
g.P("if err := stream.RecvMsg(m); err != nil { return err }")
|
||||
g.P("return srv.(", servName, "Server).", methName, "(m, &", streamType, "{stream})")
|
||||
} else {
|
||||
g.P("return srv.(", servName, "Server).", methName, "(&", streamType, "{stream})")
|
||||
}
|
||||
g.P("}")
|
||||
g.P()
|
||||
|
||||
genSend := method.GetServerStreaming()
|
||||
genSendAndClose := !method.GetServerStreaming()
|
||||
genRecv := method.GetClientStreaming()
|
||||
|
||||
// Stream auxiliary types and methods.
|
||||
g.P("type ", servName, "_", methName, "Server interface {")
|
||||
if genSend {
|
||||
g.P("Send(*", outType, ") error")
|
||||
}
|
||||
if genSendAndClose {
|
||||
g.P("SendAndClose(*", outType, ") error")
|
||||
}
|
||||
if genRecv {
|
||||
g.P("Recv() (*", inType, ", error)")
|
||||
}
|
||||
g.P(grpcPkg, ".ServerStream")
|
||||
g.P("}")
|
||||
g.P()
|
||||
|
||||
g.P("type ", streamType, " struct {")
|
||||
g.P(grpcPkg, ".ServerStream")
|
||||
g.P("}")
|
||||
g.P()
|
||||
|
||||
if genSend {
|
||||
g.P("func (x *", streamType, ") Send(m *", outType, ") error {")
|
||||
g.P("return x.ServerStream.SendMsg(m)")
|
||||
g.P("}")
|
||||
g.P()
|
||||
}
|
||||
if genSendAndClose {
|
||||
g.P("func (x *", streamType, ") SendAndClose(m *", outType, ") error {")
|
||||
g.P("return x.ServerStream.SendMsg(m)")
|
||||
g.P("}")
|
||||
g.P()
|
||||
}
|
||||
if genRecv {
|
||||
g.P("func (x *", streamType, ") Recv() (*", inType, ", error) {")
|
||||
g.P("m := new(", inType, ")")
|
||||
g.P("if err := x.ServerStream.RecvMsg(m); err != nil { return nil, err }")
|
||||
g.P("return m, nil")
|
||||
g.P("}")
|
||||
g.P()
|
||||
}
|
||||
|
||||
return hname
|
||||
}
|
||||
350
vendor/github.com/gogo/protobuf/plugin/marshalto/marshalto.go
generated
vendored
350
vendor/github.com/gogo/protobuf/plugin/marshalto/marshalto.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -73,35 +75,35 @@ message B {
|
||||
|
||||
given to the marshalto plugin, will generate the following code:
|
||||
|
||||
func (m *B) Marshal() (data []byte, err error) {
|
||||
func (m *B) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
data = make([]byte, size)
|
||||
n, err := m.MarshalTo(data)
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalTo(dAtA)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data[:n], nil
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *B) MarshalTo(data []byte) (int, error) {
|
||||
func (m *B) MarshalTo(dAtA []byte) (int, error) {
|
||||
var i int
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
data[i] = 0xa
|
||||
dAtA[i] = 0xa
|
||||
i++
|
||||
i = encodeVarintExample(data, i, uint64(m.A.Size()))
|
||||
n2, err := m.A.MarshalTo(data[i:])
|
||||
i = encodeVarintExample(dAtA, i, uint64(m.A.Size()))
|
||||
n2, err := m.A.MarshalTo(dAtA[i:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i += n2
|
||||
if len(m.G) > 0 {
|
||||
for _, msg := range m.G {
|
||||
data[i] = 0x12
|
||||
dAtA[i] = 0x12
|
||||
i++
|
||||
i = encodeVarintExample(data, i, uint64(msg.Size()))
|
||||
n, err := msg.MarshalTo(data[i:])
|
||||
i = encodeVarintExample(dAtA, i, uint64(msg.Size()))
|
||||
n, err := msg.MarshalTo(dAtA[i:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -109,7 +111,7 @@ given to the marshalto plugin, will generate the following code:
|
||||
}
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
i += copy(data[i:], m.XXX_unrecognized)
|
||||
i += copy(dAtA[i:], m.XXX_unrecognized)
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
@@ -175,6 +177,7 @@ type marshalto struct {
|
||||
protoPkg generator.Single
|
||||
sortKeysPkg generator.Single
|
||||
mathPkg generator.Single
|
||||
typesPkg generator.Single
|
||||
localName string
|
||||
unsafe bool
|
||||
}
|
||||
@@ -199,66 +202,66 @@ func (p *marshalto) Init(g *generator.Generator) {
|
||||
}
|
||||
|
||||
func (p *marshalto) callFixed64(varName ...string) {
|
||||
p.P(`i = encodeFixed64`, p.localName, `(data, i, uint64(`, strings.Join(varName, ""), `))`)
|
||||
p.P(`i = encodeFixed64`, p.localName, `(dAtA, i, uint64(`, strings.Join(varName, ""), `))`)
|
||||
}
|
||||
|
||||
func (p *marshalto) callFixed32(varName ...string) {
|
||||
p.P(`i = encodeFixed32`, p.localName, `(data, i, uint32(`, strings.Join(varName, ""), `))`)
|
||||
p.P(`i = encodeFixed32`, p.localName, `(dAtA, i, uint32(`, strings.Join(varName, ""), `))`)
|
||||
}
|
||||
|
||||
func (p *marshalto) callVarint(varName ...string) {
|
||||
p.P(`i = encodeVarint`, p.localName, `(data, i, uint64(`, strings.Join(varName, ""), `))`)
|
||||
p.P(`i = encodeVarint`, p.localName, `(dAtA, i, uint64(`, strings.Join(varName, ""), `))`)
|
||||
}
|
||||
|
||||
func (p *marshalto) encodeVarint(varName string) {
|
||||
p.P(`for `, varName, ` >= 1<<7 {`)
|
||||
p.In()
|
||||
p.P(`data[i] = uint8(uint64(`, varName, `)&0x7f|0x80)`)
|
||||
p.P(`dAtA[i] = uint8(uint64(`, varName, `)&0x7f|0x80)`)
|
||||
p.P(varName, ` >>= 7`)
|
||||
p.P(`i++`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`data[i] = uint8(`, varName, `)`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, `)`)
|
||||
p.P(`i++`)
|
||||
}
|
||||
|
||||
func (p *marshalto) encodeFixed64(varName string) {
|
||||
p.P(`data[i] = uint8(`, varName, `)`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, `)`)
|
||||
p.P(`i++`)
|
||||
p.P(`data[i] = uint8(`, varName, ` >> 8)`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 8)`)
|
||||
p.P(`i++`)
|
||||
p.P(`data[i] = uint8(`, varName, ` >> 16)`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 16)`)
|
||||
p.P(`i++`)
|
||||
p.P(`data[i] = uint8(`, varName, ` >> 24)`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 24)`)
|
||||
p.P(`i++`)
|
||||
p.P(`data[i] = uint8(`, varName, ` >> 32)`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 32)`)
|
||||
p.P(`i++`)
|
||||
p.P(`data[i] = uint8(`, varName, ` >> 40)`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 40)`)
|
||||
p.P(`i++`)
|
||||
p.P(`data[i] = uint8(`, varName, ` >> 48)`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 48)`)
|
||||
p.P(`i++`)
|
||||
p.P(`data[i] = uint8(`, varName, ` >> 56)`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 56)`)
|
||||
p.P(`i++`)
|
||||
}
|
||||
|
||||
func (p *marshalto) unsafeFixed64(varName string, someType string) {
|
||||
p.P(`*(*`, someType, `)(`, p.unsafePkg.Use(), `.Pointer(&data[i])) = `, varName)
|
||||
p.P(`*(*`, someType, `)(`, p.unsafePkg.Use(), `.Pointer(&dAtA[i])) = `, varName)
|
||||
p.P(`i+=8`)
|
||||
}
|
||||
|
||||
func (p *marshalto) encodeFixed32(varName string) {
|
||||
p.P(`data[i] = uint8(`, varName, `)`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, `)`)
|
||||
p.P(`i++`)
|
||||
p.P(`data[i] = uint8(`, varName, ` >> 8)`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 8)`)
|
||||
p.P(`i++`)
|
||||
p.P(`data[i] = uint8(`, varName, ` >> 16)`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 16)`)
|
||||
p.P(`i++`)
|
||||
p.P(`data[i] = uint8(`, varName, ` >> 24)`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 24)`)
|
||||
p.P(`i++`)
|
||||
}
|
||||
|
||||
func (p *marshalto) unsafeFixed32(varName string, someType string) {
|
||||
p.P(`*(*`, someType, `)(`, p.unsafePkg.Use(), `.Pointer(&data[i])) = `, varName)
|
||||
p.P(`*(*`, someType, `)(`, p.unsafePkg.Use(), `.Pointer(&dAtA[i])) = `, varName)
|
||||
p.P(`i+=4`)
|
||||
}
|
||||
|
||||
@@ -272,7 +275,7 @@ func (p *marshalto) encodeKey(fieldNumber int32, wireType int) {
|
||||
}
|
||||
keybuf = append(keybuf, uint8(x))
|
||||
for _, b := range keybuf {
|
||||
p.P(`data[i] = `, fmt.Sprintf("%#v", b))
|
||||
p.P(`dAtA[i] = `, fmt.Sprintf("%#v", b))
|
||||
p.P(`i++`)
|
||||
}
|
||||
}
|
||||
@@ -307,8 +310,8 @@ func wireToType(wire string) int {
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func (p *marshalto) mapField(numGen NumGen, fieldTyp descriptor.FieldDescriptorProto_Type, varName string, protoSizer bool) {
|
||||
switch fieldTyp {
|
||||
func (p *marshalto) mapField(numGen NumGen, field *descriptor.FieldDescriptorProto, kvField *descriptor.FieldDescriptorProto, varName string, protoSizer bool) {
|
||||
switch kvField.GetType() {
|
||||
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
|
||||
p.callFixed64(p.mathPkg.Use(), `.Float64bits(float64(`, varName, `))`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
|
||||
@@ -328,29 +331,47 @@ func (p *marshalto) mapField(numGen NumGen, fieldTyp descriptor.FieldDescriptorP
|
||||
case descriptor.FieldDescriptorProto_TYPE_BOOL:
|
||||
p.P(`if `, varName, ` {`)
|
||||
p.In()
|
||||
p.P(`data[i] = 1`)
|
||||
p.P(`dAtA[i] = 1`)
|
||||
p.Out()
|
||||
p.P(`} else {`)
|
||||
p.In()
|
||||
p.P(`data[i] = 0`)
|
||||
p.P(`dAtA[i] = 0`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`i++`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_STRING,
|
||||
descriptor.FieldDescriptorProto_TYPE_BYTES:
|
||||
p.callVarint(`len(`, varName, `)`)
|
||||
p.P(`i+=copy(data[i:], `, varName, `)`)
|
||||
if gogoproto.IsCustomType(field) && kvField.IsBytes() {
|
||||
p.callVarint(varName, `.Size()`)
|
||||
p.P(`n`, numGen.Next(), `, err := `, varName, `.MarshalTo(dAtA[i:])`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`return 0, err`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`i+=n`, numGen.Current())
|
||||
} else {
|
||||
p.callVarint(`len(`, varName, `)`)
|
||||
p.P(`i+=copy(dAtA[i:], `, varName, `)`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_SINT32:
|
||||
p.callVarint(`(uint32(`, varName, `) << 1) ^ uint32((`, varName, ` >> 31))`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_SINT64:
|
||||
p.callVarint(`(uint64(`, varName, `) << 1) ^ uint64((`, varName, ` >> 63))`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
|
||||
if protoSizer {
|
||||
if gogoproto.IsStdTime(field) {
|
||||
p.callVarint(p.typesPkg.Use(), `.SizeOfStdTime(*`, varName, `)`)
|
||||
p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdTimeMarshalTo(*`, varName, `, dAtA[i:])`)
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
p.callVarint(p.typesPkg.Use(), `.SizeOfStdDuration(*`, varName, `)`)
|
||||
p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdDurationMarshalTo(*`, varName, `, dAtA[i:])`)
|
||||
} else if protoSizer {
|
||||
p.callVarint(varName, `.ProtoSize()`)
|
||||
p.P(`n`, numGen.Next(), `, err := `, varName, `.MarshalTo(dAtA[i:])`)
|
||||
} else {
|
||||
p.callVarint(varName, `.Size()`)
|
||||
p.P(`n`, numGen.Next(), `, err := `, varName, `.MarshalTo(dAtA[i:])`)
|
||||
}
|
||||
p.P(`n`, numGen.Next(), `, err := `, varName, `.MarshalTo(data[i:])`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`return 0, err`)
|
||||
@@ -399,7 +420,7 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.P(`if m.`, fieldname, ` != nil {`)
|
||||
p.In()
|
||||
}
|
||||
packed := field.IsPacked()
|
||||
packed := field.IsPacked() || (proto3 && field.IsPacked3())
|
||||
wireType := field.WireType()
|
||||
fieldNumber := field.GetNumber()
|
||||
if packed {
|
||||
@@ -541,7 +562,7 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
descriptor.FieldDescriptorProto_TYPE_ENUM:
|
||||
if packed {
|
||||
jvar := "j" + numGen.Next()
|
||||
p.P(`data`, numGen.Next(), ` := make([]byte, len(m.`, fieldname, `)*10)`)
|
||||
p.P(`dAtA`, numGen.Next(), ` := make([]byte, len(m.`, fieldname, `)*10)`)
|
||||
p.P(`var `, jvar, ` int`)
|
||||
if *field.Type == descriptor.FieldDescriptorProto_TYPE_INT64 ||
|
||||
*field.Type == descriptor.FieldDescriptorProto_TYPE_INT32 {
|
||||
@@ -554,18 +575,18 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
}
|
||||
p.P(`for num >= 1<<7 {`)
|
||||
p.In()
|
||||
p.P(`data`, numGen.Current(), `[`, jvar, `] = uint8(uint64(num)&0x7f|0x80)`)
|
||||
p.P(`dAtA`, numGen.Current(), `[`, jvar, `] = uint8(uint64(num)&0x7f|0x80)`)
|
||||
p.P(`num >>= 7`)
|
||||
p.P(jvar, `++`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`data`, numGen.Current(), `[`, jvar, `] = uint8(num)`)
|
||||
p.P(`dAtA`, numGen.Current(), `[`, jvar, `] = uint8(num)`)
|
||||
p.P(jvar, `++`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(jvar)
|
||||
p.P(`i += copy(data[i:], data`, numGen.Current(), `[:`, jvar, `])`)
|
||||
p.P(`i += copy(dAtA[i:], dAtA`, numGen.Current(), `[:`, jvar, `])`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
@@ -729,11 +750,11 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.In()
|
||||
p.P(`if b {`)
|
||||
p.In()
|
||||
p.P(`data[i] = 1`)
|
||||
p.P(`dAtA[i] = 1`)
|
||||
p.Out()
|
||||
p.P(`} else {`)
|
||||
p.In()
|
||||
p.P(`data[i] = 0`)
|
||||
p.P(`dAtA[i] = 0`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`i++`)
|
||||
@@ -745,11 +766,11 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.P(`if b {`)
|
||||
p.In()
|
||||
p.P(`data[i] = 1`)
|
||||
p.P(`dAtA[i] = 1`)
|
||||
p.Out()
|
||||
p.P(`} else {`)
|
||||
p.In()
|
||||
p.P(`data[i] = 0`)
|
||||
p.P(`dAtA[i] = 0`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`i++`)
|
||||
@@ -761,11 +782,11 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.P(`if m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.P(`data[i] = 1`)
|
||||
p.P(`dAtA[i] = 1`)
|
||||
p.Out()
|
||||
p.P(`} else {`)
|
||||
p.In()
|
||||
p.P(`data[i] = 0`)
|
||||
p.P(`dAtA[i] = 0`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`i++`)
|
||||
@@ -775,11 +796,11 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.P(`if m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.P(`data[i] = 1`)
|
||||
p.P(`dAtA[i] = 1`)
|
||||
p.Out()
|
||||
p.P(`} else {`)
|
||||
p.In()
|
||||
p.P(`data[i] = 0`)
|
||||
p.P(`dAtA[i] = 0`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`i++`)
|
||||
@@ -787,11 +808,11 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.P(`if *m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.P(`data[i] = 1`)
|
||||
p.P(`dAtA[i] = 1`)
|
||||
p.Out()
|
||||
p.P(`} else {`)
|
||||
p.In()
|
||||
p.P(`data[i] = 0`)
|
||||
p.P(`dAtA[i] = 0`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`i++`)
|
||||
@@ -803,7 +824,7 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.P(`l = len(s)`)
|
||||
p.encodeVarint("l")
|
||||
p.P(`i+=copy(data[i:], s)`)
|
||||
p.P(`i+=copy(dAtA[i:], s)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
@@ -811,17 +832,17 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `)`)
|
||||
p.P(`i+=copy(data[i:], m.`, fieldname, `)`)
|
||||
p.P(`i+=copy(dAtA[i:], m.`, fieldname, `)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if !nullable {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `)`)
|
||||
p.P(`i+=copy(data[i:], m.`, fieldname, `)`)
|
||||
p.P(`i+=copy(dAtA[i:], m.`, fieldname, `)`)
|
||||
} else {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(*m.`, fieldname, `)`)
|
||||
p.P(`i+=copy(data[i:], *m.`, fieldname, `)`)
|
||||
p.P(`i+=copy(dAtA[i:], *m.`, fieldname, `)`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_GROUP:
|
||||
panic(fmt.Errorf("marshaler does not support group %v", fieldname))
|
||||
@@ -885,39 +906,65 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.P(`v := m.`, fieldname, `[k]`)
|
||||
}
|
||||
accessor := `v`
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
switch m.ValueField.GetType() {
|
||||
case descriptor.FieldDescriptorProto_TYPE_DOUBLE,
|
||||
descriptor.FieldDescriptorProto_TYPE_FIXED64,
|
||||
descriptor.FieldDescriptorProto_TYPE_SFIXED64:
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
sum = append(sum, strconv.Itoa(8))
|
||||
case descriptor.FieldDescriptorProto_TYPE_FLOAT,
|
||||
descriptor.FieldDescriptorProto_TYPE_FIXED32,
|
||||
descriptor.FieldDescriptorProto_TYPE_SFIXED32:
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
sum = append(sum, strconv.Itoa(4))
|
||||
case descriptor.FieldDescriptorProto_TYPE_INT64,
|
||||
descriptor.FieldDescriptorProto_TYPE_UINT64,
|
||||
descriptor.FieldDescriptorProto_TYPE_UINT32,
|
||||
descriptor.FieldDescriptorProto_TYPE_ENUM,
|
||||
descriptor.FieldDescriptorProto_TYPE_INT32:
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
sum = append(sum, `sov`+p.localName+`(uint64(v))`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_BOOL:
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
sum = append(sum, `1`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_STRING,
|
||||
descriptor.FieldDescriptorProto_TYPE_BYTES:
|
||||
case descriptor.FieldDescriptorProto_TYPE_STRING:
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
sum = append(sum, `len(v)+sov`+p.localName+`(uint64(len(v)))`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_SINT32,
|
||||
descriptor.FieldDescriptorProto_TYPE_SINT64:
|
||||
sum = append(sum, `soz`+p.localName+`(uint64(v))`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
|
||||
if nullable {
|
||||
p.P(`if v == nil {`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_BYTES:
|
||||
if gogoproto.IsCustomType(field) {
|
||||
p.P(`cSize := 0`)
|
||||
if gogoproto.IsNullable(field) {
|
||||
p.P(`if `, accessor, ` != nil {`)
|
||||
p.In()
|
||||
}
|
||||
p.P(`cSize = `, accessor, `.Size()`)
|
||||
p.P(`cSize += `, strconv.Itoa(valueKeySize), ` + sov`+p.localName+`(uint64(cSize))`)
|
||||
if gogoproto.IsNullable(field) {
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
}
|
||||
sum = append(sum, `cSize`)
|
||||
} else {
|
||||
p.P(`byteSize := 0`)
|
||||
if proto3 {
|
||||
p.P(`if len(v) > 0 {`)
|
||||
} else {
|
||||
p.P(`if v != nil {`)
|
||||
}
|
||||
p.In()
|
||||
p.P(`return 0, `, p.errorsPkg.Use(), `.New("proto: map has nil element")`)
|
||||
p.P(`byteSize = `, strconv.Itoa(valueKeySize), ` + len(v)+sov`+p.localName+`(uint64(len(v)))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
sum = append(sum, `byteSize`)
|
||||
}
|
||||
if valuegoTyp != valuegoAliasTyp {
|
||||
case descriptor.FieldDescriptorProto_TYPE_SINT32,
|
||||
descriptor.FieldDescriptorProto_TYPE_SINT64:
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
sum = append(sum, `soz`+p.localName+`(uint64(v))`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
|
||||
if valuegoTyp != valuegoAliasTyp &&
|
||||
!gogoproto.IsStdTime(field) &&
|
||||
!gogoproto.IsStdDuration(field) {
|
||||
if nullable {
|
||||
// cast back to the type that has the generated methods on it
|
||||
accessor = `((` + valuegoTyp + `)(` + accessor + `))`
|
||||
@@ -927,31 +974,73 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
} else if !nullable {
|
||||
accessor = `(&v)`
|
||||
}
|
||||
if protoSizer {
|
||||
p.P(`msgSize := `, accessor, `.ProtoSize()`)
|
||||
p.P(`msgSize := 0`)
|
||||
p.P(`if `, accessor, ` != nil {`)
|
||||
p.In()
|
||||
if gogoproto.IsStdTime(field) {
|
||||
p.P(`msgSize = `, p.typesPkg.Use(), `.SizeOfStdTime(*`, accessor, `)`)
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
p.P(`msgSize = `, p.typesPkg.Use(), `.SizeOfStdDuration(*`, accessor, `)`)
|
||||
} else if protoSizer {
|
||||
p.P(`msgSize = `, accessor, `.ProtoSize()`)
|
||||
} else {
|
||||
p.P(`msgSize := `, accessor, `.Size()`)
|
||||
p.P(`msgSize = `, accessor, `.Size()`)
|
||||
}
|
||||
sum = append(sum, `msgSize + sov`+p.localName+`(uint64(msgSize))`)
|
||||
p.P(`msgSize += `, strconv.Itoa(valueKeySize), ` + sov`+p.localName+`(uint64(msgSize))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
sum = append(sum, `msgSize`)
|
||||
}
|
||||
p.P(`mapSize := `, strings.Join(sum, " + "))
|
||||
p.callVarint("mapSize")
|
||||
p.encodeKey(1, wireToType(keywire))
|
||||
p.mapField(numGen, m.KeyField.GetType(), "k", protoSizer)
|
||||
p.mapField(numGen, field, m.KeyField, "k", protoSizer)
|
||||
nullableMsg := nullable && (m.ValueField.GetType() == descriptor.FieldDescriptorProto_TYPE_MESSAGE ||
|
||||
gogoproto.IsCustomType(field) && m.ValueField.IsBytes())
|
||||
plainBytes := m.ValueField.IsBytes() && !gogoproto.IsCustomType(field)
|
||||
if nullableMsg {
|
||||
p.P(`if `, accessor, ` != nil { `)
|
||||
p.In()
|
||||
} else if plainBytes {
|
||||
if proto3 {
|
||||
p.P(`if len(`, accessor, `) > 0 {`)
|
||||
} else {
|
||||
p.P(`if `, accessor, ` != nil {`)
|
||||
}
|
||||
p.In()
|
||||
}
|
||||
p.encodeKey(2, wireToType(valuewire))
|
||||
p.mapField(numGen, m.ValueField.GetType(), accessor, protoSizer)
|
||||
p.mapField(numGen, field, m.ValueField, accessor, protoSizer)
|
||||
if nullableMsg || plainBytes {
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
}
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
p.P(`for _, msg := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
if protoSizer {
|
||||
p.callVarint("msg.ProtoSize()")
|
||||
varName := "msg"
|
||||
if gogoproto.IsStdTime(field) {
|
||||
if gogoproto.IsNullable(field) {
|
||||
varName = "*" + varName
|
||||
}
|
||||
p.callVarint(p.typesPkg.Use(), `.SizeOfStdTime(`, varName, `)`)
|
||||
p.P(`n, err := `, p.typesPkg.Use(), `.StdTimeMarshalTo(`, varName, `, dAtA[i:])`)
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
if gogoproto.IsNullable(field) {
|
||||
varName = "*" + varName
|
||||
}
|
||||
p.callVarint(p.typesPkg.Use(), `.SizeOfStdDuration(`, varName, `)`)
|
||||
p.P(`n, err := `, p.typesPkg.Use(), `.StdDurationMarshalTo(`, varName, `, dAtA[i:])`)
|
||||
} else if protoSizer {
|
||||
p.callVarint(varName, ".ProtoSize()")
|
||||
p.P(`n, err := `, varName, `.MarshalTo(dAtA[i:])`)
|
||||
} else {
|
||||
p.callVarint("msg.Size()")
|
||||
p.callVarint(varName, ".Size()")
|
||||
p.P(`n, err := `, varName, `.MarshalTo(dAtA[i:])`)
|
||||
}
|
||||
p.P(`n, err := msg.MarshalTo(data[i:])`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`return 0, err`)
|
||||
@@ -962,12 +1051,26 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.P(`}`)
|
||||
} else {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
if protoSizer {
|
||||
p.callVarint(`m.`, fieldname, `.ProtoSize()`)
|
||||
varName := `m.` + fieldname
|
||||
if gogoproto.IsStdTime(field) {
|
||||
if gogoproto.IsNullable(field) {
|
||||
varName = "*" + varName
|
||||
}
|
||||
p.callVarint(p.typesPkg.Use(), `.SizeOfStdTime(`, varName, `)`)
|
||||
p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdTimeMarshalTo(`, varName, `, dAtA[i:])`)
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
if gogoproto.IsNullable(field) {
|
||||
varName = "*" + varName
|
||||
}
|
||||
p.callVarint(p.typesPkg.Use(), `.SizeOfStdDuration(`, varName, `)`)
|
||||
p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdDurationMarshalTo(`, varName, `, dAtA[i:])`)
|
||||
} else if protoSizer {
|
||||
p.callVarint(varName, `.ProtoSize()`)
|
||||
p.P(`n`, numGen.Next(), `, err := `, varName, `.MarshalTo(dAtA[i:])`)
|
||||
} else {
|
||||
p.callVarint(`m.`, fieldname, `.Size()`)
|
||||
p.callVarint(varName, `.Size()`)
|
||||
p.P(`n`, numGen.Next(), `, err := `, varName, `.MarshalTo(dAtA[i:])`)
|
||||
}
|
||||
p.P(`n`, numGen.Next(), `, err := m.`, fieldname, `.MarshalTo(data[i:])`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`return 0, err`)
|
||||
@@ -982,7 +1085,7 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint("len(b)")
|
||||
p.P(`i+=copy(data[i:], b)`)
|
||||
p.P(`i+=copy(dAtA[i:], b)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
@@ -990,13 +1093,13 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `)`)
|
||||
p.P(`i+=copy(data[i:], m.`, fieldname, `)`)
|
||||
p.P(`i+=copy(dAtA[i:], m.`, fieldname, `)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `)`)
|
||||
p.P(`i+=copy(data[i:], m.`, fieldname, `)`)
|
||||
p.P(`i+=copy(dAtA[i:], m.`, fieldname, `)`)
|
||||
}
|
||||
} else {
|
||||
if repeated {
|
||||
@@ -1008,7 +1111,7 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
} else {
|
||||
p.callVarint(`msg.Size()`)
|
||||
}
|
||||
p.P(`n, err := msg.MarshalTo(data[i:])`)
|
||||
p.P(`n, err := msg.MarshalTo(dAtA[i:])`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`return 0, err`)
|
||||
@@ -1024,7 +1127,7 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
} else {
|
||||
p.callVarint(`m.`, fieldname, `.Size()`)
|
||||
}
|
||||
p.P(`n`, numGen.Next(), `, err := m.`, fieldname, `.MarshalTo(data[i:])`)
|
||||
p.P(`n`, numGen.Next(), `, err := m.`, fieldname, `.MarshalTo(dAtA[i:])`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`return 0, err`)
|
||||
@@ -1035,7 +1138,7 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_SINT32:
|
||||
if packed {
|
||||
datavar := "data" + numGen.Next()
|
||||
datavar := "dAtA" + numGen.Next()
|
||||
jvar := "j" + numGen.Next()
|
||||
p.P(datavar, ` := make([]byte, len(m.`, fieldname, ")*5)")
|
||||
p.P(`var `, jvar, ` int`)
|
||||
@@ -1056,7 +1159,7 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.P(`}`)
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(jvar)
|
||||
p.P(`i+=copy(data[i:], `, datavar, `[:`, jvar, `])`)
|
||||
p.P(`i+=copy(dAtA[i:], `, datavar, `[:`, jvar, `])`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
@@ -1083,7 +1186,7 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
if packed {
|
||||
jvar := "j" + numGen.Next()
|
||||
xvar := "x" + numGen.Next()
|
||||
datavar := "data" + numGen.Next()
|
||||
datavar := "dAtA" + numGen.Next()
|
||||
p.P(`var `, jvar, ` int`)
|
||||
p.P(datavar, ` := make([]byte, len(m.`, fieldname, `)*10)`)
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
@@ -1102,7 +1205,7 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
p.P(`}`)
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(jvar)
|
||||
p.P(`i+=copy(data[i:], `, datavar, `[:`, jvar, `])`)
|
||||
p.P(`i+=copy(dAtA[i:], `, datavar, `[:`, jvar, `])`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
@@ -1148,6 +1251,7 @@ func (p *marshalto) Generate(file *generator.FileDescriptor) {
|
||||
}
|
||||
p.unsafePkg = p.NewImport("unsafe")
|
||||
p.errorsPkg = p.NewImport("errors")
|
||||
p.typesPkg = p.NewImport("github.com/gogo/protobuf/types")
|
||||
|
||||
for _, message := range file.Messages() {
|
||||
if message.DescriptorProto.GetOptions().GetMapEntry() {
|
||||
@@ -1172,25 +1276,25 @@ func (p *marshalto) Generate(file *generator.FileDescriptor) {
|
||||
}
|
||||
p.atleastOne = true
|
||||
|
||||
p.P(`func (m *`, ccTypeName, `) Marshal() (data []byte, err error) {`)
|
||||
p.P(`func (m *`, ccTypeName, `) Marshal() (dAtA []byte, err error) {`)
|
||||
p.In()
|
||||
if gogoproto.IsProtoSizer(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
p.P(`size := m.ProtoSize()`)
|
||||
} else {
|
||||
p.P(`size := m.Size()`)
|
||||
}
|
||||
p.P(`data = make([]byte, size)`)
|
||||
p.P(`n, err := m.MarshalTo(data)`)
|
||||
p.P(`dAtA = make([]byte, size)`)
|
||||
p.P(`n, err := m.MarshalTo(dAtA)`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`return nil, err`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`return data[:n], nil`)
|
||||
p.P(`return dAtA[:n], nil`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(``)
|
||||
p.P(`func (m *`, ccTypeName, `) MarshalTo(data []byte) (int, error) {`)
|
||||
p.P(`func (m *`, ccTypeName, `) MarshalTo(dAtA []byte) (int, error) {`)
|
||||
p.In()
|
||||
p.P(`var i int`)
|
||||
p.P(`_ = i`)
|
||||
@@ -1210,7 +1314,7 @@ func (p *marshalto) Generate(file *generator.FileDescriptor) {
|
||||
oneofs[fieldname] = struct{}{}
|
||||
p.P(`if m.`, fieldname, ` != nil {`)
|
||||
p.In()
|
||||
p.P(`nn`, numGen.Next(), `, err := m.`, fieldname, `.MarshalTo(data[i:])`)
|
||||
p.P(`nn`, numGen.Next(), `, err := m.`, fieldname, `.MarshalTo(dAtA[i:])`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`return 0, err`)
|
||||
@@ -1224,21 +1328,17 @@ func (p *marshalto) Generate(file *generator.FileDescriptor) {
|
||||
}
|
||||
if message.DescriptorProto.HasExtension() {
|
||||
if gogoproto.HasExtensionsMap(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
p.P(`if len(m.XXX_extensions) > 0 {`)
|
||||
p.In()
|
||||
p.P(`n, err := `, p.protoPkg.Use(), `.EncodeExtensionMap(m.XXX_extensions, data[i:])`)
|
||||
p.P(`n, err := `, p.protoPkg.Use(), `.EncodeInternalExtension(m, dAtA[i:])`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`return 0, err`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`i+=n`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else {
|
||||
p.P(`if m.XXX_extensions != nil {`)
|
||||
p.In()
|
||||
p.P(`i+=copy(data[i:], m.XXX_extensions)`)
|
||||
p.P(`i+=copy(dAtA[i:], m.XXX_extensions)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
}
|
||||
@@ -1246,7 +1346,7 @@ func (p *marshalto) Generate(file *generator.FileDescriptor) {
|
||||
if gogoproto.HasUnrecognized(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
p.P(`if m.XXX_unrecognized != nil {`)
|
||||
p.In()
|
||||
p.P(`i+=copy(data[i:], m.XXX_unrecognized)`)
|
||||
p.P(`i+=copy(dAtA[i:], m.XXX_unrecognized)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
}
|
||||
@@ -1264,7 +1364,7 @@ func (p *marshalto) Generate(file *generator.FileDescriptor) {
|
||||
continue
|
||||
}
|
||||
ccTypeName := p.OneOfTypeName(message, field)
|
||||
p.P(`func (m *`, ccTypeName, `) MarshalTo(data []byte) (int, error) {`)
|
||||
p.P(`func (m *`, ccTypeName, `) MarshalTo(dAtA []byte) (int, error) {`)
|
||||
p.In()
|
||||
p.P(`i := 0`)
|
||||
vanity.TurnOffNullableForNativeTypesWithoutDefaultsOnly(field)
|
||||
@@ -1276,40 +1376,40 @@ func (p *marshalto) Generate(file *generator.FileDescriptor) {
|
||||
}
|
||||
|
||||
if p.atleastOne {
|
||||
p.P(`func encodeFixed64`, p.localName, `(data []byte, offset int, v uint64) int {`)
|
||||
p.P(`func encodeFixed64`, p.localName, `(dAtA []byte, offset int, v uint64) int {`)
|
||||
p.In()
|
||||
p.P(`data[offset] = uint8(v)`)
|
||||
p.P(`data[offset+1] = uint8(v >> 8)`)
|
||||
p.P(`data[offset+2] = uint8(v >> 16)`)
|
||||
p.P(`data[offset+3] = uint8(v >> 24)`)
|
||||
p.P(`data[offset+4] = uint8(v >> 32)`)
|
||||
p.P(`data[offset+5] = uint8(v >> 40)`)
|
||||
p.P(`data[offset+6] = uint8(v >> 48)`)
|
||||
p.P(`data[offset+7] = uint8(v >> 56)`)
|
||||
p.P(`dAtA[offset] = uint8(v)`)
|
||||
p.P(`dAtA[offset+1] = uint8(v >> 8)`)
|
||||
p.P(`dAtA[offset+2] = uint8(v >> 16)`)
|
||||
p.P(`dAtA[offset+3] = uint8(v >> 24)`)
|
||||
p.P(`dAtA[offset+4] = uint8(v >> 32)`)
|
||||
p.P(`dAtA[offset+5] = uint8(v >> 40)`)
|
||||
p.P(`dAtA[offset+6] = uint8(v >> 48)`)
|
||||
p.P(`dAtA[offset+7] = uint8(v >> 56)`)
|
||||
p.P(`return offset+8`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
p.P(`func encodeFixed32`, p.localName, `(data []byte, offset int, v uint32) int {`)
|
||||
p.P(`func encodeFixed32`, p.localName, `(dAtA []byte, offset int, v uint32) int {`)
|
||||
p.In()
|
||||
p.P(`data[offset] = uint8(v)`)
|
||||
p.P(`data[offset+1] = uint8(v >> 8)`)
|
||||
p.P(`data[offset+2] = uint8(v >> 16)`)
|
||||
p.P(`data[offset+3] = uint8(v >> 24)`)
|
||||
p.P(`dAtA[offset] = uint8(v)`)
|
||||
p.P(`dAtA[offset+1] = uint8(v >> 8)`)
|
||||
p.P(`dAtA[offset+2] = uint8(v >> 16)`)
|
||||
p.P(`dAtA[offset+3] = uint8(v >> 24)`)
|
||||
p.P(`return offset+4`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
p.P(`func encodeVarint`, p.localName, `(data []byte, offset int, v uint64) int {`)
|
||||
p.P(`func encodeVarint`, p.localName, `(dAtA []byte, offset int, v uint64) int {`)
|
||||
p.In()
|
||||
p.P(`for v >= 1<<7 {`)
|
||||
p.In()
|
||||
p.P(`data[offset] = uint8(v&0x7f|0x80)`)
|
||||
p.P(`dAtA[offset] = uint8(v&0x7f|0x80)`)
|
||||
p.P(`v >>= 7`)
|
||||
p.P(`offset++`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`data[offset] = uint8(v)`)
|
||||
p.P(`dAtA[offset] = uint8(v)`)
|
||||
p.P(`return offset+1`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
4
vendor/github.com/gogo/protobuf/plugin/oneofcheck/oneofcheck.go
generated
vendored
4
vendor/github.com/gogo/protobuf/plugin/oneofcheck/oneofcheck.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
|
||||
102
vendor/github.com/gogo/protobuf/plugin/populate/populate.go
generated
vendored
102
vendor/github.com/gogo/protobuf/plugin/populate/populate.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -83,14 +85,15 @@ package populate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gogo/protobuf/gogoproto"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
descriptor "github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
|
||||
"github.com/gogo/protobuf/protoc-gen-gogo/generator"
|
||||
"github.com/gogo/protobuf/vanity"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type VarGen interface {
|
||||
@@ -121,6 +124,7 @@ type plugin struct {
|
||||
varGen VarGen
|
||||
atleastOne bool
|
||||
localName string
|
||||
typesPkg generator.Single
|
||||
}
|
||||
|
||||
func NewPlugin() *plugin {
|
||||
@@ -178,7 +182,7 @@ func negative(fieldType descriptor.FieldDescriptorProto_Type) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func getFuncName(goTypName string) string {
|
||||
func (p *plugin) getFuncName(goTypName string) string {
|
||||
funcName := "NewPopulated" + goTypName
|
||||
goTypNames := strings.Split(goTypName, ".")
|
||||
if len(goTypNames) == 2 {
|
||||
@@ -186,17 +190,24 @@ func getFuncName(goTypName string) string {
|
||||
} else if len(goTypNames) != 1 {
|
||||
panic(fmt.Errorf("unreachable: too many dots in %v", goTypName))
|
||||
}
|
||||
switch funcName {
|
||||
case "time.NewPopulatedTime":
|
||||
funcName = p.typesPkg.Use() + ".NewPopulatedStdTime"
|
||||
case "time.NewPopulatedDuration":
|
||||
p.typesPkg.Use()
|
||||
funcName = p.typesPkg.Use() + ".NewPopulatedStdDuration"
|
||||
}
|
||||
return funcName
|
||||
}
|
||||
|
||||
func getFuncCall(goTypName string) string {
|
||||
funcName := getFuncName(goTypName)
|
||||
func (p *plugin) getFuncCall(goTypName string) string {
|
||||
funcName := p.getFuncName(goTypName)
|
||||
funcCall := funcName + "(r, easy)"
|
||||
return funcCall
|
||||
}
|
||||
|
||||
func getCustomFuncCall(goTypName string) string {
|
||||
funcName := getFuncName(goTypName)
|
||||
func (p *plugin) getCustomFuncCall(goTypName string) string {
|
||||
funcName := p.getFuncName(goTypName)
|
||||
funcCall := funcName + "(r)"
|
||||
return funcCall
|
||||
}
|
||||
@@ -246,10 +257,17 @@ func (p *plugin) GenerateField(file *generator.FileDescriptor, message *generato
|
||||
if keygoAliasTyp != keygoTyp {
|
||||
keyval = keygoAliasTyp + `(` + keyval + `)`
|
||||
}
|
||||
if m.ValueField.IsMessage() || p.IsGroup(field) {
|
||||
if m.ValueField.IsMessage() || p.IsGroup(field) ||
|
||||
(m.ValueField.IsBytes() && gogoproto.IsCustomType(field)) {
|
||||
s := `this.` + fieldname + `[` + keyval + `] = `
|
||||
goTypName = generator.GoTypeToName(valuegoTyp)
|
||||
funcCall := getFuncCall(goTypName)
|
||||
if gogoproto.IsStdTime(field) || gogoproto.IsStdDuration(field) {
|
||||
valuegoTyp = valuegoAliasTyp
|
||||
}
|
||||
funcCall := p.getCustomFuncCall(goTypName)
|
||||
if !gogoproto.IsCustomType(field) {
|
||||
goTypName = generator.GoTypeToName(valuegoTyp)
|
||||
funcCall = p.getFuncCall(goTypName)
|
||||
}
|
||||
if !nullable {
|
||||
funcCall = `*` + funcCall
|
||||
}
|
||||
@@ -288,7 +306,7 @@ func (p *plugin) GenerateField(file *generator.FileDescriptor, message *generato
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if field.IsMessage() || p.IsGroup(field) {
|
||||
funcCall := getFuncCall(goTypName)
|
||||
funcCall := p.getFuncCall(goTypName)
|
||||
if field.IsRepeated() {
|
||||
p.P(p.varGen.Next(), ` := r.Intn(5)`)
|
||||
p.P(`this.`, fieldname, ` = make(`, goTyp, `, `, p.varGen.Current(), `)`)
|
||||
@@ -328,7 +346,7 @@ func (p *plugin) GenerateField(file *generator.FileDescriptor, message *generato
|
||||
p.P(`this.`, fieldname, ` = &`, p.varGen.Current())
|
||||
}
|
||||
} else if gogoproto.IsCustomType(field) {
|
||||
funcCall := getCustomFuncCall(goTypName)
|
||||
funcCall := p.getCustomFuncCall(goTypName)
|
||||
if field.IsRepeated() {
|
||||
p.P(p.varGen.Next(), ` := r.Intn(10)`)
|
||||
p.P(`this.`, fieldname, ` = make(`, goTyp, `, `, p.varGen.Current(), `)`)
|
||||
@@ -369,7 +387,8 @@ func (p *plugin) GenerateField(file *generator.FileDescriptor, message *generato
|
||||
p.P(`}`)
|
||||
}
|
||||
} else if field.IsString() {
|
||||
val := fmt.Sprintf("randString%v(r)", p.localName)
|
||||
typName := generator.GoTypeToName(goTyp)
|
||||
val := fmt.Sprintf("%s(randString%v(r))", typName, p.localName)
|
||||
if field.IsRepeated() {
|
||||
p.P(p.varGen.Next(), ` := r.Intn(10)`)
|
||||
p.P(`this.`, fieldname, ` = make(`, goTyp, `, `, p.varGen.Current(), `)`)
|
||||
@@ -449,11 +468,14 @@ func (p *plugin) hasLoop(field *descriptor.FieldDescriptorProto, visited []*gene
|
||||
return fieldMessage
|
||||
}
|
||||
}
|
||||
pkg := strings.Split(field.GetTypeName(), ".")[1]
|
||||
for _, f := range fieldMessage.Field {
|
||||
visited = append(visited, fieldMessage)
|
||||
loopTo := p.hasLoop(f, visited, excludes)
|
||||
if loopTo != nil {
|
||||
return loopTo
|
||||
if strings.HasPrefix(f.GetTypeName(), "."+pkg+".") {
|
||||
visited = append(visited, fieldMessage)
|
||||
loopTo := p.hasLoop(f, visited, excludes)
|
||||
if loopTo != nil {
|
||||
return loopTo
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -482,7 +504,7 @@ func (p *plugin) Generate(file *generator.FileDescriptor) {
|
||||
p.PluginImports = generator.NewPluginImports(p.Generator)
|
||||
p.varGen = NewVarGen()
|
||||
proto3 := gogoproto.IsProto3(file.FileDescriptorProto)
|
||||
|
||||
p.typesPkg = p.NewImport("github.com/gogo/protobuf/types")
|
||||
p.localName = generator.FileName(file)
|
||||
protoPkg := p.NewImport("github.com/gogo/protobuf/proto")
|
||||
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
|
||||
@@ -612,8 +634,8 @@ func (p *plugin) Generate(file *generator.FileDescriptor) {
|
||||
}
|
||||
p.P(`wire := r.Intn(4)`)
|
||||
p.P(`if wire == 3 { wire = 5 }`)
|
||||
p.P(`data := randField`, p.localName, `(nil, r, fieldNumber, wire)`)
|
||||
p.P(protoPkg.Use(), `.SetRawExtension(this, int32(fieldNumber), data)`)
|
||||
p.P(`dAtA := randField`, p.localName, `(nil, r, fieldNumber, wire)`)
|
||||
p.P(protoPkg.Use(), `.SetRawExtension(this, int32(fieldNumber), dAtA)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.Out()
|
||||
@@ -698,7 +720,7 @@ func (p *plugin) Generate(file *generator.FileDescriptor) {
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
p.P(`func randUnrecognized`, p.localName, `(r randy`, p.localName, `, maxFieldNumber int) (data []byte) {`)
|
||||
p.P(`func randUnrecognized`, p.localName, `(r randy`, p.localName, `, maxFieldNumber int) (dAtA []byte) {`)
|
||||
p.In()
|
||||
p.P(`l := r.Intn(5)`)
|
||||
p.P(`for i := 0; i < l; i++ {`)
|
||||
@@ -706,64 +728,64 @@ func (p *plugin) Generate(file *generator.FileDescriptor) {
|
||||
p.P(`wire := r.Intn(4)`)
|
||||
p.P(`if wire == 3 { wire = 5 }`)
|
||||
p.P(`fieldNumber := maxFieldNumber + r.Intn(100)`)
|
||||
p.P(`data = randField`, p.localName, `(data, r, fieldNumber, wire)`)
|
||||
p.P(`dAtA = randField`, p.localName, `(dAtA, r, fieldNumber, wire)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`return data`)
|
||||
p.P(`return dAtA`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
p.P(`func randField`, p.localName, `(data []byte, r randy`, p.localName, `, fieldNumber int, wire int) []byte {`)
|
||||
p.P(`func randField`, p.localName, `(dAtA []byte, r randy`, p.localName, `, fieldNumber int, wire int) []byte {`)
|
||||
p.In()
|
||||
p.P(`key := uint32(fieldNumber)<<3 | uint32(wire)`)
|
||||
p.P(`switch wire {`)
|
||||
p.P(`case 0:`)
|
||||
p.In()
|
||||
p.P(`data = encodeVarintPopulate`, p.localName, `(data, uint64(key))`)
|
||||
p.P(`dAtA = encodeVarintPopulate`, p.localName, `(dAtA, uint64(key))`)
|
||||
p.P(p.varGen.Next(), ` := r.Int63()`)
|
||||
p.P(`if r.Intn(2) == 0 {`)
|
||||
p.In()
|
||||
p.P(p.varGen.Current(), ` *= -1`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`data = encodeVarintPopulate`, p.localName, `(data, uint64(`, p.varGen.Current(), `))`)
|
||||
p.P(`dAtA = encodeVarintPopulate`, p.localName, `(dAtA, uint64(`, p.varGen.Current(), `))`)
|
||||
p.Out()
|
||||
p.P(`case 1:`)
|
||||
p.In()
|
||||
p.P(`data = encodeVarintPopulate`, p.localName, `(data, uint64(key))`)
|
||||
p.P(`data = append(data, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))`)
|
||||
p.P(`dAtA = encodeVarintPopulate`, p.localName, `(dAtA, uint64(key))`)
|
||||
p.P(`dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))`)
|
||||
p.Out()
|
||||
p.P(`case 2:`)
|
||||
p.In()
|
||||
p.P(`data = encodeVarintPopulate`, p.localName, `(data, uint64(key))`)
|
||||
p.P(`dAtA = encodeVarintPopulate`, p.localName, `(dAtA, uint64(key))`)
|
||||
p.P(`ll := r.Intn(100)`)
|
||||
p.P(`data = encodeVarintPopulate`, p.localName, `(data, uint64(ll))`)
|
||||
p.P(`dAtA = encodeVarintPopulate`, p.localName, `(dAtA, uint64(ll))`)
|
||||
p.P(`for j := 0; j < ll; j++ {`)
|
||||
p.In()
|
||||
p.P(`data = append(data, byte(r.Intn(256)))`)
|
||||
p.P(`dAtA = append(dAtA, byte(r.Intn(256)))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.Out()
|
||||
p.P(`default:`)
|
||||
p.In()
|
||||
p.P(`data = encodeVarintPopulate`, p.localName, `(data, uint64(key))`)
|
||||
p.P(`data = append(data, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))`)
|
||||
p.P(`dAtA = encodeVarintPopulate`, p.localName, `(dAtA, uint64(key))`)
|
||||
p.P(`dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`return data`)
|
||||
p.P(`return dAtA`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
p.P(`func encodeVarintPopulate`, p.localName, `(data []byte, v uint64) []byte {`)
|
||||
p.P(`func encodeVarintPopulate`, p.localName, `(dAtA []byte, v uint64) []byte {`)
|
||||
p.In()
|
||||
p.P(`for v >= 1<<7 {`)
|
||||
p.In()
|
||||
p.P(`data = append(data, uint8(uint64(v)&0x7f|0x80))`)
|
||||
p.P(`dAtA = append(dAtA, uint8(uint64(v)&0x7f|0x80))`)
|
||||
p.P(`v >>= 7`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`data = append(data, uint8(v))`)
|
||||
p.P(`return data`)
|
||||
p.P(`dAtA = append(dAtA, uint8(v))`)
|
||||
p.P(`return dAtA`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
|
||||
106
vendor/github.com/gogo/protobuf/plugin/size/size.go
generated
vendored
106
vendor/github.com/gogo/protobuf/plugin/size/size.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -88,13 +90,13 @@ and the following test code:
|
||||
func TestBSize(t *testing5.T) {
|
||||
popr := math_rand5.New(math_rand5.NewSource(time5.Now().UnixNano()))
|
||||
p := NewPopulatedB(popr, true)
|
||||
data, err := github_com_gogo_protobuf_proto2.Marshal(p)
|
||||
dAtA, err := github_com_gogo_protobuf_proto2.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(data) != size {
|
||||
t.Fatalf("size %v != marshalled size %v", size, len(data))
|
||||
if len(dAtA) != size {
|
||||
t.Fatalf("size %v != marshalled size %v", size, len(dAtA))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +136,7 @@ type size struct {
|
||||
generator.PluginImports
|
||||
atleastOne bool
|
||||
localName string
|
||||
typesPkg generator.Single
|
||||
}
|
||||
|
||||
func NewSize() *size {
|
||||
@@ -198,6 +201,23 @@ func (p *size) sizeZigZag() {
|
||||
}`)
|
||||
}
|
||||
|
||||
func (p *size) std(field *descriptor.FieldDescriptorProto, name string) (string, bool) {
|
||||
if gogoproto.IsStdTime(field) {
|
||||
if gogoproto.IsNullable(field) {
|
||||
return p.typesPkg.Use() + `.SizeOfStdTime(*` + name + `)`, true
|
||||
} else {
|
||||
return p.typesPkg.Use() + `.SizeOfStdTime(` + name + `)`, true
|
||||
}
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
if gogoproto.IsNullable(field) {
|
||||
return p.typesPkg.Use() + `.SizeOfStdDuration(*` + name + `)`, true
|
||||
} else {
|
||||
return p.typesPkg.Use() + `.SizeOfStdDuration(` + name + `)`, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func (p *size) generateField(proto3 bool, file *generator.FileDescriptor, message *generator.Descriptor, field *descriptor.FieldDescriptorProto, sizeName string) {
|
||||
fieldname := p.GetOneOfFieldName(message, field)
|
||||
nullable := gogoproto.IsNullable(field)
|
||||
@@ -210,7 +230,7 @@ func (p *size) generateField(proto3 bool, file *generator.FileDescriptor, messag
|
||||
p.P(`if m.`, fieldname, ` != nil {`)
|
||||
p.In()
|
||||
}
|
||||
packed := field.IsPacked()
|
||||
packed := field.IsPacked() || (proto3 && field.IsPacked3())
|
||||
_, wire := p.GoType(message, field)
|
||||
wireType := wireToType(wire)
|
||||
fieldNumber := field.GetNumber()
|
||||
@@ -367,50 +387,89 @@ func (p *size) generateField(proto3 bool, file *generator.FileDescriptor, messag
|
||||
descriptor.FieldDescriptorProto_TYPE_SINT64:
|
||||
sum = append(sum, `soz`+p.localName+`(uint64(k))`)
|
||||
}
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
switch m.ValueField.GetType() {
|
||||
case descriptor.FieldDescriptorProto_TYPE_DOUBLE,
|
||||
descriptor.FieldDescriptorProto_TYPE_FIXED64,
|
||||
descriptor.FieldDescriptorProto_TYPE_SFIXED64:
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
sum = append(sum, strconv.Itoa(8))
|
||||
case descriptor.FieldDescriptorProto_TYPE_FLOAT,
|
||||
descriptor.FieldDescriptorProto_TYPE_FIXED32,
|
||||
descriptor.FieldDescriptorProto_TYPE_SFIXED32:
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
sum = append(sum, strconv.Itoa(4))
|
||||
case descriptor.FieldDescriptorProto_TYPE_INT64,
|
||||
descriptor.FieldDescriptorProto_TYPE_UINT64,
|
||||
descriptor.FieldDescriptorProto_TYPE_UINT32,
|
||||
descriptor.FieldDescriptorProto_TYPE_ENUM,
|
||||
descriptor.FieldDescriptorProto_TYPE_INT32:
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
sum = append(sum, `sov`+p.localName+`(uint64(v))`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_BOOL:
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
sum = append(sum, `1`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_STRING,
|
||||
descriptor.FieldDescriptorProto_TYPE_BYTES:
|
||||
case descriptor.FieldDescriptorProto_TYPE_STRING:
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
sum = append(sum, `len(v)+sov`+p.localName+`(uint64(len(v)))`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_BYTES:
|
||||
if gogoproto.IsCustomType(field) {
|
||||
p.P(`l = 0`)
|
||||
if nullable {
|
||||
p.P(`if v != nil {`)
|
||||
p.In()
|
||||
}
|
||||
p.P(`l = v.`, sizeName, `()`)
|
||||
p.P(`l += `, strconv.Itoa(valueKeySize), ` + sov`+p.localName+`(uint64(l))`)
|
||||
if nullable {
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
}
|
||||
sum = append(sum, `l`)
|
||||
} else {
|
||||
p.P(`l = 0`)
|
||||
if proto3 {
|
||||
p.P(`if len(v) > 0 {`)
|
||||
} else {
|
||||
p.P(`if v != nil {`)
|
||||
}
|
||||
p.In()
|
||||
p.P(`l = `, strconv.Itoa(valueKeySize), ` + len(v)+sov`+p.localName+`(uint64(len(v)))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
sum = append(sum, `l`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_SINT32,
|
||||
descriptor.FieldDescriptorProto_TYPE_SINT64:
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
sum = append(sum, `soz`+p.localName+`(uint64(v))`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
|
||||
stdSizeCall, stdOk := p.std(field, "v")
|
||||
if nullable {
|
||||
p.P(`l = 0`)
|
||||
p.P(`if v != nil {`)
|
||||
p.In()
|
||||
if valuegoTyp != valuegoAliasTyp {
|
||||
if stdOk {
|
||||
p.P(`l = `, stdSizeCall)
|
||||
} else if valuegoTyp != valuegoAliasTyp {
|
||||
p.P(`l = ((`, valuegoTyp, `)(v)).`, sizeName, `()`)
|
||||
} else {
|
||||
p.P(`l = v.`, sizeName, `()`)
|
||||
}
|
||||
p.P(`l += `, strconv.Itoa(valueKeySize), ` + sov`+p.localName+`(uint64(l))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
sum = append(sum, `l`)
|
||||
} else {
|
||||
if valuegoTyp != valuegoAliasTyp {
|
||||
if stdOk {
|
||||
p.P(`l = `, stdSizeCall)
|
||||
} else if valuegoTyp != valuegoAliasTyp {
|
||||
p.P(`l = ((*`, valuegoTyp, `)(&v)).`, sizeName, `()`)
|
||||
} else {
|
||||
p.P(`l = v.`, sizeName, `()`)
|
||||
}
|
||||
sum = append(sum, strconv.Itoa(valueKeySize))
|
||||
sum = append(sum, `l+sov`+p.localName+`(uint64(l))`)
|
||||
}
|
||||
sum = append(sum, `l+sov`+p.localName+`(uint64(l))`)
|
||||
}
|
||||
p.P(`mapEntrySize := `, strings.Join(sum, "+"))
|
||||
p.P(`n+=mapEntrySize+`, fieldKeySize, `+sov`, p.localName, `(uint64(mapEntrySize))`)
|
||||
@@ -419,12 +478,22 @@ func (p *size) generateField(proto3 bool, file *generator.FileDescriptor, messag
|
||||
} else if repeated {
|
||||
p.P(`for _, e := range m.`, fieldname, ` { `)
|
||||
p.In()
|
||||
p.P(`l=e.`, sizeName, `()`)
|
||||
stdSizeCall, stdOk := p.std(field, "e")
|
||||
if stdOk {
|
||||
p.P(`l=`, stdSizeCall)
|
||||
} else {
|
||||
p.P(`l=e.`, sizeName, `()`)
|
||||
}
|
||||
p.P(`n+=`, strconv.Itoa(key), `+l+sov`, p.localName, `(uint64(l))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else {
|
||||
p.P(`l=m.`, fieldname, `.`, sizeName, `()`)
|
||||
stdSizeCall, stdOk := p.std(field, "m."+fieldname)
|
||||
if stdOk {
|
||||
p.P(`l=`, stdSizeCall)
|
||||
} else {
|
||||
p.P(`l=m.`, fieldname, `.`, sizeName, `()`)
|
||||
}
|
||||
p.P(`n+=`, strconv.Itoa(key), `+l+sov`, p.localName, `(uint64(l))`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_BYTES:
|
||||
@@ -500,6 +569,7 @@ func (p *size) Generate(file *generator.FileDescriptor) {
|
||||
p.PluginImports = generator.NewPluginImports(p.Generator)
|
||||
p.atleastOne = false
|
||||
p.localName = generator.FileName(file)
|
||||
p.typesPkg = p.NewImport("github.com/gogo/protobuf/types")
|
||||
protoPkg := p.NewImport("github.com/gogo/protobuf/proto")
|
||||
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
|
||||
protoPkg = p.NewImport("github.com/golang/protobuf/proto")
|
||||
@@ -543,15 +613,15 @@ func (p *size) Generate(file *generator.FileDescriptor) {
|
||||
}
|
||||
}
|
||||
if message.DescriptorProto.HasExtension() {
|
||||
p.P(`if m.XXX_extensions != nil {`)
|
||||
p.In()
|
||||
if gogoproto.HasExtensionsMap(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
p.P(`n += `, protoPkg.Use(), `.SizeOfExtensionMap(m.XXX_extensions)`)
|
||||
p.P(`n += `, protoPkg.Use(), `.SizeOfInternalExtension(m)`)
|
||||
} else {
|
||||
p.P(`if m.XXX_extensions != nil {`)
|
||||
p.In()
|
||||
p.P(`n+=len(m.XXX_extensions)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
}
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
}
|
||||
if gogoproto.HasUnrecognized(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
p.P(`if m.XXX_unrecognized != nil {`)
|
||||
|
||||
10
vendor/github.com/gogo/protobuf/plugin/size/sizetest.go
generated
vendored
10
vendor/github.com/gogo/protobuf/plugin/size/sizetest.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -71,16 +73,16 @@ func (p *test) Generate(imports generator.PluginImports, file *generator.FileDes
|
||||
p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(seed))`)
|
||||
p.P(`p := NewPopulated`, ccTypeName, `(popr, true)`)
|
||||
p.P(`size2 := `, protoPkg.Use(), `.Size(p)`)
|
||||
p.P(`data, err := `, protoPkg.Use(), `.Marshal(p)`)
|
||||
p.P(`dAtA, err := `, protoPkg.Use(), `.Marshal(p)`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`t.Fatalf("seed = %d, err = %v", seed, err)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`size := p.`, sizeName, `()`)
|
||||
p.P(`if len(data) != size {`)
|
||||
p.P(`if len(dAtA) != size {`)
|
||||
p.In()
|
||||
p.P(`t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(data))`)
|
||||
p.P(`t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`if size2 != size {`)
|
||||
|
||||
9
vendor/github.com/gogo/protobuf/plugin/stringer/stringer.go
generated
vendored
9
vendor/github.com/gogo/protobuf/plugin/stringer/stringer.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -126,6 +128,7 @@ func (p *stringer) Generate(file *generator.FileDescriptor) {
|
||||
stringsPkg := p.NewImport("strings")
|
||||
reflectPkg := p.NewImport("reflect")
|
||||
sortKeysPkg := p.NewImport("github.com/gogo/protobuf/sortkeys")
|
||||
protoPkg := p.NewImport("github.com/gogo/protobuf/proto")
|
||||
for _, message := range file.Messages() {
|
||||
if !gogoproto.IsStringer(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
continue
|
||||
@@ -222,9 +225,9 @@ func (p *stringer) Generate(file *generator.FileDescriptor) {
|
||||
}
|
||||
if message.DescriptorProto.HasExtension() {
|
||||
if gogoproto.HasExtensionsMap(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
p.P("`XXX_extensions:` + proto.StringFromExtensionsMap(this.XXX_extensions) + `,`,")
|
||||
p.P("`XXX_InternalExtensions:` + ", protoPkg.Use(), ".StringFromInternalExtension(this) + `,`,")
|
||||
} else {
|
||||
p.P("`XXX_extensions:` + proto.StringFromExtensionsBytes(this.XXX_extensions) + `,`,")
|
||||
p.P("`XXX_extensions:` + ", protoPkg.Use(), ".StringFromExtensionsBytes(this.XXX_extensions) + `,`,")
|
||||
}
|
||||
}
|
||||
if gogoproto.HasUnrecognized(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
|
||||
4
vendor/github.com/gogo/protobuf/plugin/stringer/stringertest.go
generated
vendored
4
vendor/github.com/gogo/protobuf/plugin/stringer/stringertest.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
|
||||
70
vendor/github.com/gogo/protobuf/plugin/testgen/testgen.go
generated
vendored
70
vendor/github.com/gogo/protobuf/plugin/testgen/testgen.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -61,16 +63,16 @@ given to the testgen plugin, will generate the following test code:
|
||||
func TestAProto(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedA(popr, false)
|
||||
data, err := github_com_gogo_protobuf_proto.Marshal(p)
|
||||
dAtA, err := github_com_gogo_protobuf_proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &A{}
|
||||
if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
|
||||
if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for i := range data {
|
||||
data[i] = byte(popr.Intn(256))
|
||||
for i := range dAtA {
|
||||
dAtA[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
|
||||
@@ -89,11 +91,11 @@ given to the testgen plugin, will generate the following test code:
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
data, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
|
||||
dAtA, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(data)
|
||||
total += len(dAtA)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
@@ -103,11 +105,11 @@ given to the testgen plugin, will generate the following test code:
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
data, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedA(popr, false))
|
||||
dAtA, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedA(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = data
|
||||
datas[i] = dAtA
|
||||
}
|
||||
msg := &A{}
|
||||
b.ResetTimer()
|
||||
@@ -144,9 +146,9 @@ given to the testgen plugin, will generate the following test code:
|
||||
func TestAProtoText(t *testing2.T) {
|
||||
popr := math_rand2.New(math_rand2.NewSource(time2.Now().UnixNano()))
|
||||
p := NewPopulatedA(popr, true)
|
||||
data := github_com_gogo_protobuf_proto1.MarshalTextString(p)
|
||||
dAtA := github_com_gogo_protobuf_proto1.MarshalTextString(p)
|
||||
msg := &A{}
|
||||
if err := github_com_gogo_protobuf_proto1.UnmarshalText(data, msg); err != nil {
|
||||
if err := github_com_gogo_protobuf_proto1.UnmarshalText(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
@@ -160,9 +162,9 @@ given to the testgen plugin, will generate the following test code:
|
||||
func TestAProtoCompactText(t *testing2.T) {
|
||||
popr := math_rand2.New(math_rand2.NewSource(time2.Now().UnixNano()))
|
||||
p := NewPopulatedA(popr, true)
|
||||
data := github_com_gogo_protobuf_proto1.CompactTextString(p)
|
||||
dAtA := github_com_gogo_protobuf_proto1.CompactTextString(p)
|
||||
msg := &A{}
|
||||
if err := github_com_gogo_protobuf_proto1.UnmarshalText(data, msg); err != nil {
|
||||
if err := github_com_gogo_protobuf_proto1.UnmarshalText(dAtA, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
@@ -285,23 +287,23 @@ func (p *testProto) Generate(imports generator.PluginImports, file *generator.Fi
|
||||
p.P(`seed := `, timePkg.Use(), `.Now().UnixNano()`)
|
||||
p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(seed))`)
|
||||
p.P(`p := NewPopulated`, ccTypeName, `(popr, false)`)
|
||||
p.P(`data, err := `, protoPkg.Use(), `.Marshal(p)`)
|
||||
p.P(`dAtA, err := `, protoPkg.Use(), `.Marshal(p)`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`t.Fatalf("seed = %d, err = %v", seed, err)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`msg := &`, ccTypeName, `{}`)
|
||||
p.P(`if err := `, protoPkg.Use(), `.Unmarshal(data, msg); err != nil {`)
|
||||
p.P(`if err := `, protoPkg.Use(), `.Unmarshal(dAtA, msg); err != nil {`)
|
||||
p.In()
|
||||
p.P(`t.Fatalf("seed = %d, err = %v", seed, err)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`littlefuzz := make([]byte, len(data))`)
|
||||
p.P(`copy(littlefuzz, data)`)
|
||||
p.P(`for i := range data {`)
|
||||
p.P(`littlefuzz := make([]byte, len(dAtA))`)
|
||||
p.P(`copy(littlefuzz, dAtA)`)
|
||||
p.P(`for i := range dAtA {`)
|
||||
p.In()
|
||||
p.P(`data[i] = byte(popr.Intn(256))`)
|
||||
p.P(`dAtA[i] = byte(popr.Intn(256))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
if gogoproto.HasVerboseEqual(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
@@ -346,27 +348,27 @@ func (p *testProto) Generate(imports generator.PluginImports, file *generator.Fi
|
||||
} else {
|
||||
p.P(`size := p.Size()`)
|
||||
}
|
||||
p.P(`data := make([]byte, size)`)
|
||||
p.P(`for i := range data {`)
|
||||
p.P(`dAtA := make([]byte, size)`)
|
||||
p.P(`for i := range dAtA {`)
|
||||
p.In()
|
||||
p.P(`data[i] = byte(popr.Intn(256))`)
|
||||
p.P(`dAtA[i] = byte(popr.Intn(256))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`_, err := p.MarshalTo(data)`)
|
||||
p.P(`_, err := p.MarshalTo(dAtA)`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`t.Fatalf("seed = %d, err = %v", seed, err)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`msg := &`, ccTypeName, `{}`)
|
||||
p.P(`if err := `, protoPkg.Use(), `.Unmarshal(data, msg); err != nil {`)
|
||||
p.P(`if err := `, protoPkg.Use(), `.Unmarshal(dAtA, msg); err != nil {`)
|
||||
p.In()
|
||||
p.P(`t.Fatalf("seed = %d, err = %v", seed, err)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`for i := range data {`)
|
||||
p.P(`for i := range dAtA {`)
|
||||
p.In()
|
||||
p.P(`data[i] = byte(popr.Intn(256))`)
|
||||
p.P(`dAtA[i] = byte(popr.Intn(256))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
if gogoproto.HasVerboseEqual(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
@@ -402,13 +404,13 @@ func (p *testProto) Generate(imports generator.PluginImports, file *generator.Fi
|
||||
p.P(`b.ResetTimer()`)
|
||||
p.P(`for i := 0; i < b.N; i++ {`)
|
||||
p.In()
|
||||
p.P(`data, err := `, protoPkg.Use(), `.Marshal(pops[i%10000])`)
|
||||
p.P(`dAtA, err := `, protoPkg.Use(), `.Marshal(pops[i%10000])`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`panic(err)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`total += len(data)`)
|
||||
p.P(`total += len(dAtA)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`b.SetBytes(int64(total / b.N))`)
|
||||
@@ -423,13 +425,13 @@ func (p *testProto) Generate(imports generator.PluginImports, file *generator.Fi
|
||||
p.P(`datas := make([][]byte, 10000)`)
|
||||
p.P(`for i := 0; i < 10000; i++ {`)
|
||||
p.In()
|
||||
p.P(`data, err := `, protoPkg.Use(), `.Marshal(NewPopulated`, ccTypeName, `(popr, false))`)
|
||||
p.P(`dAtA, err := `, protoPkg.Use(), `.Marshal(NewPopulated`, ccTypeName, `(popr, false))`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`panic(err)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`datas[i] = data`)
|
||||
p.P(`datas[i] = dAtA`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`msg := &`, ccTypeName, `{}`)
|
||||
@@ -543,9 +545,9 @@ func (p *testText) Generate(imports generator.PluginImports, file *generator.Fil
|
||||
p.P(`seed := `, timePkg.Use(), `.Now().UnixNano()`)
|
||||
p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(seed))`)
|
||||
p.P(`p := NewPopulated`, ccTypeName, `(popr, true)`)
|
||||
p.P(`data := `, protoPkg.Use(), `.MarshalTextString(p)`)
|
||||
p.P(`dAtA := `, protoPkg.Use(), `.MarshalTextString(p)`)
|
||||
p.P(`msg := &`, ccTypeName, `{}`)
|
||||
p.P(`if err := `, protoPkg.Use(), `.UnmarshalText(data, msg); err != nil {`)
|
||||
p.P(`if err := `, protoPkg.Use(), `.UnmarshalText(dAtA, msg); err != nil {`)
|
||||
p.In()
|
||||
p.P(`t.Fatalf("seed = %d, err = %v", seed, err)`)
|
||||
p.Out()
|
||||
@@ -571,9 +573,9 @@ func (p *testText) Generate(imports generator.PluginImports, file *generator.Fil
|
||||
p.P(`seed := `, timePkg.Use(), `.Now().UnixNano()`)
|
||||
p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(seed))`)
|
||||
p.P(`p := NewPopulated`, ccTypeName, `(popr, true)`)
|
||||
p.P(`data := `, protoPkg.Use(), `.CompactTextString(p)`)
|
||||
p.P(`dAtA := `, protoPkg.Use(), `.CompactTextString(p)`)
|
||||
p.P(`msg := &`, ccTypeName, `{}`)
|
||||
p.P(`if err := `, protoPkg.Use(), `.UnmarshalText(data, msg); err != nil {`)
|
||||
p.P(`if err := `, protoPkg.Use(), `.UnmarshalText(dAtA, msg); err != nil {`)
|
||||
p.In()
|
||||
p.P(`t.Fatalf("seed = %d, err = %v", seed, err)`)
|
||||
p.Out()
|
||||
|
||||
4
vendor/github.com/gogo/protobuf/plugin/union/union.go
generated
vendored
4
vendor/github.com/gogo/protobuf/plugin/union/union.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
|
||||
4
vendor/github.com/gogo/protobuf/plugin/union/uniontest.go
generated
vendored
4
vendor/github.com/gogo/protobuf/plugin/union/uniontest.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
|
||||
268
vendor/github.com/gogo/protobuf/plugin/unmarshal/unmarshal.go
generated
vendored
268
vendor/github.com/gogo/protobuf/plugin/unmarshal/unmarshal.go
generated
vendored
@@ -1,4 +1,6 @@
|
||||
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
|
||||
// Protocol Buffers for Go with Gadgets
|
||||
//
|
||||
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
// http://github.com/gogo/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -73,8 +75,8 @@ The following message:
|
||||
|
||||
given to the unmarshal plugin, will generate the following code:
|
||||
|
||||
func (m *B) Unmarshal(data []byte) error {
|
||||
l := len(data)
|
||||
func (m *B) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
@@ -82,7 +84,7 @@ given to the unmarshal plugin, will generate the following code:
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[iNdEx]
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
@@ -101,7 +103,7 @@ given to the unmarshal plugin, will generate the following code:
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[iNdEx]
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
@@ -112,7 +114,7 @@ given to the unmarshal plugin, will generate the following code:
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if err := m.A.Unmarshal(data[iNdEx:postIndex]); err != nil {
|
||||
if err := m.A.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
@@ -125,7 +127,7 @@ given to the unmarshal plugin, will generate the following code:
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[iNdEx]
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
@@ -137,7 +139,7 @@ given to the unmarshal plugin, will generate the following code:
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.G = append(m.G, github_com_gogo_protobuf_test_custom.Uint128{})
|
||||
if err := m.G[len(m.G)-1].Unmarshal(data[iNdEx:postIndex]); err != nil {
|
||||
if err := m.G[len(m.G)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
@@ -151,14 +153,14 @@ given to the unmarshal plugin, will generate the following code:
|
||||
}
|
||||
}
|
||||
iNdEx -= sizeOfWire
|
||||
skippy, err := skip(data[iNdEx:])
|
||||
skippy, err := skip(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.XXX_unrecognized = append(m.XXX_unrecognized, data[iNdEx:iNdEx+skippy]...)
|
||||
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
@@ -191,6 +193,7 @@ type unmarshal struct {
|
||||
ioPkg generator.Single
|
||||
mathPkg generator.Single
|
||||
unsafePkg generator.Single
|
||||
typesPkg generator.Single
|
||||
localName string
|
||||
}
|
||||
|
||||
@@ -226,7 +229,7 @@ func (p *unmarshal) decodeVarint(varName string, typName string) {
|
||||
p.P(`return `, p.ioPkg.Use(), `.ErrUnexpectedEOF`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`b := data[iNdEx]`)
|
||||
p.P(`b := dAtA[iNdEx]`)
|
||||
p.P(`iNdEx++`)
|
||||
p.P(varName, ` |= (`, typName, `(b) & 0x7F) << shift`)
|
||||
p.P(`if b < 0x80 {`)
|
||||
@@ -245,10 +248,10 @@ func (p *unmarshal) decodeFixed32(varName string, typeName string) {
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`iNdEx += 4`)
|
||||
p.P(varName, ` = `, typeName, `(data[iNdEx-4])`)
|
||||
p.P(varName, ` |= `, typeName, `(data[iNdEx-3]) << 8`)
|
||||
p.P(varName, ` |= `, typeName, `(data[iNdEx-2]) << 16`)
|
||||
p.P(varName, ` |= `, typeName, `(data[iNdEx-1]) << 24`)
|
||||
p.P(varName, ` = `, typeName, `(dAtA[iNdEx-4])`)
|
||||
p.P(varName, ` |= `, typeName, `(dAtA[iNdEx-3]) << 8`)
|
||||
p.P(varName, ` |= `, typeName, `(dAtA[iNdEx-2]) << 16`)
|
||||
p.P(varName, ` |= `, typeName, `(dAtA[iNdEx-1]) << 24`)
|
||||
}
|
||||
|
||||
func (p *unmarshal) unsafeFixed32(varName string, typeName string) {
|
||||
@@ -257,7 +260,7 @@ func (p *unmarshal) unsafeFixed32(varName string, typeName string) {
|
||||
p.P(`return `, p.ioPkg.Use(), `.ErrUnexpectedEOF`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(varName, ` = *(*`, typeName, `)(`, p.unsafePkg.Use(), `.Pointer(&data[iNdEx]))`)
|
||||
p.P(varName, ` = *(*`, typeName, `)(`, p.unsafePkg.Use(), `.Pointer(&dAtA[iNdEx]))`)
|
||||
p.P(`iNdEx += 4`)
|
||||
}
|
||||
|
||||
@@ -268,14 +271,14 @@ func (p *unmarshal) decodeFixed64(varName string, typeName string) {
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`iNdEx += 8`)
|
||||
p.P(varName, ` = `, typeName, `(data[iNdEx-8])`)
|
||||
p.P(varName, ` |= `, typeName, `(data[iNdEx-7]) << 8`)
|
||||
p.P(varName, ` |= `, typeName, `(data[iNdEx-6]) << 16`)
|
||||
p.P(varName, ` |= `, typeName, `(data[iNdEx-5]) << 24`)
|
||||
p.P(varName, ` |= `, typeName, `(data[iNdEx-4]) << 32`)
|
||||
p.P(varName, ` |= `, typeName, `(data[iNdEx-3]) << 40`)
|
||||
p.P(varName, ` |= `, typeName, `(data[iNdEx-2]) << 48`)
|
||||
p.P(varName, ` |= `, typeName, `(data[iNdEx-1]) << 56`)
|
||||
p.P(varName, ` = `, typeName, `(dAtA[iNdEx-8])`)
|
||||
p.P(varName, ` |= `, typeName, `(dAtA[iNdEx-7]) << 8`)
|
||||
p.P(varName, ` |= `, typeName, `(dAtA[iNdEx-6]) << 16`)
|
||||
p.P(varName, ` |= `, typeName, `(dAtA[iNdEx-5]) << 24`)
|
||||
p.P(varName, ` |= `, typeName, `(dAtA[iNdEx-4]) << 32`)
|
||||
p.P(varName, ` |= `, typeName, `(dAtA[iNdEx-3]) << 40`)
|
||||
p.P(varName, ` |= `, typeName, `(dAtA[iNdEx-2]) << 48`)
|
||||
p.P(varName, ` |= `, typeName, `(dAtA[iNdEx-1]) << 56`)
|
||||
}
|
||||
|
||||
func (p *unmarshal) unsafeFixed64(varName string, typeName string) {
|
||||
@@ -284,11 +287,11 @@ func (p *unmarshal) unsafeFixed64(varName string, typeName string) {
|
||||
p.P(`return `, p.ioPkg.Use(), `.ErrUnexpectedEOF`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(varName, ` = *(*`, typeName, `)(`, p.unsafePkg.Use(), `.Pointer(&data[iNdEx]))`)
|
||||
p.P(varName, ` = *(*`, typeName, `)(`, p.unsafePkg.Use(), `.Pointer(&dAtA[iNdEx]))`)
|
||||
p.P(`iNdEx += 8`)
|
||||
}
|
||||
|
||||
func (p *unmarshal) mapField(varName string, field *descriptor.FieldDescriptorProto) {
|
||||
func (p *unmarshal) mapField(varName string, customType bool, field *descriptor.FieldDescriptorProto) {
|
||||
switch field.GetType() {
|
||||
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
|
||||
p.P(`var `, varName, `temp uint64`)
|
||||
@@ -334,7 +337,7 @@ func (p *unmarshal) mapField(varName string, field *descriptor.FieldDescriptorPr
|
||||
p.P(`}`)
|
||||
cast, _ := p.GoType(nil, field)
|
||||
cast = strings.Replace(cast, "*", "", 1)
|
||||
p.P(varName, ` := `, cast, `(data[iNdEx:postStringIndex`, varName, `])`)
|
||||
p.P(varName, ` := `, cast, `(dAtA[iNdEx:postStringIndex`, varName, `])`)
|
||||
p.P(`iNdEx = postStringIndex`, varName)
|
||||
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
|
||||
p.P(`var mapmsglen int`)
|
||||
@@ -357,8 +360,17 @@ func (p *unmarshal) mapField(varName string, field *descriptor.FieldDescriptorPr
|
||||
p.P(`}`)
|
||||
desc := p.ObjectNamed(field.GetTypeName())
|
||||
msgname := p.TypeName(desc)
|
||||
p.P(varName, ` := &`, msgname, `{}`)
|
||||
p.P(`if err := `, varName, `.Unmarshal(data[iNdEx:postmsgIndex]); err != nil {`)
|
||||
buf := `dAtA[iNdEx:postmsgIndex]`
|
||||
if gogoproto.IsStdTime(field) {
|
||||
p.P(varName, ` := new(time.Time)`)
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdTimeUnmarshal(`, varName, `, `, buf, `); err != nil {`)
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
p.P(varName, ` := new(time.Duration)`)
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdDurationUnmarshal(`, varName, `, `, buf, `); err != nil {`)
|
||||
} else {
|
||||
p.P(varName, ` := &`, msgname, `{}`)
|
||||
p.P(`if err := `, varName, `.Unmarshal(`, buf, `); err != nil {`)
|
||||
}
|
||||
p.In()
|
||||
p.P(`return err`)
|
||||
p.Out()
|
||||
@@ -379,8 +391,22 @@ func (p *unmarshal) mapField(varName string, field *descriptor.FieldDescriptorPr
|
||||
p.P(`return `, p.ioPkg.Use(), `.ErrUnexpectedEOF`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(varName, ` := make([]byte, mapbyteLen)`)
|
||||
p.P(`copy(`, varName, `, data[iNdEx:postbytesIndex])`)
|
||||
if customType {
|
||||
_, ctyp, err := generator.GetCustomType(field)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
p.P(`var `, varName, `1 `, ctyp)
|
||||
p.P(`var `, varName, ` = &`, varName, `1`)
|
||||
p.P(`if err := `, varName, `.Unmarshal(dAtA[iNdEx:postbytesIndex]); err != nil {`)
|
||||
p.In()
|
||||
p.P(`return err`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else {
|
||||
p.P(varName, ` := make([]byte, mapbyteLen)`)
|
||||
p.P(`copy(`, varName, `, dAtA[iNdEx:postbytesIndex])`)
|
||||
}
|
||||
p.P(`iNdEx = postbytesIndex`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_UINT32:
|
||||
p.P(`var `, varName, ` uint32`)
|
||||
@@ -640,13 +666,13 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
if oneof {
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{`, typ, `(data[iNdEx:postIndex])}`)
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{`, typ, `(dAtA[iNdEx:postIndex])}`)
|
||||
} else if repeated {
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, `, typ, `(data[iNdEx:postIndex]))`)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, `, typ, `(dAtA[iNdEx:postIndex]))`)
|
||||
} else if proto3 || !nullable {
|
||||
p.P(`m.`, fieldname, ` = `, typ, `(data[iNdEx:postIndex])`)
|
||||
p.P(`m.`, fieldname, ` = `, typ, `(dAtA[iNdEx:postIndex])`)
|
||||
} else {
|
||||
p.P(`s := `, typ, `(data[iNdEx:postIndex])`)
|
||||
p.P(`s := `, typ, `(dAtA[iNdEx:postIndex])`)
|
||||
p.P(`m.`, fieldname, ` = &s`)
|
||||
}
|
||||
p.P(`iNdEx = postIndex`)
|
||||
@@ -669,8 +695,27 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
if oneof {
|
||||
p.P(`v := &`, msgname, `{}`)
|
||||
p.P(`if err := v.Unmarshal(data[iNdEx:postIndex]); err != nil {`)
|
||||
buf := `dAtA[iNdEx:postIndex]`
|
||||
if gogoproto.IsStdTime(field) {
|
||||
if nullable {
|
||||
p.P(`v := new(time.Time)`)
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdTimeUnmarshal(v, `, buf, `); err != nil {`)
|
||||
} else {
|
||||
p.P(`v := time.Time{}`)
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdTimeUnmarshal(&v, `, buf, `); err != nil {`)
|
||||
}
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
if nullable {
|
||||
p.P(`v := new(time.Duration)`)
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdDurationUnmarshal(v, `, buf, `); err != nil {`)
|
||||
} else {
|
||||
p.P(`v := time.Duration(0)`)
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdDurationUnmarshal(&v, `, buf, `); err != nil {`)
|
||||
}
|
||||
} else {
|
||||
p.P(`v := &`, msgname, `{}`)
|
||||
p.P(`if err := v.Unmarshal(`, buf, `); err != nil {`)
|
||||
}
|
||||
p.In()
|
||||
p.P(`return err`)
|
||||
p.Out()
|
||||
@@ -694,13 +739,13 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
p.RecordTypeUse(m.ValueAliasField.GetTypeName())
|
||||
|
||||
nullable, valuegoTyp, valuegoAliasTyp = generator.GoMapValueTypes(field, m.ValueField, valuegoTyp, valuegoAliasTyp)
|
||||
if gogoproto.IsStdTime(field) || gogoproto.IsStdDuration(field) {
|
||||
valuegoTyp = valuegoAliasTyp
|
||||
}
|
||||
|
||||
p.P(`var keykey uint64`)
|
||||
p.decodeVarint("keykey", "uint64")
|
||||
p.mapField("mapkey", m.KeyAliasField)
|
||||
p.P(`var valuekey uint64`)
|
||||
p.decodeVarint("valuekey", "uint64")
|
||||
p.mapField("mapvalue", m.ValueAliasField)
|
||||
p.mapField("mapkey", false, m.KeyAliasField)
|
||||
p.P(`if m.`, fieldname, ` == nil {`)
|
||||
p.In()
|
||||
p.P(`m.`, fieldname, ` = make(`, m.GoType, `)`)
|
||||
@@ -713,20 +758,76 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
s += `[` + keygoAliasTyp + `(mapkey)]`
|
||||
}
|
||||
v := `mapvalue`
|
||||
if m.ValueField.IsMessage() && !nullable {
|
||||
if (m.ValueField.IsMessage() || gogoproto.IsCustomType(field)) && !nullable {
|
||||
v = `*` + v
|
||||
}
|
||||
if valuegoTyp != valuegoAliasTyp {
|
||||
v = `((` + valuegoAliasTyp + `)(` + v + `))`
|
||||
}
|
||||
p.P(`if iNdEx < postIndex {`)
|
||||
p.In()
|
||||
p.P(`var valuekey uint64`)
|
||||
p.decodeVarint("valuekey", "uint64")
|
||||
p.mapField("mapvalue", gogoproto.IsCustomType(field), m.ValueAliasField)
|
||||
p.P(s, ` = `, v)
|
||||
p.Out()
|
||||
p.P(`} else {`)
|
||||
p.In()
|
||||
if gogoproto.IsStdTime(field) {
|
||||
p.P(`var mapvalue = new(time.Time)`)
|
||||
if nullable {
|
||||
p.P(s, ` = mapvalue`)
|
||||
} else {
|
||||
p.P(s, ` = *mapvalue`)
|
||||
}
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
p.P(`var mapvalue = new(time.Duration)`)
|
||||
if nullable {
|
||||
p.P(s, ` = mapvalue`)
|
||||
} else {
|
||||
p.P(s, ` = *mapvalue`)
|
||||
}
|
||||
} else {
|
||||
p.P(`var mapvalue `, valuegoAliasTyp)
|
||||
p.P(s, ` = mapvalue`)
|
||||
}
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
if nullable {
|
||||
if gogoproto.IsStdTime(field) {
|
||||
if nullable {
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, new(time.Time))`)
|
||||
} else {
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, time.Time{})`)
|
||||
}
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
if nullable {
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, new(time.Duration))`)
|
||||
} else {
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, time.Duration(0))`)
|
||||
}
|
||||
} else if nullable {
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, &`, msgname, `{})`)
|
||||
} else {
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, `, msgname, `{})`)
|
||||
}
|
||||
p.P(`if err := m.`, fieldname, `[len(m.`, fieldname, `)-1].Unmarshal(data[iNdEx:postIndex]); err != nil {`)
|
||||
varName := `m.` + fieldname + `[len(m.` + fieldname + `)-1]`
|
||||
buf := `dAtA[iNdEx:postIndex]`
|
||||
if gogoproto.IsStdTime(field) {
|
||||
if nullable {
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdTimeUnmarshal(`, varName, `,`, buf, `); err != nil {`)
|
||||
} else {
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdTimeUnmarshal(&(`, varName, `),`, buf, `); err != nil {`)
|
||||
}
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
if nullable {
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdDurationUnmarshal(`, varName, `,`, buf, `); err != nil {`)
|
||||
} else {
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdDurationUnmarshal(&(`, varName, `),`, buf, `); err != nil {`)
|
||||
}
|
||||
} else {
|
||||
p.P(`if err := `, varName, `.Unmarshal(`, buf, `); err != nil {`)
|
||||
}
|
||||
p.In()
|
||||
p.P(`return err`)
|
||||
p.Out()
|
||||
@@ -734,16 +835,34 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
} else if nullable {
|
||||
p.P(`if m.`, fieldname, ` == nil {`)
|
||||
p.In()
|
||||
p.P(`m.`, fieldname, ` = &`, msgname, `{}`)
|
||||
if gogoproto.IsStdTime(field) {
|
||||
p.P(`m.`, fieldname, ` = new(time.Time)`)
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
p.P(`m.`, fieldname, ` = new(time.Duration)`)
|
||||
} else {
|
||||
p.P(`m.`, fieldname, ` = &`, msgname, `{}`)
|
||||
}
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`if err := m.`, fieldname, `.Unmarshal(data[iNdEx:postIndex]); err != nil {`)
|
||||
if gogoproto.IsStdTime(field) {
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdTimeUnmarshal(m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`)
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdDurationUnmarshal(m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`)
|
||||
} else {
|
||||
p.P(`if err := m.`, fieldname, `.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {`)
|
||||
}
|
||||
p.In()
|
||||
p.P(`return err`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else {
|
||||
p.P(`if err := m.`, fieldname, `.Unmarshal(data[iNdEx:postIndex]); err != nil {`)
|
||||
if gogoproto.IsStdTime(field) {
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdTimeUnmarshal(&m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`)
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
p.P(`if err := `, p.typesPkg.Use(), `.StdDurationUnmarshal(&m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`)
|
||||
} else {
|
||||
p.P(`if err := m.`, fieldname, `.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {`)
|
||||
}
|
||||
p.In()
|
||||
p.P(`return err`)
|
||||
p.Out()
|
||||
@@ -767,13 +886,13 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
if !gogoproto.IsCustomType(field) {
|
||||
if oneof {
|
||||
p.P(`v := make([]byte, postIndex-iNdEx)`)
|
||||
p.P(`copy(v, data[iNdEx:postIndex])`)
|
||||
p.P(`copy(v, dAtA[iNdEx:postIndex])`)
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, make([]byte, postIndex-iNdEx))`)
|
||||
p.P(`copy(m.`, fieldname, `[len(m.`, fieldname, `)-1], data[iNdEx:postIndex])`)
|
||||
p.P(`copy(m.`, fieldname, `[len(m.`, fieldname, `)-1], dAtA[iNdEx:postIndex])`)
|
||||
} else {
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `[:0] , data[iNdEx:postIndex]...)`)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `[:0] , dAtA[iNdEx:postIndex]...)`)
|
||||
p.P(`if m.`, fieldname, ` == nil {`)
|
||||
p.In()
|
||||
p.P(`m.`, fieldname, ` = []byte{}`)
|
||||
@@ -788,7 +907,7 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
if oneof {
|
||||
p.P(`var vv `, ctyp)
|
||||
p.P(`v := &vv`)
|
||||
p.P(`if err := v.Unmarshal(data[iNdEx:postIndex]); err != nil {`)
|
||||
p.P(`if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {`)
|
||||
p.In()
|
||||
p.P(`return err`)
|
||||
p.Out()
|
||||
@@ -797,7 +916,7 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
} else if repeated {
|
||||
p.P(`var v `, ctyp)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
p.P(`if err := m.`, fieldname, `[len(m.`, fieldname, `)-1].Unmarshal(data[iNdEx:postIndex]); err != nil {`)
|
||||
p.P(`if err := m.`, fieldname, `[len(m.`, fieldname, `)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {`)
|
||||
p.In()
|
||||
p.P(`return err`)
|
||||
p.Out()
|
||||
@@ -805,13 +924,13 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
} else if nullable {
|
||||
p.P(`var v `, ctyp)
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
p.P(`if err := m.`, fieldname, `.Unmarshal(data[iNdEx:postIndex]); err != nil {`)
|
||||
p.P(`if err := m.`, fieldname, `.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {`)
|
||||
p.In()
|
||||
p.P(`return err`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else {
|
||||
p.P(`if err := m.`, fieldname, `.Unmarshal(data[iNdEx:postIndex]); err != nil {`)
|
||||
p.P(`if err := m.`, fieldname, `.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {`)
|
||||
p.In()
|
||||
p.P(`return err`)
|
||||
p.Out()
|
||||
@@ -968,6 +1087,7 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
p.ioPkg = p.NewImport("io")
|
||||
p.mathPkg = p.NewImport("math")
|
||||
p.unsafePkg = p.NewImport("unsafe")
|
||||
p.typesPkg = p.NewImport("github.com/gogo/protobuf/types")
|
||||
fmtPkg := p.NewImport("fmt")
|
||||
protoPkg := p.NewImport("github.com/gogo/protobuf/proto")
|
||||
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
|
||||
@@ -1008,12 +1128,12 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
}
|
||||
rfCount := len(rfMap)
|
||||
|
||||
p.P(`func (m *`, ccTypeName, `) Unmarshal(data []byte) error {`)
|
||||
p.P(`func (m *`, ccTypeName, `) Unmarshal(dAtA []byte) error {`)
|
||||
p.In()
|
||||
if rfCount > 0 {
|
||||
p.P(`var hasFields [`, strconv.Itoa(1+(rfCount-1)/64), `]uint64`)
|
||||
}
|
||||
p.P(`l := len(data)`)
|
||||
p.P(`l := len(dAtA)`)
|
||||
p.P(`iNdEx := 0`)
|
||||
p.P(`for iNdEx < l {`)
|
||||
p.In()
|
||||
@@ -1044,12 +1164,16 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
if field.OneofIndex != nil {
|
||||
errFieldname = p.GetOneOfFieldName(message, field)
|
||||
}
|
||||
packed := field.IsPacked()
|
||||
possiblyPacked := field.IsScalar() && field.IsRepeated()
|
||||
p.P(`case `, strconv.Itoa(int(field.GetNumber())), `:`)
|
||||
p.In()
|
||||
wireType := field.WireType()
|
||||
if packed {
|
||||
p.P(`if wireType == `, strconv.Itoa(proto.WireBytes), `{`)
|
||||
if possiblyPacked {
|
||||
p.P(`if wireType == `, strconv.Itoa(wireType), `{`)
|
||||
p.In()
|
||||
p.field(file, message, field, fieldname, false)
|
||||
p.Out()
|
||||
p.P(`} else if wireType == `, strconv.Itoa(proto.WireBytes), `{`)
|
||||
p.In()
|
||||
p.P(`var packedLen int`)
|
||||
p.decodeVarint("packedLen", "int")
|
||||
@@ -1070,10 +1194,6 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.Out()
|
||||
p.P(`} else if wireType == `, strconv.Itoa(wireType), `{`)
|
||||
p.In()
|
||||
p.field(file, message, field, fieldname, false)
|
||||
p.Out()
|
||||
p.P(`} else {`)
|
||||
p.In()
|
||||
p.P(`return ` + fmtPkg.Use() + `.Errorf("proto: wrong wireType = %d for field ` + errFieldname + `", wireType)`)
|
||||
@@ -1119,7 +1239,7 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`iNdEx-=sizeOfWire`)
|
||||
p.P(`skippy, err := skip`, p.localName+`(data[iNdEx:])`)
|
||||
p.P(`skippy, err := skip`, p.localName+`(dAtA[iNdEx:])`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`return err`)
|
||||
@@ -1135,14 +1255,14 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
p.P(`return `, p.ioPkg.Use(), `.ErrUnexpectedEOF`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(protoPkg.Use(), `.AppendExtension(m, int32(fieldNum), data[iNdEx:iNdEx+skippy])`)
|
||||
p.P(protoPkg.Use(), `.AppendExtension(m, int32(fieldNum), dAtA[iNdEx:iNdEx+skippy])`)
|
||||
p.P(`iNdEx += skippy`)
|
||||
p.Out()
|
||||
p.P(`} else {`)
|
||||
p.In()
|
||||
}
|
||||
p.P(`iNdEx=preIndex`)
|
||||
p.P(`skippy, err := skip`, p.localName, `(data[iNdEx:])`)
|
||||
p.P(`skippy, err := skip`, p.localName, `(dAtA[iNdEx:])`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`return err`)
|
||||
@@ -1159,7 +1279,7 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
if gogoproto.HasUnrecognized(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
p.P(`m.XXX_unrecognized = append(m.XXX_unrecognized, data[iNdEx:iNdEx+skippy]...)`)
|
||||
p.P(`m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)`)
|
||||
}
|
||||
p.P(`iNdEx += skippy`)
|
||||
p.Out()
|
||||
@@ -1206,8 +1326,8 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
return
|
||||
}
|
||||
|
||||
p.P(`func skip` + p.localName + `(data []byte) (n int, err error) {
|
||||
l := len(data)
|
||||
p.P(`func skip` + p.localName + `(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
@@ -1218,7 +1338,7 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
if iNdEx >= l {
|
||||
return 0, ` + p.ioPkg.Use() + `.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[iNdEx]
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
@@ -1236,7 +1356,7 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
return 0, ` + p.ioPkg.Use() + `.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx++
|
||||
if data[iNdEx-1] < 0x80 {
|
||||
if dAtA[iNdEx-1] < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -1253,7 +1373,7 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
if iNdEx >= l {
|
||||
return 0, ` + p.ioPkg.Use() + `.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[iNdEx]
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
length |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
@@ -1276,7 +1396,7 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
if iNdEx >= l {
|
||||
return 0, ` + p.ioPkg.Use() + `.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[iNdEx]
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
innerWire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
@@ -1287,7 +1407,7 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
if innerWireType == 4 {
|
||||
break
|
||||
}
|
||||
next, err := skip` + p.localName + `(data[start:])
|
||||
next, err := skip` + p.localName + `(dAtA[start:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user