Update etcd client to 3.3.9
This commit is contained in:
2
vendor/github.com/gogo/protobuf/plugin/compare/compare.go
generated
vendored
2
vendor/github.com/gogo/protobuf/plugin/compare/compare.go
generated
vendored
@@ -512,7 +512,7 @@ func (p *plugin) generateMessage(file *generator.FileDescriptor, message *genera
|
||||
p.In()
|
||||
|
||||
p.generateMsgNullAndTypeCheck(ccTypeName)
|
||||
vanity.TurnOffNullableForNativeTypesWithoutDefaultsOnly(field)
|
||||
vanity.TurnOffNullableForNativeTypes(field)
|
||||
p.generateField(file, message, field)
|
||||
|
||||
p.P(`return 0`)
|
||||
|
||||
2
vendor/github.com/gogo/protobuf/plugin/equal/equal.go
generated
vendored
2
vendor/github.com/gogo/protobuf/plugin/equal/equal.go
generated
vendored
@@ -627,7 +627,7 @@ func (p *plugin) generateMessage(file *generator.FileDescriptor, message *genera
|
||||
p.In()
|
||||
|
||||
p.generateMsgNullAndTypeCheck(ccTypeName, verbose)
|
||||
vanity.TurnOffNullableForNativeTypesWithoutDefaultsOnly(field)
|
||||
vanity.TurnOffNullableForNativeTypes(field)
|
||||
p.generateField(file, message, field, verbose)
|
||||
|
||||
if verbose {
|
||||
|
||||
45
vendor/github.com/gogo/protobuf/plugin/gostring/gostring.go
generated
vendored
45
vendor/github.com/gogo/protobuf/plugin/gostring/gostring.go
generated
vendored
@@ -98,11 +98,12 @@ package gostring
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogo/protobuf/gogoproto"
|
||||
"github.com/gogo/protobuf/protoc-gen-gogo/generator"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gogo/protobuf/gogoproto"
|
||||
"github.com/gogo/protobuf/protoc-gen-gogo/generator"
|
||||
)
|
||||
|
||||
type gostring struct {
|
||||
@@ -229,8 +230,22 @@ func (p *gostring) Generate(file *generator.FileDescriptor) {
|
||||
p.P(`if this.`, fieldname, ` != nil {`)
|
||||
p.In()
|
||||
}
|
||||
if nullable || repeated {
|
||||
if nullable {
|
||||
p.P(`s = append(s, "`, fieldname, `: " + `, fmtPkg.Use(), `.Sprintf("%#v", this.`, fieldname, `) + ",\n")`)
|
||||
} else if repeated {
|
||||
if nullable {
|
||||
p.P(`s = append(s, "`, fieldname, `: " + `, fmtPkg.Use(), `.Sprintf("%#v", this.`, fieldname, `) + ",\n")`)
|
||||
} else {
|
||||
goTyp, _ := p.GoType(message, field)
|
||||
goTyp = strings.Replace(goTyp, "[]", "", 1)
|
||||
p.P("vs := make([]*", goTyp, ", len(this.", fieldname, "))")
|
||||
p.P("for i := range vs {")
|
||||
p.In()
|
||||
p.P("vs[i] = &this.", fieldname, "[i]")
|
||||
p.Out()
|
||||
p.P("}")
|
||||
p.P(`s = append(s, "`, fieldname, `: " + `, fmtPkg.Use(), `.Sprintf("%#v", vs) + ",\n")`)
|
||||
}
|
||||
} else {
|
||||
p.P(`s = append(s, "`, fieldname, `: " + `, stringsPkg.Use(), `.Replace(this.`, fieldname, `.GoString()`, ",`&`,``,1)", ` + ",\n")`)
|
||||
}
|
||||
@@ -246,7 +261,7 @@ func (p *gostring) Generate(file *generator.FileDescriptor) {
|
||||
if field.IsEnum() {
|
||||
if nullable && !repeated && !proto3 {
|
||||
goTyp, _ := p.GoType(message, field)
|
||||
p.P(`s = append(s, "`, fieldname, `: " + valueToGoString`, p.localName, `(this.`, fieldname, `,"`, packageName, ".", generator.GoTypeToName(goTyp), `"`, `) + ",\n")`)
|
||||
p.P(`s = append(s, "`, fieldname, `: " + valueToGoString`, p.localName, `(this.`, fieldname, `,"`, generator.GoTypeToName(goTyp), `"`, `) + ",\n")`)
|
||||
} else {
|
||||
p.P(`s = append(s, "`, fieldname, `: " + `, fmtPkg.Use(), `.Sprintf("%#v", this.`, fieldname, `) + ",\n")`)
|
||||
}
|
||||
@@ -285,7 +300,6 @@ func (p *gostring) Generate(file *generator.FileDescriptor) {
|
||||
}
|
||||
|
||||
p.P(`s = append(s, "}")`)
|
||||
//outStr += strings.Join([]string{" + `}`", `}`, `,", "`, ")"}, "")
|
||||
p.P(`return `, stringsPkg.Use(), `.Join(s, "")`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
@@ -304,20 +318,15 @@ func (p *gostring) Generate(file *generator.FileDescriptor) {
|
||||
p.P(`return "nil"`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
outFlds := []string{}
|
||||
fieldname := p.GetOneOfFieldName(message, field)
|
||||
if field.IsMessage() || p.IsGroup(field) {
|
||||
tmp := strings.Join([]string{"`", fieldname, ":` + "}, "")
|
||||
tmp += strings.Join([]string{fmtPkg.Use(), `.Sprintf("%#v", this.`, fieldname, `)`}, "")
|
||||
outFlds = append(outFlds, tmp)
|
||||
} else {
|
||||
tmp := strings.Join([]string{"`", fieldname, ":` + "}, "")
|
||||
tmp += strings.Join([]string{fmtPkg.Use(), `.Sprintf("%#v", this.`, fieldname, ")"}, "")
|
||||
outFlds = append(outFlds, tmp)
|
||||
}
|
||||
outStr := strings.Join([]string{"s := ", stringsPkg.Use(), ".Join([]string{`&", packageName, ".", ccTypeName, "{` + \n"}, "")
|
||||
outStr += strings.Join(outFlds, ",\n")
|
||||
outStr += strings.Join([]string{" + `}`", `}`, `,", "`, ")"}, "")
|
||||
outStr := strings.Join([]string{
|
||||
"s := ",
|
||||
stringsPkg.Use(), ".Join([]string{`&", packageName, ".", ccTypeName, "{` + \n",
|
||||
"`", fieldname, ":` + ", fmtPkg.Use(), `.Sprintf("%#v", this.`, fieldname, `)`,
|
||||
" + `}`",
|
||||
`}`,
|
||||
`,", "`,
|
||||
`)`}, "")
|
||||
p.P(outStr)
|
||||
p.P(`return s`)
|
||||
p.Out()
|
||||
|
||||
2
vendor/github.com/gogo/protobuf/plugin/gostring/gostringtest.go
generated
vendored
2
vendor/github.com/gogo/protobuf/plugin/gostring/gostringtest.go
generated
vendored
@@ -74,7 +74,7 @@ func (p *test) Generate(imports generator.PluginImports, file *generator.FileDes
|
||||
p.P(`_, err := `, parserPkg.Use(), `.ParseExpr(s1)`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`panic(err)`)
|
||||
p.P(`t.Fatal(err)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.Out()
|
||||
|
||||
464
vendor/github.com/gogo/protobuf/plugin/marshalto/marshalto.go
generated
vendored
464
vendor/github.com/gogo/protobuf/plugin/marshalto/marshalto.go
generated
vendored
@@ -172,28 +172,20 @@ type marshalto struct {
|
||||
*generator.Generator
|
||||
generator.PluginImports
|
||||
atleastOne bool
|
||||
unsafePkg generator.Single
|
||||
errorsPkg generator.Single
|
||||
protoPkg generator.Single
|
||||
sortKeysPkg generator.Single
|
||||
mathPkg generator.Single
|
||||
typesPkg generator.Single
|
||||
binaryPkg generator.Single
|
||||
localName string
|
||||
unsafe bool
|
||||
}
|
||||
|
||||
func NewMarshal() *marshalto {
|
||||
return &marshalto{}
|
||||
}
|
||||
|
||||
func NewUnsafeMarshal() *marshalto {
|
||||
return &marshalto{unsafe: true}
|
||||
}
|
||||
|
||||
func (p *marshalto) Name() string {
|
||||
if p.unsafe {
|
||||
return "unsafemarshaler"
|
||||
}
|
||||
return "marshalto"
|
||||
}
|
||||
|
||||
@@ -202,11 +194,13 @@ 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(p.binaryPkg.Use(), `.LittleEndian.PutUint64(dAtA[i:], uint64(`, strings.Join(varName, ""), `))`)
|
||||
p.P(`i += 8`)
|
||||
}
|
||||
|
||||
func (p *marshalto) callFixed32(varName ...string) {
|
||||
p.P(`i = encodeFixed32`, p.localName, `(dAtA, i, uint32(`, strings.Join(varName, ""), `))`)
|
||||
p.P(p.binaryPkg.Use(), `.LittleEndian.PutUint32(dAtA[i:], uint32(`, strings.Join(varName, ""), `))`)
|
||||
p.P(`i += 4`)
|
||||
}
|
||||
|
||||
func (p *marshalto) callVarint(varName ...string) {
|
||||
@@ -225,46 +219,6 @@ func (p *marshalto) encodeVarint(varName string) {
|
||||
p.P(`i++`)
|
||||
}
|
||||
|
||||
func (p *marshalto) encodeFixed64(varName string) {
|
||||
p.P(`dAtA[i] = uint8(`, varName, `)`)
|
||||
p.P(`i++`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 8)`)
|
||||
p.P(`i++`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 16)`)
|
||||
p.P(`i++`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 24)`)
|
||||
p.P(`i++`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 32)`)
|
||||
p.P(`i++`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 40)`)
|
||||
p.P(`i++`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 48)`)
|
||||
p.P(`i++`)
|
||||
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(`i+=8`)
|
||||
}
|
||||
|
||||
func (p *marshalto) encodeFixed32(varName string) {
|
||||
p.P(`dAtA[i] = uint8(`, varName, `)`)
|
||||
p.P(`i++`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 8)`)
|
||||
p.P(`i++`)
|
||||
p.P(`dAtA[i] = uint8(`, varName, ` >> 16)`)
|
||||
p.P(`i++`)
|
||||
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(`i+=4`)
|
||||
}
|
||||
|
||||
func (p *marshalto) encodeKey(fieldNumber int32, wireType int) {
|
||||
x := uint32(fieldNumber)<<3 | uint32(wireType)
|
||||
i := 0
|
||||
@@ -428,132 +382,68 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
}
|
||||
switch *field.Type {
|
||||
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
|
||||
if !p.unsafe || gogoproto.IsCastType(field) {
|
||||
if packed {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `) * 8`)
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.P(`f`, numGen.Next(), ` := `, p.mathPkg.Use(), `.Float64bits(float64(num))`)
|
||||
p.encodeFixed64("f" + numGen.Current())
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.P(`f`, numGen.Next(), ` := `, p.mathPkg.Use(), `.Float64bits(float64(num))`)
|
||||
p.encodeFixed64("f" + numGen.Current())
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
p.P(`if m.`, fieldname, ` != 0 {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed64(p.mathPkg.Use(), `.Float64bits(float64(m.`+fieldname, `))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if !nullable {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed64(p.mathPkg.Use(), `.Float64bits(float64(m.`+fieldname, `))`)
|
||||
} else {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed64(p.mathPkg.Use(), `.Float64bits(float64(*m.`+fieldname, `))`)
|
||||
}
|
||||
if packed {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `) * 8`)
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.P(`f`, numGen.Next(), ` := `, p.mathPkg.Use(), `.Float64bits(float64(num))`)
|
||||
p.callFixed64("f" + numGen.Current())
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.P(`f`, numGen.Next(), ` := `, p.mathPkg.Use(), `.Float64bits(float64(num))`)
|
||||
p.callFixed64("f" + numGen.Current())
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
p.P(`if m.`, fieldname, ` != 0 {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed64(p.mathPkg.Use(), `.Float64bits(float64(m.`+fieldname, `))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if !nullable {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed64(p.mathPkg.Use(), `.Float64bits(float64(m.`+fieldname, `))`)
|
||||
} else {
|
||||
if packed {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `) * 8`)
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.unsafeFixed64("num", "float64")
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed64("num", "float64")
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
p.P(`if m.`, fieldname, ` != 0 {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed64(`m.`+fieldname, "float64")
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if !nullable {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed64(`m.`+fieldname, "float64")
|
||||
} else {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed64(`*m.`+fieldname, `float64`)
|
||||
}
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed64(p.mathPkg.Use(), `.Float64bits(float64(*m.`+fieldname, `))`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
|
||||
if !p.unsafe || gogoproto.IsCastType(field) {
|
||||
if packed {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `) * 4`)
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.P(`f`, numGen.Next(), ` := `, p.mathPkg.Use(), `.Float32bits(float32(num))`)
|
||||
p.encodeFixed32("f" + numGen.Current())
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.P(`f`, numGen.Next(), ` := `, p.mathPkg.Use(), `.Float32bits(float32(num))`)
|
||||
p.encodeFixed32("f" + numGen.Current())
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
p.P(`if m.`, fieldname, ` != 0 {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed32(p.mathPkg.Use(), `.Float32bits(float32(m.`+fieldname, `))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if !nullable {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed32(p.mathPkg.Use(), `.Float32bits(float32(m.`+fieldname, `))`)
|
||||
} else {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed32(p.mathPkg.Use(), `.Float32bits(float32(*m.`+fieldname, `))`)
|
||||
}
|
||||
if packed {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `) * 4`)
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.P(`f`, numGen.Next(), ` := `, p.mathPkg.Use(), `.Float32bits(float32(num))`)
|
||||
p.callFixed32("f" + numGen.Current())
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.P(`f`, numGen.Next(), ` := `, p.mathPkg.Use(), `.Float32bits(float32(num))`)
|
||||
p.callFixed32("f" + numGen.Current())
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
p.P(`if m.`, fieldname, ` != 0 {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed32(p.mathPkg.Use(), `.Float32bits(float32(m.`+fieldname, `))`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if !nullable {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed32(p.mathPkg.Use(), `.Float32bits(float32(m.`+fieldname, `))`)
|
||||
} else {
|
||||
if packed {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `) * 4`)
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.unsafeFixed32("num", "float32")
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed32("num", "float32")
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
p.P(`if m.`, fieldname, ` != 0 {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed32(`m.`+fieldname, `float32`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if !nullable {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed32(`m.`+fieldname, `float32`)
|
||||
} else {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed32(`*m.`+fieldname, "float32")
|
||||
}
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed32(p.mathPkg.Use(), `.Float32bits(float32(*m.`+fieldname, `))`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_INT64,
|
||||
descriptor.FieldDescriptorProto_TYPE_UINT64,
|
||||
@@ -610,137 +500,65 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_FIXED64,
|
||||
descriptor.FieldDescriptorProto_TYPE_SFIXED64:
|
||||
if !p.unsafe {
|
||||
if packed {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `) * 8`)
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeFixed64("num")
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.encodeFixed64("num")
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
p.P(`if m.`, fieldname, ` != 0 {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed64("m." + fieldname)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if !nullable {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed64("m." + fieldname)
|
||||
} else {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed64("*m." + fieldname)
|
||||
}
|
||||
if packed {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `) * 8`)
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.callFixed64("num")
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed64("num")
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
p.P(`if m.`, fieldname, ` != 0 {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed64("m." + fieldname)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if !nullable {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed64("m." + fieldname)
|
||||
} else {
|
||||
typeName := "int64"
|
||||
if *field.Type == descriptor.FieldDescriptorProto_TYPE_FIXED64 {
|
||||
typeName = "uint64"
|
||||
}
|
||||
if packed {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `) * 8`)
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.unsafeFixed64("num", typeName)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed64("num", typeName)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
p.P(`if m.`, fieldname, ` != 0 {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed64("m."+fieldname, typeName)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if !nullable {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed64("m."+fieldname, typeName)
|
||||
} else {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed64("*m."+fieldname, typeName)
|
||||
}
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed64("*m." + fieldname)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_FIXED32,
|
||||
descriptor.FieldDescriptorProto_TYPE_SFIXED32:
|
||||
if !p.unsafe {
|
||||
if packed {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `) * 4`)
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeFixed32("num")
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.encodeFixed32("num")
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
p.P(`if m.`, fieldname, ` != 0 {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed32("m." + fieldname)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if !nullable {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed32("m." + fieldname)
|
||||
} else {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed32("*m." + fieldname)
|
||||
}
|
||||
if packed {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `) * 4`)
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.callFixed32("num")
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed32("num")
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
p.P(`if m.`, fieldname, ` != 0 {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed32("m." + fieldname)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if !nullable {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed32("m." + fieldname)
|
||||
} else {
|
||||
typeName := "int32"
|
||||
if *field.Type == descriptor.FieldDescriptorProto_TYPE_FIXED32 {
|
||||
typeName = "uint32"
|
||||
}
|
||||
if packed {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callVarint(`len(m.`, fieldname, `) * 4`)
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.unsafeFixed32("num", typeName)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if repeated {
|
||||
p.P(`for _, num := range m.`, fieldname, ` {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed32("num", typeName)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if proto3 {
|
||||
p.P(`if m.`, fieldname, ` != 0 {`)
|
||||
p.In()
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed32("m."+fieldname, typeName)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
} else if !nullable {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed32("m."+fieldname, typeName)
|
||||
} else {
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.unsafeFixed32("*m."+fieldname, typeName)
|
||||
}
|
||||
p.encodeKey(fieldNumber, wireType)
|
||||
p.callFixed32("*m." + fieldname)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_BOOL:
|
||||
if packed {
|
||||
@@ -1240,6 +1058,7 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi
|
||||
func (p *marshalto) Generate(file *generator.FileDescriptor) {
|
||||
numGen := NewNumGen()
|
||||
p.PluginImports = generator.NewPluginImports(p.Generator)
|
||||
|
||||
p.atleastOne = false
|
||||
p.localName = generator.FileName(file)
|
||||
|
||||
@@ -1249,8 +1068,8 @@ func (p *marshalto) Generate(file *generator.FileDescriptor) {
|
||||
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
|
||||
p.protoPkg = p.NewImport("github.com/golang/protobuf/proto")
|
||||
}
|
||||
p.unsafePkg = p.NewImport("unsafe")
|
||||
p.errorsPkg = p.NewImport("errors")
|
||||
p.binaryPkg = p.NewImport("encoding/binary")
|
||||
p.typesPkg = p.NewImport("github.com/gogo/protobuf/types")
|
||||
|
||||
for _, message := range file.Messages() {
|
||||
@@ -1258,21 +1077,9 @@ func (p *marshalto) Generate(file *generator.FileDescriptor) {
|
||||
continue
|
||||
}
|
||||
ccTypeName := generator.CamelCaseSlice(message.TypeName())
|
||||
if p.unsafe {
|
||||
if !gogoproto.IsUnsafeMarshaler(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
continue
|
||||
}
|
||||
if gogoproto.IsMarshaler(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
panic(fmt.Sprintf("unsafe_marshaler and marshalto enabled for %v", ccTypeName))
|
||||
}
|
||||
}
|
||||
if !p.unsafe {
|
||||
if !gogoproto.IsMarshaler(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
continue
|
||||
}
|
||||
if gogoproto.IsUnsafeMarshaler(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
panic(fmt.Sprintf("unsafe_marshaler and marshalto enabled for %v", ccTypeName))
|
||||
}
|
||||
if !gogoproto.IsMarshaler(file.FileDescriptorProto, message.DescriptorProto) &&
|
||||
!gogoproto.IsUnsafeMarshaler(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
continue
|
||||
}
|
||||
p.atleastOne = true
|
||||
|
||||
@@ -1367,7 +1174,7 @@ func (p *marshalto) Generate(file *generator.FileDescriptor) {
|
||||
p.P(`func (m *`, ccTypeName, `) MarshalTo(dAtA []byte) (int, error) {`)
|
||||
p.In()
|
||||
p.P(`i := 0`)
|
||||
vanity.TurnOffNullableForNativeTypesWithoutDefaultsOnly(field)
|
||||
vanity.TurnOffNullableForNativeTypes(field)
|
||||
p.generateField(false, numGen, file, message, field)
|
||||
p.P(`return i, nil`)
|
||||
p.Out()
|
||||
@@ -1376,30 +1183,6 @@ func (p *marshalto) Generate(file *generator.FileDescriptor) {
|
||||
}
|
||||
|
||||
if p.atleastOne {
|
||||
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(`return offset+8`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
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(`return offset+4`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
p.P(`func encodeVarint`, p.localName, `(dAtA []byte, offset int, v uint64) int {`)
|
||||
p.In()
|
||||
p.P(`for v >= 1<<7 {`)
|
||||
@@ -1419,5 +1202,4 @@ func (p *marshalto) Generate(file *generator.FileDescriptor) {
|
||||
|
||||
func init() {
|
||||
generator.RegisterPlugin(NewMarshal())
|
||||
generator.RegisterPlugin(NewUnsafeMarshal())
|
||||
}
|
||||
|
||||
2
vendor/github.com/gogo/protobuf/plugin/populate/populate.go
generated
vendored
2
vendor/github.com/gogo/protobuf/plugin/populate/populate.go
generated
vendored
@@ -667,7 +667,7 @@ func (p *plugin) Generate(file *generator.FileDescriptor) {
|
||||
p.P(`func NewPopulated`, ccTypeName, `(r randy`, p.localName, `, easy bool) *`, ccTypeName, ` {`)
|
||||
p.In()
|
||||
p.P(`this := &`, ccTypeName, `{}`)
|
||||
vanity.TurnOffNullableForNativeTypesWithoutDefaultsOnly(f)
|
||||
vanity.TurnOffNullableForNativeTypes(f)
|
||||
p.GenerateField(file, message, f)
|
||||
p.P(`return this`)
|
||||
p.Out()
|
||||
|
||||
2
vendor/github.com/gogo/protobuf/plugin/size/size.go
generated
vendored
2
vendor/github.com/gogo/protobuf/plugin/size/size.go
generated
vendored
@@ -652,7 +652,7 @@ func (p *size) Generate(file *generator.FileDescriptor) {
|
||||
p.In()
|
||||
p.P(`var l int`)
|
||||
p.P(`_ = l`)
|
||||
vanity.TurnOffNullableForNativeTypesWithoutDefaultsOnly(f)
|
||||
vanity.TurnOffNullableForNativeTypes(f)
|
||||
p.generateField(false, file, message, f, sizeName)
|
||||
p.P(`return n`)
|
||||
p.Out()
|
||||
|
||||
19
vendor/github.com/gogo/protobuf/plugin/testgen/testgen.go
generated
vendored
19
vendor/github.com/gogo/protobuf/plugin/testgen/testgen.go
generated
vendored
@@ -270,7 +270,6 @@ func (p *testProto) Generate(imports generator.PluginImports, file *generator.Fi
|
||||
testingPkg := imports.NewImport("testing")
|
||||
randPkg := imports.NewImport("math/rand")
|
||||
timePkg := imports.NewImport("time")
|
||||
unsafePkg := imports.NewImport("unsafe")
|
||||
protoPkg := imports.NewImport("github.com/gogo/protobuf/proto")
|
||||
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
|
||||
protoPkg = imports.NewImport("github.com/golang/protobuf/proto")
|
||||
@@ -280,21 +279,11 @@ func (p *testProto) Generate(imports generator.PluginImports, file *generator.Fi
|
||||
if message.DescriptorProto.GetOptions().GetMapEntry() {
|
||||
continue
|
||||
}
|
||||
hasUnsafe := gogoproto.IsUnsafeMarshaler(file.FileDescriptorProto, message.DescriptorProto) ||
|
||||
gogoproto.IsUnsafeUnmarshaler(file.FileDescriptorProto, message.DescriptorProto)
|
||||
if gogoproto.HasTestGen(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
used = true
|
||||
|
||||
p.P(`func Test`, ccTypeName, `Proto(t *`, testingPkg.Use(), `.T) {`)
|
||||
p.In()
|
||||
if hasUnsafe {
|
||||
p.P(`var bigendian uint32 = 0x01020304`)
|
||||
p.P(`if *(*byte)(`, unsafePkg.Use(), `.Pointer(&bigendian)) == 1 {`)
|
||||
p.In()
|
||||
p.P(`t.Skip("unsafe does not work on big endian architectures")`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
}
|
||||
p.P(`seed := `, timePkg.Use(), `.Now().UnixNano()`)
|
||||
p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(seed))`)
|
||||
p.P(`p := NewPopulated`, ccTypeName, `(popr, false)`)
|
||||
@@ -351,14 +340,6 @@ func (p *testProto) Generate(imports generator.PluginImports, file *generator.Fi
|
||||
if gogoproto.IsMarshaler(file.FileDescriptorProto, message.DescriptorProto) || gogoproto.IsUnsafeMarshaler(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
p.P(`func Test`, ccTypeName, `MarshalTo(t *`, testingPkg.Use(), `.T) {`)
|
||||
p.In()
|
||||
if hasUnsafe {
|
||||
p.P(`var bigendian uint32 = 0x01020304`)
|
||||
p.P(`if *(*byte)(`, unsafePkg.Use(), `.Pointer(&bigendian)) == 1 {`)
|
||||
p.In()
|
||||
p.P(`t.Skip("unsafe does not work on big endian architectures")`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
}
|
||||
p.P(`seed := `, timePkg.Use(), `.Now().UnixNano()`)
|
||||
p.P(`popr := `, randPkg.Use(), `.New(`, randPkg.Use(), `.NewSource(seed))`)
|
||||
p.P(`p := NewPopulated`, ccTypeName, `(popr, false)`)
|
||||
|
||||
506
vendor/github.com/gogo/protobuf/plugin/unmarshal/unmarshal.go
generated
vendored
506
vendor/github.com/gogo/protobuf/plugin/unmarshal/unmarshal.go
generated
vendored
@@ -187,13 +187,12 @@ import (
|
||||
|
||||
type unmarshal struct {
|
||||
*generator.Generator
|
||||
unsafe bool
|
||||
generator.PluginImports
|
||||
atleastOne bool
|
||||
ioPkg generator.Single
|
||||
mathPkg generator.Single
|
||||
unsafePkg generator.Single
|
||||
typesPkg generator.Single
|
||||
binaryPkg generator.Single
|
||||
localName string
|
||||
}
|
||||
|
||||
@@ -201,14 +200,7 @@ func NewUnmarshal() *unmarshal {
|
||||
return &unmarshal{}
|
||||
}
|
||||
|
||||
func NewUnsafeUnmarshal() *unmarshal {
|
||||
return &unmarshal{unsafe: true}
|
||||
}
|
||||
|
||||
func (p *unmarshal) Name() string {
|
||||
if p.unsafe {
|
||||
return "unsafeunmarshaler"
|
||||
}
|
||||
return "unmarshal"
|
||||
}
|
||||
|
||||
@@ -247,20 +239,7 @@ func (p *unmarshal) decodeFixed32(varName string, typeName string) {
|
||||
p.P(`return `, p.ioPkg.Use(), `.ErrUnexpectedEOF`)
|
||||
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`)
|
||||
}
|
||||
|
||||
func (p *unmarshal) unsafeFixed32(varName string, typeName string) {
|
||||
p.P(`if iNdEx + 4 > l {`)
|
||||
p.In()
|
||||
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.binaryPkg.Use(), `.LittleEndian.Uint32(dAtA[iNdEx:]))`)
|
||||
p.P(`iNdEx += 4`)
|
||||
}
|
||||
|
||||
@@ -270,25 +249,71 @@ func (p *unmarshal) decodeFixed64(varName string, typeName string) {
|
||||
p.P(`return `, p.ioPkg.Use(), `.ErrUnexpectedEOF`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(varName, ` = `, typeName, `(`, p.binaryPkg.Use(), `.LittleEndian.Uint64(dAtA[iNdEx:]))`)
|
||||
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`)
|
||||
}
|
||||
|
||||
func (p *unmarshal) unsafeFixed64(varName string, typeName string) {
|
||||
p.P(`if iNdEx + 8 > l {`)
|
||||
p.In()
|
||||
p.P(`return `, p.ioPkg.Use(), `.ErrUnexpectedEOF`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(varName, ` = *(*`, typeName, `)(`, p.unsafePkg.Use(), `.Pointer(&dAtA[iNdEx]))`)
|
||||
p.P(`iNdEx += 8`)
|
||||
func (p *unmarshal) declareMapField(varName string, nullable bool, customType bool, field *descriptor.FieldDescriptorProto) {
|
||||
switch field.GetType() {
|
||||
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
|
||||
p.P(`var `, varName, ` float64`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
|
||||
p.P(`var `, varName, ` float32`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_INT64:
|
||||
p.P(`var `, varName, ` int64`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_UINT64:
|
||||
p.P(`var `, varName, ` uint64`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_INT32:
|
||||
p.P(`var `, varName, ` int32`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_FIXED64:
|
||||
p.P(`var `, varName, ` uint64`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_FIXED32:
|
||||
p.P(`var `, varName, ` uint32`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_BOOL:
|
||||
p.P(`var `, varName, ` bool`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_STRING:
|
||||
cast, _ := p.GoType(nil, field)
|
||||
cast = strings.Replace(cast, "*", "", 1)
|
||||
p.P(`var `, varName, ` `, cast)
|
||||
case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
|
||||
if gogoproto.IsStdTime(field) {
|
||||
p.P(varName, ` := new(time.Time)`)
|
||||
} else if gogoproto.IsStdDuration(field) {
|
||||
p.P(varName, ` := new(time.Duration)`)
|
||||
} else {
|
||||
desc := p.ObjectNamed(field.GetTypeName())
|
||||
msgname := p.TypeName(desc)
|
||||
if nullable {
|
||||
p.P(`var `, varName, ` *`, msgname)
|
||||
} else {
|
||||
p.P(varName, ` := &`, msgname, `{}`)
|
||||
}
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_BYTES:
|
||||
if customType {
|
||||
_, ctyp, err := generator.GetCustomType(field)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
p.P(`var `, varName, `1 `, ctyp)
|
||||
p.P(`var `, varName, ` = &`, varName, `1`)
|
||||
} else {
|
||||
p.P(varName, ` := []byte{}`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_UINT32:
|
||||
p.P(`var `, varName, ` uint32`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_ENUM:
|
||||
typName := p.TypeName(p.ObjectNamed(field.GetTypeName()))
|
||||
p.P(`var `, varName, ` `, typName)
|
||||
case descriptor.FieldDescriptorProto_TYPE_SFIXED32:
|
||||
p.P(`var `, varName, ` int32`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_SFIXED64:
|
||||
p.P(`var `, varName, ` int64`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_SINT32:
|
||||
p.P(`var `, varName, ` int32`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_SINT64:
|
||||
p.P(`var `, varName, ` int64`)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *unmarshal) mapField(varName string, customType bool, field *descriptor.FieldDescriptorProto) {
|
||||
@@ -296,30 +321,25 @@ func (p *unmarshal) mapField(varName string, customType bool, field *descriptor.
|
||||
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
|
||||
p.P(`var `, varName, `temp uint64`)
|
||||
p.decodeFixed64(varName+"temp", "uint64")
|
||||
p.P(varName, ` := `, p.mathPkg.Use(), `.Float64frombits(`, varName, `temp)`)
|
||||
p.P(varName, ` = `, p.mathPkg.Use(), `.Float64frombits(`, varName, `temp)`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
|
||||
p.P(`var `, varName, `temp uint32`)
|
||||
p.decodeFixed32(varName+"temp", "uint32")
|
||||
p.P(varName, ` := `, p.mathPkg.Use(), `.Float32frombits(`, varName, `temp)`)
|
||||
p.P(varName, ` = `, p.mathPkg.Use(), `.Float32frombits(`, varName, `temp)`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_INT64:
|
||||
p.P(`var `, varName, ` int64`)
|
||||
p.decodeVarint(varName, "int64")
|
||||
case descriptor.FieldDescriptorProto_TYPE_UINT64:
|
||||
p.P(`var `, varName, ` uint64`)
|
||||
p.decodeVarint(varName, "uint64")
|
||||
case descriptor.FieldDescriptorProto_TYPE_INT32:
|
||||
p.P(`var `, varName, ` int32`)
|
||||
p.decodeVarint(varName, "int32")
|
||||
case descriptor.FieldDescriptorProto_TYPE_FIXED64:
|
||||
p.P(`var `, varName, ` uint64`)
|
||||
p.decodeFixed64(varName, "uint64")
|
||||
case descriptor.FieldDescriptorProto_TYPE_FIXED32:
|
||||
p.P(`var `, varName, ` uint32`)
|
||||
p.decodeFixed32(varName, "uint32")
|
||||
case descriptor.FieldDescriptorProto_TYPE_BOOL:
|
||||
p.P(`var `, varName, `temp int`)
|
||||
p.decodeVarint(varName+"temp", "int")
|
||||
p.P(varName, ` := bool(`, varName, `temp != 0)`)
|
||||
p.P(varName, ` = bool(`, varName, `temp != 0)`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_STRING:
|
||||
p.P(`var stringLen`, varName, ` uint64`)
|
||||
p.decodeVarint("stringLen"+varName, "uint64")
|
||||
@@ -337,7 +357,7 @@ func (p *unmarshal) mapField(varName string, customType bool, field *descriptor.
|
||||
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`)
|
||||
@@ -358,17 +378,15 @@ func (p *unmarshal) mapField(varName string, customType bool, field *descriptor.
|
||||
p.P(`return `, p.ioPkg.Use(), `.ErrUnexpectedEOF`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
desc := p.ObjectNamed(field.GetTypeName())
|
||||
msgname := p.TypeName(desc)
|
||||
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, `{}`)
|
||||
desc := p.ObjectNamed(field.GetTypeName())
|
||||
msgname := p.TypeName(desc)
|
||||
p.P(varName, ` = &`, msgname, `{}`)
|
||||
p.P(`if err := `, varName, `.Unmarshal(`, buf, `); err != nil {`)
|
||||
}
|
||||
p.In()
|
||||
@@ -392,45 +410,35 @@ func (p *unmarshal) mapField(varName string, customType bool, field *descriptor.
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
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(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`)
|
||||
p.decodeVarint(varName, "uint32")
|
||||
case descriptor.FieldDescriptorProto_TYPE_ENUM:
|
||||
typName := p.TypeName(p.ObjectNamed(field.GetTypeName()))
|
||||
p.P(`var `, varName, ` `, typName)
|
||||
p.decodeVarint(varName, typName)
|
||||
case descriptor.FieldDescriptorProto_TYPE_SFIXED32:
|
||||
p.P(`var `, varName, ` int32`)
|
||||
p.decodeFixed32(varName, "int32")
|
||||
case descriptor.FieldDescriptorProto_TYPE_SFIXED64:
|
||||
p.P(`var `, varName, ` int64`)
|
||||
p.decodeFixed64(varName, "int64")
|
||||
case descriptor.FieldDescriptorProto_TYPE_SINT32:
|
||||
p.P(`var `, varName, `temp int32`)
|
||||
p.decodeVarint(varName+"temp", "int32")
|
||||
p.P(varName, `temp = int32((uint32(`, varName, `temp) >> 1) ^ uint32(((`, varName, `temp&1)<<31)>>31))`)
|
||||
p.P(varName, ` := int32(`, varName, `temp)`)
|
||||
p.P(varName, ` = int32(`, varName, `temp)`)
|
||||
case descriptor.FieldDescriptorProto_TYPE_SINT64:
|
||||
p.P(`var `, varName, `temp uint64`)
|
||||
p.decodeVarint(varName+"temp", "uint64")
|
||||
p.P(varName, `temp = (`, varName, `temp >> 1) ^ uint64((int64(`, varName, `temp&1)<<63)>>63)`)
|
||||
p.P(varName, ` := int64(`, varName, `temp)`)
|
||||
p.P(varName, ` = int64(`, varName, `temp)`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,68 +460,32 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
oneof := field.OneofIndex != nil
|
||||
switch *field.Type {
|
||||
case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
|
||||
if !p.unsafe || gogoproto.IsCastType(field) {
|
||||
p.P(`var v uint64`)
|
||||
p.decodeFixed64("v", "uint64")
|
||||
if oneof {
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{`, typ, "(", p.mathPkg.Use(), `.Float64frombits(v))}`)
|
||||
} else if repeated {
|
||||
p.P(`v2 := `, typ, "(", p.mathPkg.Use(), `.Float64frombits(v))`)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v2)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.P(`m.`, fieldname, ` = `, typ, "(", p.mathPkg.Use(), `.Float64frombits(v))`)
|
||||
} else {
|
||||
p.P(`v2 := `, typ, "(", p.mathPkg.Use(), `.Float64frombits(v))`)
|
||||
p.P(`m.`, fieldname, ` = &v2`)
|
||||
}
|
||||
p.P(`var v uint64`)
|
||||
p.decodeFixed64("v", "uint64")
|
||||
if oneof {
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{`, typ, "(", p.mathPkg.Use(), `.Float64frombits(v))}`)
|
||||
} else if repeated {
|
||||
p.P(`v2 := `, typ, "(", p.mathPkg.Use(), `.Float64frombits(v))`)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v2)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.P(`m.`, fieldname, ` = `, typ, "(", p.mathPkg.Use(), `.Float64frombits(v))`)
|
||||
} else {
|
||||
if oneof {
|
||||
p.P(`var v float64`)
|
||||
p.unsafeFixed64("v", "float64")
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v float64`)
|
||||
p.unsafeFixed64("v", "float64")
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.unsafeFixed64(`m.`+fieldname, "float64")
|
||||
} else {
|
||||
p.P(`var v float64`)
|
||||
p.unsafeFixed64("v", "float64")
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
p.P(`v2 := `, typ, "(", p.mathPkg.Use(), `.Float64frombits(v))`)
|
||||
p.P(`m.`, fieldname, ` = &v2`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_FLOAT:
|
||||
if !p.unsafe || gogoproto.IsCastType(field) {
|
||||
p.P(`var v uint32`)
|
||||
p.decodeFixed32("v", "uint32")
|
||||
if oneof {
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{`, typ, "(", p.mathPkg.Use(), `.Float32frombits(v))}`)
|
||||
} else if repeated {
|
||||
p.P(`v2 := `, typ, "(", p.mathPkg.Use(), `.Float32frombits(v))`)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v2)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.P(`m.`, fieldname, ` = `, typ, "(", p.mathPkg.Use(), `.Float32frombits(v))`)
|
||||
} else {
|
||||
p.P(`v2 := `, typ, "(", p.mathPkg.Use(), `.Float32frombits(v))`)
|
||||
p.P(`m.`, fieldname, ` = &v2`)
|
||||
}
|
||||
p.P(`var v uint32`)
|
||||
p.decodeFixed32("v", "uint32")
|
||||
if oneof {
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{`, typ, "(", p.mathPkg.Use(), `.Float32frombits(v))}`)
|
||||
} else if repeated {
|
||||
p.P(`v2 := `, typ, "(", p.mathPkg.Use(), `.Float32frombits(v))`)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v2)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.P(`m.`, fieldname, ` = `, typ, "(", p.mathPkg.Use(), `.Float32frombits(v))`)
|
||||
} else {
|
||||
if oneof {
|
||||
p.P(`var v float32`)
|
||||
p.unsafeFixed32("v", "float32")
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v float32`)
|
||||
p.unsafeFixed32("v", "float32")
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.unsafeFixed32("m."+fieldname, "float32")
|
||||
} else {
|
||||
p.P(`var v float32`)
|
||||
p.unsafeFixed32("v", "float32")
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
p.P(`v2 := `, typ, "(", p.mathPkg.Use(), `.Float32frombits(v))`)
|
||||
p.P(`m.`, fieldname, ` = &v2`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_INT64:
|
||||
if oneof {
|
||||
@@ -567,74 +539,38 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_FIXED64:
|
||||
if !p.unsafe || gogoproto.IsCastType(field) {
|
||||
if oneof {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed64("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed64("v", typ)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.P(`m.`, fieldname, ` = 0`)
|
||||
p.decodeFixed64("m."+fieldname, typ)
|
||||
} else {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed64("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
if oneof {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed64("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed64("v", typ)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.P(`m.`, fieldname, ` = 0`)
|
||||
p.decodeFixed64("m."+fieldname, typ)
|
||||
} else {
|
||||
if oneof {
|
||||
p.P(`var v uint64`)
|
||||
p.unsafeFixed64("v", "uint64")
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v uint64`)
|
||||
p.unsafeFixed64("v", "uint64")
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.unsafeFixed64("m."+fieldname, "uint64")
|
||||
} else {
|
||||
p.P(`var v uint64`)
|
||||
p.unsafeFixed64("v", "uint64")
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed64("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_FIXED32:
|
||||
if !p.unsafe || gogoproto.IsCastType(field) {
|
||||
if oneof {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed32("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed32("v", typ)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.P(`m.`, fieldname, ` = 0`)
|
||||
p.decodeFixed32("m."+fieldname, typ)
|
||||
} else {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed32("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
if oneof {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed32("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed32("v", typ)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.P(`m.`, fieldname, ` = 0`)
|
||||
p.decodeFixed32("m."+fieldname, typ)
|
||||
} else {
|
||||
if oneof {
|
||||
p.P(`var v uint32`)
|
||||
p.unsafeFixed32("v", "uint32")
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v uint32`)
|
||||
p.unsafeFixed32("v", "uint32")
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.unsafeFixed32("m."+fieldname, "uint32")
|
||||
} else {
|
||||
p.P(`var v uint32`)
|
||||
p.unsafeFixed32("v", "uint32")
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed32("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_BOOL:
|
||||
p.P(`var v int`)
|
||||
@@ -747,20 +683,63 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
valuegoTyp = valuegoAliasTyp
|
||||
}
|
||||
|
||||
p.P(`var keykey uint64`)
|
||||
p.decodeVarint("keykey", "uint64")
|
||||
p.mapField("mapkey", false, m.KeyAliasField)
|
||||
p.P(`if m.`, fieldname, ` == nil {`)
|
||||
p.In()
|
||||
p.P(`m.`, fieldname, ` = make(`, m.GoType, `)`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
p.declareMapField("mapkey", false, false, m.KeyAliasField)
|
||||
p.declareMapField("mapvalue", nullable, gogoproto.IsCustomType(field), m.ValueAliasField)
|
||||
p.P(`for iNdEx < postIndex {`)
|
||||
p.In()
|
||||
|
||||
p.P(`entryPreIndex := iNdEx`)
|
||||
p.P(`var wire uint64`)
|
||||
p.decodeVarint("wire", "uint64")
|
||||
p.P(`fieldNum := int32(wire >> 3)`)
|
||||
|
||||
p.P(`if fieldNum == 1 {`)
|
||||
p.In()
|
||||
p.mapField("mapkey", false, m.KeyAliasField)
|
||||
p.Out()
|
||||
p.P(`} else if fieldNum == 2 {`)
|
||||
p.In()
|
||||
p.mapField("mapvalue", gogoproto.IsCustomType(field), m.ValueAliasField)
|
||||
p.Out()
|
||||
p.P(`} else {`)
|
||||
p.In()
|
||||
p.P(`iNdEx = entryPreIndex`)
|
||||
p.P(`skippy, err := skip`, p.localName, `(dAtA[iNdEx:])`)
|
||||
p.P(`if err != nil {`)
|
||||
p.In()
|
||||
p.P(`return err`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`if skippy < 0 {`)
|
||||
p.In()
|
||||
p.P(`return ErrInvalidLength`, p.localName)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`if (iNdEx + skippy) > postIndex {`)
|
||||
p.In()
|
||||
p.P(`return `, p.ioPkg.Use(), `.ErrUnexpectedEOF`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
p.P(`iNdEx += skippy`)
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
p.Out()
|
||||
p.P(`}`)
|
||||
|
||||
s := `m.` + fieldname
|
||||
if keygoTyp == keygoAliasTyp {
|
||||
s += `[mapkey]`
|
||||
} else {
|
||||
s += `[` + keygoAliasTyp + `(mapkey)]`
|
||||
}
|
||||
|
||||
v := `mapvalue`
|
||||
if (m.ValueField.IsMessage() || gogoproto.IsCustomType(field)) && !nullable {
|
||||
v = `*` + v
|
||||
@@ -768,35 +747,8 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
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 gogoproto.IsStdTime(field) {
|
||||
if nullable {
|
||||
@@ -984,74 +936,38 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_SFIXED32:
|
||||
if !p.unsafe || gogoproto.IsCastType(field) {
|
||||
if oneof {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed32("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed32("v", typ)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.P(`m.`, fieldname, ` = 0`)
|
||||
p.decodeFixed32("m."+fieldname, typ)
|
||||
} else {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed32("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
if oneof {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed32("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed32("v", typ)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.P(`m.`, fieldname, ` = 0`)
|
||||
p.decodeFixed32("m."+fieldname, typ)
|
||||
} else {
|
||||
if oneof {
|
||||
p.P(`var v int32`)
|
||||
p.unsafeFixed32("v", "int32")
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v int32`)
|
||||
p.unsafeFixed32("v", "int32")
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.unsafeFixed32("m."+fieldname, "int32")
|
||||
} else {
|
||||
p.P(`var v int32`)
|
||||
p.unsafeFixed32("v", "int32")
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed32("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_SFIXED64:
|
||||
if !p.unsafe || gogoproto.IsCastType(field) {
|
||||
if oneof {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed64("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed64("v", typ)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.P(`m.`, fieldname, ` = 0`)
|
||||
p.decodeFixed64("m."+fieldname, typ)
|
||||
} else {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed64("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
if oneof {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed64("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed64("v", typ)
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.P(`m.`, fieldname, ` = 0`)
|
||||
p.decodeFixed64("m."+fieldname, typ)
|
||||
} else {
|
||||
if oneof {
|
||||
p.P(`var v int64`)
|
||||
p.unsafeFixed64("v", "int64")
|
||||
p.P(`m.`, fieldname, ` = &`, p.OneOfTypeName(msg, field), `{v}`)
|
||||
} else if repeated {
|
||||
p.P(`var v int64`)
|
||||
p.unsafeFixed64("v", "int64")
|
||||
p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`)
|
||||
} else if proto3 || !nullable {
|
||||
p.unsafeFixed64("m."+fieldname, "int64")
|
||||
} else {
|
||||
p.P(`var v int64`)
|
||||
p.unsafeFixed64("v", "int64")
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
p.P(`var v `, typ)
|
||||
p.decodeFixed64("v", typ)
|
||||
p.P(`m.`, fieldname, ` = &v`)
|
||||
}
|
||||
case descriptor.FieldDescriptorProto_TYPE_SINT32:
|
||||
p.P(`var v `, typ)
|
||||
@@ -1090,14 +1006,11 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
p.PluginImports = generator.NewPluginImports(p.Generator)
|
||||
p.atleastOne = false
|
||||
p.localName = generator.FileName(file)
|
||||
if p.unsafe {
|
||||
p.localName += "Unsafe"
|
||||
}
|
||||
|
||||
p.ioPkg = p.NewImport("io")
|
||||
p.mathPkg = p.NewImport("math")
|
||||
p.unsafePkg = p.NewImport("unsafe")
|
||||
p.typesPkg = p.NewImport("github.com/gogo/protobuf/types")
|
||||
p.binaryPkg = p.NewImport("encoding/binary")
|
||||
fmtPkg := p.NewImport("fmt")
|
||||
protoPkg := p.NewImport("github.com/gogo/protobuf/proto")
|
||||
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
|
||||
@@ -1106,21 +1019,9 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
|
||||
for _, message := range file.Messages() {
|
||||
ccTypeName := generator.CamelCaseSlice(message.TypeName())
|
||||
if p.unsafe {
|
||||
if !gogoproto.IsUnsafeUnmarshaler(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
continue
|
||||
}
|
||||
if gogoproto.IsUnmarshaler(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
panic(fmt.Sprintf("unsafe_unmarshaler and unmarshaler enabled for %v", ccTypeName))
|
||||
}
|
||||
}
|
||||
if !p.unsafe {
|
||||
if !gogoproto.IsUnmarshaler(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
continue
|
||||
}
|
||||
if gogoproto.IsUnsafeUnmarshaler(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
panic(fmt.Sprintf("unsafe_unmarshaler and unmarshaler enabled for %v", ccTypeName))
|
||||
}
|
||||
if !gogoproto.IsUnmarshaler(file.FileDescriptorProto, message.DescriptorProto) &&
|
||||
!gogoproto.IsUnsafeUnmarshaler(file.FileDescriptorProto, message.DescriptorProto) {
|
||||
continue
|
||||
}
|
||||
if message.DescriptorProto.GetOptions().GetMapEntry() {
|
||||
continue
|
||||
@@ -1445,5 +1346,4 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
|
||||
|
||||
func init() {
|
||||
generator.RegisterPlugin(NewUnmarshal())
|
||||
generator.RegisterPlugin(NewUnsafeUnmarshal())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user