From 44902ae811dcd404a356543216250dc1b2981b06 Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Fri, 21 Sep 2018 17:36:27 -0400 Subject: [PATCH] Codegen for well-known types - Fixes #472 --- gogoproto/gogo.proto | 2 + gogoproto/helper.go | 49 + plugin/equal/equal.go | 65 +- plugin/gostring/gostring.go | 2 +- plugin/marshalto/marshalto.go | 150 +- plugin/populate/populate.go | 52 +- plugin/size/size.go | 52 +- plugin/unmarshal/unmarshal.go | 260 +++- proto/properties.go | 8 + proto/table_marshal.go | 113 ++ proto/table_unmarshal.go | 111 ++ proto/wrappers.go | 1888 ++++++++++++++++++++++++ proto/wrappers_gogo.go | 113 ++ protoc-gen-gogo/generator/generator.go | 202 ++- protoc-gen-gogo/generator/helper.go | 7 + test/stdtypes/Makefile | 3 +- test/stdtypes/stdtypes.proto | 93 ++ types/wrappers_gogo.go | 300 ++++ 18 files changed, 3391 insertions(+), 79 deletions(-) create mode 100644 proto/wrappers.go create mode 100644 proto/wrappers_gogo.go create mode 100644 types/wrappers_gogo.go diff --git a/gogoproto/gogo.proto b/gogoproto/gogo.proto index e80238f5cb..fab27b5541 100644 --- a/gogoproto/gogo.proto +++ b/gogoproto/gogo.proto @@ -143,4 +143,6 @@ extend google.protobuf.FieldOptions { optional bool stdtime = 65010; optional bool stdduration = 65011; + optional bool wktpointer = 65012; + } diff --git a/gogoproto/helper.go b/gogoproto/helper.go index aa4bbf9311..4129fcfb70 100644 --- a/gogoproto/helper.go +++ b/gogoproto/helper.go @@ -47,6 +47,55 @@ func IsStdDuration(field *google_protobuf.FieldDescriptorProto) bool { return proto.GetBoolExtension(field.Options, E_Stdduration, false) } +func IsStdDouble(field *google_protobuf.FieldDescriptorProto) bool { + return proto.GetBoolExtension(field.Options, E_Wktpointer, false) && *field.TypeName == ".google.protobuf.DoubleValue" +} + +func IsStdFloat(field *google_protobuf.FieldDescriptorProto) bool { + return proto.GetBoolExtension(field.Options, E_Wktpointer, false) && *field.TypeName == ".google.protobuf.FloatValue" +} + +func IsStdInt64(field *google_protobuf.FieldDescriptorProto) bool { + return proto.GetBoolExtension(field.Options, E_Wktpointer, false) && *field.TypeName == ".google.protobuf.Int64Value" +} + +func IsStdUInt64(field *google_protobuf.FieldDescriptorProto) bool { + return proto.GetBoolExtension(field.Options, E_Wktpointer, false) && *field.TypeName == ".google.protobuf.UInt64Value" +} + +func IsStdInt32(field *google_protobuf.FieldDescriptorProto) bool { + return proto.GetBoolExtension(field.Options, E_Wktpointer, false) && *field.TypeName == ".google.protobuf.Int32Value" +} + +func IsStdUInt32(field *google_protobuf.FieldDescriptorProto) bool { + return proto.GetBoolExtension(field.Options, E_Wktpointer, false) && *field.TypeName == ".google.protobuf.UInt32Value" +} + +func IsStdBool(field *google_protobuf.FieldDescriptorProto) bool { + return proto.GetBoolExtension(field.Options, E_Wktpointer, false) && *field.TypeName == ".google.protobuf.BoolValue" +} + +func IsStdString(field *google_protobuf.FieldDescriptorProto) bool { + return proto.GetBoolExtension(field.Options, E_Wktpointer, false) && *field.TypeName == ".google.protobuf.StringValue" +} + +func IsStdBytes(field *google_protobuf.FieldDescriptorProto) bool { + return proto.GetBoolExtension(field.Options, E_Wktpointer, false) && *field.TypeName == ".google.protobuf.BytesValue" +} + +func IsStdType(field *google_protobuf.FieldDescriptorProto) bool { + return (IsStdTime(field) || IsStdDuration(field) || + IsStdDouble(field) || IsStdFloat(field) || + IsStdInt64(field) || IsStdUInt64(field) || + IsStdInt32(field) || IsStdUInt32(field) || + IsStdBool(field) || + IsStdString(field) || IsStdBytes(field)) +} + +func IsWktPtr(field *google_protobuf.FieldDescriptorProto) bool { + return proto.GetBoolExtension(field.Options, E_Wktpointer, false) +} + func NeedsNilCheck(proto3 bool, field *google_protobuf.FieldDescriptorProto) bool { nullable := IsNullable(field) if field.IsMessage() || IsCustomType(field) { diff --git a/plugin/equal/equal.go b/plugin/equal/equal.go index 41a2c97041..33aec968e2 100644 --- a/plugin/equal/equal.go +++ b/plugin/equal/equal.go @@ -292,7 +292,16 @@ func (p *plugin) generateField(file *generator.FileDescriptor, message *generato repeated := field.IsRepeated() ctype := gogoproto.IsCustomType(field) nullable := gogoproto.IsNullable(field) - isDuration := gogoproto.IsStdDuration(field) + isNormal := (gogoproto.IsStdDuration(field) || + gogoproto.IsStdDouble(field) || + gogoproto.IsStdFloat(field) || + gogoproto.IsStdInt64(field) || + gogoproto.IsStdUInt64(field) || + gogoproto.IsStdInt32(field) || + gogoproto.IsStdUInt32(field) || + gogoproto.IsStdBool(field) || + gogoproto.IsStdString(field)) + isBytes := gogoproto.IsStdBytes(field) isTimestamp := gogoproto.IsStdTime(field) // oneof := field.OneofIndex != nil if !repeated { @@ -322,7 +331,7 @@ func (p *plugin) generateField(file *generator.FileDescriptor, message *generato } p.Out() p.P(`}`) - } else if isDuration { + } else if isNormal { if nullable { p.generateNullableField(fieldname, verbose) } else { @@ -336,6 +345,32 @@ func (p *plugin) generateField(file *generator.FileDescriptor, message *generato } p.Out() p.P(`}`) + } else if isBytes { + if nullable { + p.P(`if that1.`, fieldname, ` == nil {`) + p.In() + p.P(`if this.`, fieldname, ` != nil {`) + p.In() + if verbose { + p.P(`return `, p.fmtPkg.Use(), `.Errorf("this.`, fieldname, ` != nil && that1.`, fieldname, ` == nil")`) + } else { + p.P(`return false`) + } + p.Out() + p.P(`}`) + p.Out() + p.P(`} else if !`, p.bytesPkg.Use(), `.Equal(this.`, fieldname, `, that1.`, fieldname, `) {`) + } else { + p.P(`if !`, p.bytesPkg.Use(), `.Equal(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 { @@ -387,12 +422,14 @@ func (p *plugin) generateField(file *generator.FileDescriptor, message *generato } else { p.P(`if !this.`, fieldname, `[i].Equal(that1.`, fieldname, `[i]) {`) } - } else if isDuration { + } else if isNormal { 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 isBytes { + p.P(`if !`, p.bytesPkg.Use(), `.Equal(this.`, fieldname, `[i], that1.`, fieldname, `[i]) {`) } else { if p.IsMap(field) { m := p.GoMapType(nil, field) @@ -401,6 +438,16 @@ func (p *plugin) generateField(file *generator.FileDescriptor, message *generato nullable, valuegoTyp, valuegoAliasTyp = generator.GoMapValueTypes(field, m.ValueField, valuegoTyp, valuegoAliasTyp) mapValue := m.ValueAliasField + mapValueNormal := (gogoproto.IsStdDuration(mapValue) || + gogoproto.IsStdDouble(mapValue) || + gogoproto.IsStdFloat(mapValue) || + gogoproto.IsStdInt64(mapValue) || + gogoproto.IsStdUInt64(mapValue) || + gogoproto.IsStdInt32(mapValue) || + gogoproto.IsStdUInt32(mapValue) || + gogoproto.IsStdBool(mapValue) || + gogoproto.IsStdString(mapValue)) + mapValueBytes := gogoproto.IsStdBytes(mapValue) if mapValue.IsMessage() || p.IsGroup(mapValue) { if nullable && valuegoTyp == valuegoAliasTyp { p.P(`if !this.`, fieldname, `[i].Equal(that1.`, fieldname, `[i]) {`) @@ -408,14 +455,22 @@ func (p *plugin) generateField(file *generator.FileDescriptor, message *generato // Equal() has a pointer receiver, but map value is a value type a := `this.` + fieldname + `[i]` b := `that1.` + fieldname + `[i]` - if valuegoTyp != valuegoAliasTyp { + if !mapValueNormal && !mapValueBytes && valuegoTyp != valuegoAliasTyp { // cast back to the type that has the generated methods on it a = `(` + valuegoTyp + `)(` + a + `)` b = `(` + valuegoTyp + `)(` + b + `)` } p.P(`a := `, a) p.P(`b := `, b) - if nullable { + if mapValueNormal { + if nullable { + p.P(`if *a != *b {`) + } else { + p.P(`if a != b {`) + } + } else if mapValueBytes { + p.P(`if !`, p.bytesPkg.Use(), `.Equal(a, b) {`) + } else if nullable { p.P(`if !a.Equal(b) {`) } else { p.P(`if !(&a).Equal(&b) {`) diff --git a/plugin/gostring/gostring.go b/plugin/gostring/gostring.go index 31e01e898d..6003d65f22 100644 --- a/plugin/gostring/gostring.go +++ b/plugin/gostring/gostring.go @@ -225,7 +225,7 @@ func (p *gostring) Generate(file *generator.FileDescriptor) { p.P(`s = append(s, "`, fieldname, `: " + `, mapName, `+ ",\n")`) p.Out() p.P(`}`) - } else if (field.IsMessage() && !gogoproto.IsCustomType(field) && !gogoproto.IsStdTime(field) && !gogoproto.IsStdDuration(field)) || p.IsGroup(field) { + } else if (field.IsMessage() && !gogoproto.IsCustomType(field) && !gogoproto.IsStdType(field)) || p.IsGroup(field) { if nullable || repeated { p.P(`if this.`, fieldname, ` != nil {`) p.In() diff --git a/plugin/marshalto/marshalto.go b/plugin/marshalto/marshalto.go index 24110cb443..1350dd255f 100644 --- a/plugin/marshalto/marshalto.go +++ b/plugin/marshalto/marshalto.go @@ -319,6 +319,33 @@ func (p *marshalto) mapField(numGen NumGen, field *descriptor.FieldDescriptorPro } 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 gogoproto.IsStdDouble(field) { + p.callVarint(p.typesPkg.Use(), `.SizeOfStdDouble(*`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdDoubleMarshalTo(*`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdFloat(field) { + p.callVarint(p.typesPkg.Use(), `.SizeOfStdFloat(*`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdFloatMarshalTo(*`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdInt64(field) { + p.callVarint(p.typesPkg.Use(), `.SizeOfStdInt64(*`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdInt64MarshalTo(*`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdUInt64(field) { + p.callVarint(p.typesPkg.Use(), `.SizeOfStdUInt64(*`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdUInt64MarshalTo(*`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdInt32(field) { + p.callVarint(p.typesPkg.Use(), `.SizeOfStdInt32(*`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdInt32MarshalTo(*`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdUInt32(field) { + p.callVarint(p.typesPkg.Use(), `.SizeOfStdUInt32(*`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdUInt32MarshalTo(*`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdBool(field) { + p.callVarint(p.typesPkg.Use(), `.SizeOfStdBool(*`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdBoolMarshalTo(*`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdString(field) { + p.callVarint(p.typesPkg.Use(), `.SizeOfStdString(*`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdStringMarshalTo(*`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdBytes(field) { + p.callVarint(p.typesPkg.Use(), `.SizeOfStdBytes(`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdBytesMarshalTo(`, varName, `, dAtA[i:])`) } else if protoSizer { p.callVarint(varName, `.ProtoSize()`) p.P(`n`, numGen.Next(), `, err := `, varName, `.MarshalTo(dAtA[i:])`) @@ -781,8 +808,7 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi sum = append(sum, `soz`+p.localName+`(uint64(v))`) case descriptor.FieldDescriptorProto_TYPE_MESSAGE: if valuegoTyp != valuegoAliasTyp && - !gogoproto.IsStdTime(field) && - !gogoproto.IsStdDuration(field) { + !gogoproto.IsStdType(field) { if nullable { // cast back to the type that has the generated methods on it accessor = `((` + valuegoTyp + `)(` + accessor + `))` @@ -799,6 +825,24 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi p.P(`msgSize = `, p.typesPkg.Use(), `.SizeOfStdTime(*`, accessor, `)`) } else if gogoproto.IsStdDuration(field) { p.P(`msgSize = `, p.typesPkg.Use(), `.SizeOfStdDuration(*`, accessor, `)`) + } else if gogoproto.IsStdDouble(field) { + p.P(`msgSize = `, p.typesPkg.Use(), `.SizeOfStdDouble(*`, accessor, `)`) + } else if gogoproto.IsStdFloat(field) { + p.P(`msgSize = `, p.typesPkg.Use(), `.SizeOfStdFloat(*`, accessor, `)`) + } else if gogoproto.IsStdInt64(field) { + p.P(`msgSize = `, p.typesPkg.Use(), `.SizeOfStdInt64(*`, accessor, `)`) + } else if gogoproto.IsStdUInt64(field) { + p.P(`msgSize = `, p.typesPkg.Use(), `.SizeOfStdUInt64(*`, accessor, `)`) + } else if gogoproto.IsStdInt32(field) { + p.P(`msgSize = `, p.typesPkg.Use(), `.SizeOfStdInt32(*`, accessor, `)`) + } else if gogoproto.IsStdUInt32(field) { + p.P(`msgSize = `, p.typesPkg.Use(), `.SizeOfStdUInt32(*`, accessor, `)`) + } else if gogoproto.IsStdBool(field) { + p.P(`msgSize = `, p.typesPkg.Use(), `.SizeOfStdBool(*`, accessor, `)`) + } else if gogoproto.IsStdString(field) { + p.P(`msgSize = `, p.typesPkg.Use(), `.SizeOfStdString(*`, accessor, `)`) + } else if gogoproto.IsStdBytes(field) { + p.P(`msgSize = `, p.typesPkg.Use(), `.SizeOfStdBytes(`, accessor, `)`) } else if protoSizer { p.P(`msgSize = `, accessor, `.ProtoSize()`) } else { @@ -852,6 +896,57 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi } p.callVarint(p.typesPkg.Use(), `.SizeOfStdDuration(`, varName, `)`) p.P(`n, err := `, p.typesPkg.Use(), `.StdDurationMarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdDouble(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdDouble(`, varName, `)`) + p.P(`n, err := `, p.typesPkg.Use(), `.StdDoubleMarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdFloat(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdFloat(`, varName, `)`) + p.P(`n, err := `, p.typesPkg.Use(), `.StdFloatMarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdInt64(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdInt64(`, varName, `)`) + p.P(`n, err := `, p.typesPkg.Use(), `.StdInt64MarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdUInt64(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdUInt64(`, varName, `)`) + p.P(`n, err := `, p.typesPkg.Use(), `.StdUInt64MarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdInt32(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdInt32(`, varName, `)`) + p.P(`n, err := `, p.typesPkg.Use(), `.StdInt32MarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdUInt32(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdUInt32(`, varName, `)`) + p.P(`n, err := `, p.typesPkg.Use(), `.StdUInt32MarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdBool(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdBool(`, varName, `)`) + p.P(`n, err := `, p.typesPkg.Use(), `.StdBoolMarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdString(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdString(`, varName, `)`) + p.P(`n, err := `, p.typesPkg.Use(), `.StdStringMarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdBytes(field) { + p.callVarint(p.typesPkg.Use(), `.SizeOfStdBytes(`, varName, `)`) + p.P(`n, err := `, p.typesPkg.Use(), `.StdBytesMarshalTo(`, varName, `, dAtA[i:])`) } else if protoSizer { p.callVarint(varName, ".ProtoSize()") p.P(`n, err := `, varName, `.MarshalTo(dAtA[i:])`) @@ -882,6 +977,57 @@ func (p *marshalto) generateField(proto3 bool, numGen NumGen, file *generator.Fi } p.callVarint(p.typesPkg.Use(), `.SizeOfStdDuration(`, varName, `)`) p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdDurationMarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdDouble(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdDouble(`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdDoubleMarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdFloat(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdFloat(`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdFloatMarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdInt64(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdInt64(`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdInt64MarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdUInt64(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdUInt64(`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdUInt64MarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdInt32(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdInt32(`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdInt32MarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdUInt32(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdUInt32(`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdUInt32MarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdBool(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdBool(`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdBoolMarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdString(field) { + if gogoproto.IsNullable(field) { + varName = "*" + varName + } + p.callVarint(p.typesPkg.Use(), `.SizeOfStdString(`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdStringMarshalTo(`, varName, `, dAtA[i:])`) + } else if gogoproto.IsStdBytes(field) { + p.callVarint(p.typesPkg.Use(), `.SizeOfStdBytes(`, varName, `)`) + p.P(`n`, numGen.Next(), `, err := `, p.typesPkg.Use(), `.StdBytesMarshalTo(`, varName, `, dAtA[i:])`) } else if protoSizer { p.callVarint(varName, `.ProtoSize()`) p.P(`n`, numGen.Next(), `, err := `, varName, `.MarshalTo(dAtA[i:])`) diff --git a/plugin/populate/populate.go b/plugin/populate/populate.go index 40869581b5..52009f6b73 100644 --- a/plugin/populate/populate.go +++ b/plugin/populate/populate.go @@ -182,7 +182,7 @@ func negative(fieldType descriptor.FieldDescriptorProto_Type) bool { return true } -func (p *plugin) getFuncName(goTypName string) string { +func (p *plugin) getFuncName(goTypName string, field *descriptor.FieldDescriptorProto) string { funcName := "NewPopulated" + goTypName goTypNames := strings.Split(goTypName, ".") if len(goTypNames) == 2 { @@ -190,23 +190,43 @@ func (p *plugin) 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": - funcName = p.typesPkg.Use() + ".NewPopulatedStdDuration" + if field != nil { + switch { + case gogoproto.IsStdTime(field): + funcName = p.typesPkg.Use() + ".NewPopulatedStdTime" + case gogoproto.IsStdDuration(field): + funcName = p.typesPkg.Use() + ".NewPopulatedStdDuration" + case gogoproto.IsStdDouble(field): + funcName = p.typesPkg.Use() + ".NewPopulatedStdDouble" + case gogoproto.IsStdFloat(field): + funcName = p.typesPkg.Use() + ".NewPopulatedStdFloat" + case gogoproto.IsStdInt64(field): + funcName = p.typesPkg.Use() + ".NewPopulatedStdInt64" + case gogoproto.IsStdUInt64(field): + funcName = p.typesPkg.Use() + ".NewPopulatedStdUInt64" + case gogoproto.IsStdInt32(field): + funcName = p.typesPkg.Use() + ".NewPopulatedStdInt32" + case gogoproto.IsStdUInt32(field): + funcName = p.typesPkg.Use() + ".NewPopulatedStdUInt32" + case gogoproto.IsStdBool(field): + funcName = p.typesPkg.Use() + ".NewPopulatedStdBool" + case gogoproto.IsStdString(field): + funcName = p.typesPkg.Use() + ".NewPopulatedStdString" + case gogoproto.IsStdBytes(field): + funcName = p.typesPkg.Use() + ".NewPopulatedStdBytes" + } } return funcName } -func (p *plugin) getFuncCall(goTypName string) string { - funcName := p.getFuncName(goTypName) +func (p *plugin) getFuncCall(goTypName string, field *descriptor.FieldDescriptorProto) string { + funcName := p.getFuncName(goTypName, field) funcCall := funcName + "(r, easy)" return funcCall } func (p *plugin) getCustomFuncCall(goTypName string) string { - funcName := p.getFuncName(goTypName) + funcName := p.getFuncName(goTypName, nil) funcCall := funcName + "(r)" return funcCall } @@ -259,15 +279,15 @@ func (p *plugin) GenerateField(file *generator.FileDescriptor, message *generato if m.ValueField.IsMessage() || p.IsGroup(field) || (m.ValueField.IsBytes() && gogoproto.IsCustomType(field)) { s := `this.` + fieldname + `[` + keyval + `] = ` - if gogoproto.IsStdTime(field) || gogoproto.IsStdDuration(field) { + if gogoproto.IsStdType(field) { valuegoTyp = valuegoAliasTyp } funcCall := p.getCustomFuncCall(goTypName) if !gogoproto.IsCustomType(field) { goTypName = generator.GoTypeToName(valuegoTyp) - funcCall = p.getFuncCall(goTypName) + funcCall = p.getFuncCall(goTypName, m.ValueAliasField) } - if !nullable { + if !nullable && !gogoproto.IsStdBytes(m.ValueAliasField) { funcCall = `*` + funcCall } if valuegoTyp != valuegoAliasTyp { @@ -315,20 +335,20 @@ func (p *plugin) GenerateField(file *generator.FileDescriptor, message *generato p.P(`this.`, fieldname, `[i] = *`, p.varGen.Current()) p.Out() p.P(`}`) - } else if gogoproto.IsNullable(field) { + } else if gogoproto.IsNullable(field) || gogoproto.IsStdBytes(field) { p.P(`this.`, fieldname, ` = `, funcCall) } else { p.P(p.varGen.Next(), `:= `, funcCall) p.P(`this.`, fieldname, ` = *`, p.varGen.Current()) } } else if field.IsMessage() || p.IsGroup(field) { - funcCall := p.getFuncCall(goTypName) + funcCall := p.getFuncCall(goTypName, field) if field.IsRepeated() { p.P(p.varGen.Next(), ` := r.Intn(5)`) p.P(`this.`, fieldname, ` = make(`, goTyp, `, `, p.varGen.Current(), `)`) p.P(`for i := 0; i < `, p.varGen.Current(), `; i++ {`) p.In() - if gogoproto.IsNullable(field) { + if gogoproto.IsNullable(field) || gogoproto.IsStdBytes(field) { p.P(`this.`, fieldname, `[i] = `, funcCall) } else { p.P(p.varGen.Next(), `:= `, funcCall) @@ -337,7 +357,7 @@ func (p *plugin) GenerateField(file *generator.FileDescriptor, message *generato p.Out() p.P(`}`) } else { - if gogoproto.IsNullable(field) { + if gogoproto.IsNullable(field) || gogoproto.IsStdBytes(field) { p.P(`this.`, fieldname, ` = `, funcCall) } else { p.P(p.varGen.Next(), `:= `, funcCall) diff --git a/plugin/size/size.go b/plugin/size/size.go index 20e66678c4..5f898a6bdb 100644 --- a/plugin/size/size.go +++ b/plugin/size/size.go @@ -218,6 +218,56 @@ func (p *size) std(field *descriptor.FieldDescriptorProto, name string) (string, } else { return p.typesPkg.Use() + `.SizeOfStdDuration(` + name + `)`, true } + } else if gogoproto.IsStdDouble(field) { + if gogoproto.IsNullable(field) { + return p.typesPkg.Use() + `.SizeOfStdDouble(*` + name + `)`, true + } else { + return p.typesPkg.Use() + `.SizeOfStdDouble(` + name + `)`, true + } + } else if gogoproto.IsStdFloat(field) { + if gogoproto.IsNullable(field) { + return p.typesPkg.Use() + `.SizeOfStdFloat(*` + name + `)`, true + } else { + return p.typesPkg.Use() + `.SizeOfStdFloat(` + name + `)`, true + } + } else if gogoproto.IsStdInt64(field) { + if gogoproto.IsNullable(field) { + return p.typesPkg.Use() + `.SizeOfStdInt64(*` + name + `)`, true + } else { + return p.typesPkg.Use() + `.SizeOfStdInt64(` + name + `)`, true + } + } else if gogoproto.IsStdUInt64(field) { + if gogoproto.IsNullable(field) { + return p.typesPkg.Use() + `.SizeOfStdUInt64(*` + name + `)`, true + } else { + return p.typesPkg.Use() + `.SizeOfStdUInt64(` + name + `)`, true + } + } else if gogoproto.IsStdInt32(field) { + if gogoproto.IsNullable(field) { + return p.typesPkg.Use() + `.SizeOfStdInt32(*` + name + `)`, true + } else { + return p.typesPkg.Use() + `.SizeOfStdInt32(` + name + `)`, true + } + } else if gogoproto.IsStdUInt32(field) { + if gogoproto.IsNullable(field) { + return p.typesPkg.Use() + `.SizeOfStdUInt32(*` + name + `)`, true + } else { + return p.typesPkg.Use() + `.SizeOfStdUInt32(` + name + `)`, true + } + } else if gogoproto.IsStdBool(field) { + if gogoproto.IsNullable(field) { + return p.typesPkg.Use() + `.SizeOfStdBool(*` + name + `)`, true + } else { + return p.typesPkg.Use() + `.SizeOfStdBool(` + name + `)`, true + } + } else if gogoproto.IsStdString(field) { + if gogoproto.IsNullable(field) { + return p.typesPkg.Use() + `.SizeOfStdString(*` + name + `)`, true + } else { + return p.typesPkg.Use() + `.SizeOfStdString(` + name + `)`, true + } + } else if gogoproto.IsStdBytes(field) { + return p.typesPkg.Use() + `.SizeOfStdBytes(` + name + `)`, true } return "", false } @@ -447,7 +497,7 @@ func (p *size) generateField(proto3 bool, file *generator.FileDescriptor, messag 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") + stdSizeCall, stdOk := p.std(m.ValueAliasField, "v") if nullable { p.P(`l = 0`) p.P(`if v != nil {`) diff --git a/plugin/unmarshal/unmarshal.go b/plugin/unmarshal/unmarshal.go index d7cfb59400..b5594d2e1d 100644 --- a/plugin/unmarshal/unmarshal.go +++ b/plugin/unmarshal/unmarshal.go @@ -280,6 +280,24 @@ func (p *unmarshal) declareMapField(varName string, nullable bool, customType bo p.P(varName, ` := new(time.Time)`) } else if gogoproto.IsStdDuration(field) { p.P(varName, ` := new(time.Duration)`) + } else if gogoproto.IsStdDouble(field) { + p.P(varName, ` := new(float64)`) + } else if gogoproto.IsStdFloat(field) { + p.P(varName, ` := new(float32)`) + } else if gogoproto.IsStdInt64(field) { + p.P(varName, ` := new(int64)`) + } else if gogoproto.IsStdUInt64(field) { + p.P(varName, ` := new(uint64)`) + } else if gogoproto.IsStdInt32(field) { + p.P(varName, ` := new(int32)`) + } else if gogoproto.IsStdUInt32(field) { + p.P(varName, ` := new(uint32)`) + } else if gogoproto.IsStdBool(field) { + p.P(varName, ` := new(bool)`) + } else if gogoproto.IsStdString(field) { + p.P(varName, ` := new(string)`) + } else if gogoproto.IsStdBytes(field) { + p.P(varName, ` := make([]byte)`) } else { desc := p.ObjectNamed(field.GetTypeName()) msgname := p.TypeName(desc) @@ -383,6 +401,24 @@ func (p *unmarshal) mapField(varName string, customType bool, field *descriptor. p.P(`if err := `, p.typesPkg.Use(), `.StdTimeUnmarshal(`, varName, `, `, buf, `); err != nil {`) } else if gogoproto.IsStdDuration(field) { p.P(`if err := `, p.typesPkg.Use(), `.StdDurationUnmarshal(`, varName, `, `, buf, `); err != nil {`) + } else if gogoproto.IsStdDouble(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdDoubleUnmarshal(`, varName, `, `, buf, `); err != nil {`) + } else if gogoproto.IsStdFloat(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdFloatUnmarshal(`, varName, `, `, buf, `); err != nil {`) + } else if gogoproto.IsStdInt64(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdInt64Unmarshal(`, varName, `, `, buf, `); err != nil {`) + } else if gogoproto.IsStdUInt64(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt64Unmarshal(`, varName, `, `, buf, `); err != nil {`) + } else if gogoproto.IsStdInt32(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdInt32Unmarshal(`, varName, `, `, buf, `); err != nil {`) + } else if gogoproto.IsStdUInt32(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt32Unmarshal(`, varName, `, `, buf, `); err != nil {`) + } else if gogoproto.IsStdBool(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdBoolUnmarshal(`, varName, `, `, buf, `); err != nil {`) + } else if gogoproto.IsStdString(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdStringUnmarshal(`, varName, `, `, buf, `); err != nil {`) + } else if gogoproto.IsStdBytes(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdBytesUnmarshal(`, varName, `, `, buf, `); err != nil {`) } else { desc := p.ObjectNamed(field.GetTypeName()) msgname := p.TypeName(desc) @@ -648,6 +684,73 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip p.P(`v := time.Duration(0)`) p.P(`if err := `, p.typesPkg.Use(), `.StdDurationUnmarshal(&v, `, buf, `); err != nil {`) } + } else if gogoproto.IsStdDouble(field) { + if nullable { + p.P(`v := new(float64)`) + p.P(`if err := `, p.typesPkg.Use(), `.StdDoubleUnmarshal(v, `, buf, `); err != nil {`) + } else { + p.P(`v := 0`) + p.P(`if err := `, p.typesPkg.Use(), `.StdDoubleUnmarshal(&v, `, buf, `); err != nil {`) + } + } else if gogoproto.IsStdFloat(field) { + if nullable { + p.P(`v := new(float32)`) + p.P(`if err := `, p.typesPkg.Use(), `.StdFloatUnmarshal(v, `, buf, `); err != nil {`) + } else { + p.P(`v := 0`) + p.P(`if err := `, p.typesPkg.Use(), `.StdFloatUnmarshal(&v, `, buf, `); err != nil {`) + } + } else if gogoproto.IsStdInt64(field) { + if nullable { + p.P(`v := new(int64)`) + p.P(`if err := `, p.typesPkg.Use(), `.StdInt64Unmarshal(v, `, buf, `); err != nil {`) + } else { + p.P(`v := 0`) + p.P(`if err := `, p.typesPkg.Use(), `.StdInt64Unmarshal(&v, `, buf, `); err != nil {`) + } + } else if gogoproto.IsStdUInt64(field) { + if nullable { + p.P(`v := new(uint64)`) + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt64Unmarshal(v, `, buf, `); err != nil {`) + } else { + p.P(`v := 0`) + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt64Unmarshal(&v, `, buf, `); err != nil {`) + } + } else if gogoproto.IsStdInt32(field) { + if nullable { + p.P(`v := new(int32)`) + p.P(`if err := `, p.typesPkg.Use(), `.StdInt32Unmarshal(v, `, buf, `); err != nil {`) + } else { + p.P(`v := 0`) + p.P(`if err := `, p.typesPkg.Use(), `.StdInt32Unmarshal(&v, `, buf, `); err != nil {`) + } + } else if gogoproto.IsStdUInt32(field) { + if nullable { + p.P(`v := new(uint32)`) + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt32Unmarshal(v, `, buf, `); err != nil {`) + } else { + p.P(`v := 0`) + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt32Unmarshal(&v, `, buf, `); err != nil {`) + } + } else if gogoproto.IsStdBool(field) { + if nullable { + p.P(`v := new(bool)`) + p.P(`if err := `, p.typesPkg.Use(), `.StdBoolUnmarshal(v, `, buf, `); err != nil {`) + } else { + p.P(`v := false`) + p.P(`if err := `, p.typesPkg.Use(), `.StdBoolUnmarshal(&v, `, buf, `); err != nil {`) + } + } else if gogoproto.IsStdString(field) { + if nullable { + p.P(`v := new(string)`) + p.P(`if err := `, p.typesPkg.Use(), `.StdStringUnmarshal(v, `, buf, `); err != nil {`) + } else { + p.P(`v := ""`) + p.P(`if err := `, p.typesPkg.Use(), `.StdStringUnmarshal(&v, `, buf, `); err != nil {`) + } + } else if gogoproto.IsStdBytes(field) { + p.P(`var v []byte`) + p.P(`if err := `, p.typesPkg.Use(), `.StdBytesUnmarshal(v, `, buf, `); err != nil {`) } else { p.P(`v := &`, msgname, `{}`) p.P(`if err := v.Unmarshal(`, buf, `); err != nil {`) @@ -679,7 +782,7 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip } nullable, valuegoTyp, valuegoAliasTyp = generator.GoMapValueTypes(field, m.ValueField, valuegoTyp, valuegoAliasTyp) - if gogoproto.IsStdTime(field) || gogoproto.IsStdDuration(field) { + if gogoproto.IsStdType(field) { valuegoTyp = valuegoAliasTyp } @@ -762,6 +865,57 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip } else { p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, time.Duration(0))`) } + } else if gogoproto.IsStdDouble(field) { + if nullable { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, new(float64))`) + } else { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, 0)`) + } + } else if gogoproto.IsStdFloat(field) { + if nullable { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, new(float32))`) + } else { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, 0)`) + } + } else if gogoproto.IsStdInt64(field) { + if nullable { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, new(int64))`) + } else { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, 0)`) + } + } else if gogoproto.IsStdUInt64(field) { + if nullable { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, new(uint64))`) + } else { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, 0)`) + } + } else if gogoproto.IsStdInt32(field) { + if nullable { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, new(int32))`) + } else { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, 0)`) + } + } else if gogoproto.IsStdUInt32(field) { + if nullable { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, new(uint32))`) + } else { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, 0)`) + } + } else if gogoproto.IsStdBool(field) { + if nullable { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, new(bool))`) + } else { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, false)`) + } + } else if gogoproto.IsStdString(field) { + if nullable { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, new(string))`) + } else { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, "")`) + } + } else if gogoproto.IsStdBytes(field) { + p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, []byte{})`) + } else if nullable && !gogoproto.IsCustomType(field) { p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, &`, msgname, `{})`) } else { @@ -784,6 +938,56 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip } else { p.P(`if err := `, p.typesPkg.Use(), `.StdDurationUnmarshal(&(`, varName, `),`, buf, `); err != nil {`) } + } else if gogoproto.IsStdDouble(field) { + if nullable { + p.P(`if err := `, p.typesPkg.Use(), `.StdDoubleUnmarshal(`, varName, `,`, buf, `); err != nil {`) + } else { + p.P(`if err := `, p.typesPkg.Use(), `.StdDoubleUnmarshal(&(`, varName, `),`, buf, `); err != nil {`) + } + } else if gogoproto.IsStdFloat(field) { + if nullable { + p.P(`if err := `, p.typesPkg.Use(), `.StdFloatUnmarshal(`, varName, `,`, buf, `); err != nil {`) + } else { + p.P(`if err := `, p.typesPkg.Use(), `.StdFloatUnmarshal(&(`, varName, `),`, buf, `); err != nil {`) + } + } else if gogoproto.IsStdInt64(field) { + if nullable { + p.P(`if err := `, p.typesPkg.Use(), `.StdInt64Unmarshal(`, varName, `,`, buf, `); err != nil {`) + } else { + p.P(`if err := `, p.typesPkg.Use(), `.StdInt64Unmarshal(&(`, varName, `),`, buf, `); err != nil {`) + } + } else if gogoproto.IsStdUInt64(field) { + if nullable { + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt64Unmarshal(`, varName, `,`, buf, `); err != nil {`) + } else { + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt64Unmarshal(&(`, varName, `),`, buf, `); err != nil {`) + } + } else if gogoproto.IsStdInt32(field) { + if nullable { + p.P(`if err := `, p.typesPkg.Use(), `.StdInt32Unmarshal(`, varName, `,`, buf, `); err != nil {`) + } else { + p.P(`if err := `, p.typesPkg.Use(), `.StdInt32Unmarshal(&(`, varName, `),`, buf, `); err != nil {`) + } + } else if gogoproto.IsStdUInt32(field) { + if nullable { + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt32Unmarshal(`, varName, `,`, buf, `); err != nil {`) + } else { + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt32Unmarshal(&(`, varName, `),`, buf, `); err != nil {`) + } + } else if gogoproto.IsStdBool(field) { + if nullable { + p.P(`if err := `, p.typesPkg.Use(), `.StdBoolUnmarshal(`, varName, `,`, buf, `); err != nil {`) + } else { + p.P(`if err := `, p.typesPkg.Use(), `.StdBoolUnmarshal(&(`, varName, `),`, buf, `); err != nil {`) + } + } else if gogoproto.IsStdString(field) { + if nullable { + p.P(`if err := `, p.typesPkg.Use(), `.StdStringUnmarshal(`, varName, `,`, buf, `); err != nil {`) + } else { + p.P(`if err := `, p.typesPkg.Use(), `.StdStringUnmarshal(&(`, varName, `),`, buf, `); err != nil {`) + } + } else if gogoproto.IsStdBytes(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdBytesUnmarshal(`, varName, `,`, buf, `); err != nil {`) } else { p.P(`if err := `, varName, `.Unmarshal(`, buf, `); err != nil {`) } @@ -798,6 +1002,24 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip p.P(`m.`, fieldname, ` = new(time.Time)`) } else if gogoproto.IsStdDuration(field) { p.P(`m.`, fieldname, ` = new(time.Duration)`) + } else if gogoproto.IsStdDouble(field) { + p.P(`m.`, fieldname, ` = new(float64)`) + } else if gogoproto.IsStdFloat(field) { + p.P(`m.`, fieldname, ` = new(float32)`) + } else if gogoproto.IsStdInt64(field) { + p.P(`m.`, fieldname, ` = new(int64)`) + } else if gogoproto.IsStdUInt64(field) { + p.P(`m.`, fieldname, ` = new(uint64)`) + } else if gogoproto.IsStdInt32(field) { + p.P(`m.`, fieldname, ` = new(int32)`) + } else if gogoproto.IsStdUInt32(field) { + p.P(`m.`, fieldname, ` = new(uint32)`) + } else if gogoproto.IsStdBool(field) { + p.P(`m.`, fieldname, ` = new(bool)`) + } else if gogoproto.IsStdString(field) { + p.P(`m.`, fieldname, ` = new(string)`) + } else if gogoproto.IsStdBytes(field) { + p.P(`m.`, fieldname, ` = []byte{}`) } else { goType, _ := p.GoType(nil, field) // remove the star from the type @@ -809,6 +1031,24 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip 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 if gogoproto.IsStdDouble(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdDoubleUnmarshal(m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdFloat(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdFloatUnmarshal(m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdInt64(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdInt64Unmarshal(m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdUInt64(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt64Unmarshal(m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdInt32(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdInt32Unmarshal(m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdUInt32(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt32Unmarshal(m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdBool(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdBoolUnmarshal(m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdString(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdStringUnmarshal(m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdBytes(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdBytesUnmarshal(m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) } else { p.P(`if err := m.`, fieldname, `.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {`) } @@ -821,6 +1061,24 @@ func (p *unmarshal) field(file *generator.FileDescriptor, msg *generator.Descrip 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 if gogoproto.IsStdDouble(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdDoubleUnmarshal(&m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdFloat(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdFloatUnmarshal(&m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdInt64(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdInt64Unmarshal(&m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdUInt64(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt64Unmarshal(&m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdInt32(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdInt32Unmarshal(&m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdUInt32(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdUInt32Unmarshal(&m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdBool(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdBoolUnmarshal(&m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdString(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdStringUnmarshal(&m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) + } else if gogoproto.IsStdBytes(field) { + p.P(`if err := `, p.typesPkg.Use(), `.StdBytesUnmarshal(m.`, fieldname, `, dAtA[iNdEx:postIndex]); err != nil {`) } else { p.P(`if err := m.`, fieldname, `.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {`) } diff --git a/proto/properties.go b/proto/properties.go index 7a5e28efe5..3f6f40e559 100644 --- a/proto/properties.go +++ b/proto/properties.go @@ -153,6 +153,7 @@ type Properties struct { CastType string StdTime bool StdDuration bool + WktPointer bool stype reflect.Type // set for struct types only ctype reflect.Type // set for custom types only @@ -274,6 +275,8 @@ outer: p.StdTime = true case f == "stdduration": p.StdDuration = true + case f == "wktptr": + p.WktPointer = true } } } @@ -296,6 +299,10 @@ func (p *Properties) setFieldProps(typ reflect.Type, f *reflect.StructField, loc p.setTag(lockGetProp) return } + if p.WktPointer && !isMap { + p.setTag(lockGetProp) + return + } switch t1 := typ; t1.Kind() { case reflect.Struct: p.stype = typ @@ -330,6 +337,7 @@ func (p *Properties) setFieldProps(typ reflect.Type, f *reflect.StructField, loc p.mvalprop.CustomType = p.CustomType p.mvalprop.StdDuration = p.StdDuration p.mvalprop.StdTime = p.StdTime + p.mvalprop.WktPointer = p.WktPointer p.mvalprop.init(vtype, "Value", f.Tag.Get("protobuf_val"), nil, lockGetProp) } p.setTag(lockGetProp) diff --git a/proto/table_marshal.go b/proto/table_marshal.go index b479760a84..be50ff0f88 100644 --- a/proto/table_marshal.go +++ b/proto/table_marshal.go @@ -581,6 +581,7 @@ func typeMarshaler(t reflect.Type, tags []string, nozero, oneof bool) (sizer, ma ctype := false isTime := false isDuration := false + isWktPointer := false for i := 2; i < len(tags); i++ { if tags[i] == "packed" { packed = true @@ -597,6 +598,9 @@ func typeMarshaler(t reflect.Type, tags []string, nozero, oneof bool) (sizer, ma if tags[i] == "stdduration" { isDuration = true } + if tags[i] == "wktptr" { + isWktPointer = true + } } if !proto3 && !pointer && !slice { nozero = false @@ -642,6 +646,112 @@ func typeMarshaler(t reflect.Type, tags []string, nozero, oneof bool) (sizer, ma return makeDurationMarshaler(getMarshalInfo(t)) } + if isWktPointer { + switch t.Kind() { + case reflect.Float64: + if pointer { + if slice { + return makeDoublePtrSliceMarshaler(getMarshalInfo(t)) + } + return makeDoublePtrMarshaler(getMarshalInfo(t)) + } + if slice { + return makeDoubleSliceMarshaler(getMarshalInfo(t)) + } + return makeDoubleMarshaler(getMarshalInfo(t)) + case reflect.Float32: + if pointer { + if slice { + return makeFloatPtrSliceMarshaler(getMarshalInfo(t)) + } + return makeFloatPtrMarshaler(getMarshalInfo(t)) + } + if slice { + return makeFloatSliceMarshaler(getMarshalInfo(t)) + } + return makeFloatMarshaler(getMarshalInfo(t)) + case reflect.Int64: + if pointer { + if slice { + return makeInt64PtrSliceMarshaler(getMarshalInfo(t)) + } + return makeInt64PtrMarshaler(getMarshalInfo(t)) + } + if slice { + return makeInt64SliceMarshaler(getMarshalInfo(t)) + } + return makeInt64Marshaler(getMarshalInfo(t)) + case reflect.Uint64: + if pointer { + if slice { + return makeUInt64PtrSliceMarshaler(getMarshalInfo(t)) + } + return makeUInt64PtrMarshaler(getMarshalInfo(t)) + } + if slice { + return makeUInt64SliceMarshaler(getMarshalInfo(t)) + } + return makeUInt64Marshaler(getMarshalInfo(t)) + case reflect.Int32: + if pointer { + if slice { + return makeInt32PtrSliceMarshaler(getMarshalInfo(t)) + } + return makeInt32PtrMarshaler(getMarshalInfo(t)) + } + if slice { + return makeInt32SliceMarshaler(getMarshalInfo(t)) + } + return makeInt32Marshaler(getMarshalInfo(t)) + case reflect.Uint32: + if pointer { + if slice { + return makeUInt32PtrSliceMarshaler(getMarshalInfo(t)) + } + return makeUInt32PtrMarshaler(getMarshalInfo(t)) + } + if slice { + return makeUInt32SliceMarshaler(getMarshalInfo(t)) + } + return makeUInt32Marshaler(getMarshalInfo(t)) + case reflect.Bool: + if pointer { + if slice { + return makeBoolPtrSliceMarshaler(getMarshalInfo(t)) + } + return makeBoolPtrMarshaler(getMarshalInfo(t)) + } + if slice { + return makeBoolSliceMarshaler(getMarshalInfo(t)) + } + return makeBoolMarshaler(getMarshalInfo(t)) + case reflect.String: + if pointer { + if slice { + return makeStringPtrSliceMarshaler(getMarshalInfo(t)) + } + return makeStringPtrMarshaler(getMarshalInfo(t)) + } + if slice { + return makeStringSliceMarshaler(getMarshalInfo(t)) + } + return makeStringMarshaler(getMarshalInfo(t)) + default: + // bytes?? + if pointer { + if slice { + return makeBytesPtrSliceMarshaler(getMarshalInfo(t)) + } + return makeBytesPtrMarshaler(getMarshalInfo(t)) + } + if slice { + return makeBytesSliceMarshaler(getMarshalInfo(t)) + } + return makeBytesMarshaler(getMarshalInfo(t)) + + } + } + switch t.Kind() { case reflect.Bool: if pointer { @@ -2332,6 +2442,9 @@ func makeMapMarshaler(f *reflect.StructField) (sizer, marshaler) { if t == "stdduration" { valTags = append(valTags, t) } + if t == "wktptr" { + valTags = append(valTags, t) + } } keySizer, keyMarshaler := typeMarshaler(keyType, keyTags, false, false) // don't omit zero value in map valSizer, valMarshaler := typeMarshaler(valType, valTags, false, false) // don't omit zero value in map diff --git a/proto/table_unmarshal.go b/proto/table_unmarshal.go index b6371bb56b..a1c57eae24 100644 --- a/proto/table_unmarshal.go +++ b/proto/table_unmarshal.go @@ -465,6 +465,7 @@ func typeUnmarshaler(t reflect.Type, tags string) unmarshaler { ctype := false isTime := false isDuration := false + isWktPointer := false for _, tag := range tagArray[3:] { if strings.HasPrefix(tag, "name=") { name = tag[5:] @@ -478,6 +479,9 @@ func typeUnmarshaler(t reflect.Type, tags string) unmarshaler { if tag == "stdduration" { isDuration = true } + if tag == "wktptr" { + isWktPointer = true + } } // Figure out packaging (pointer, slice, or both) @@ -532,6 +536,110 @@ func typeUnmarshaler(t reflect.Type, tags string) unmarshaler { return makeUnmarshalDuration(getUnmarshalInfo(t), name) } + if isWktPointer { + switch t.Kind() { + case reflect.Float64: + if pointer { + if slice { + return makeUnmarshalDoublePtrSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalDoublePtr(getUnmarshalInfo(t), name) + } + if slice { + return makeUnmarshalDoubleSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalDouble(getUnmarshalInfo(t), name) + case reflect.Float32: + if pointer { + if slice { + return makeUnmarshalFloatPtrSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalFloatPtr(getUnmarshalInfo(t), name) + } + if slice { + return makeUnmarshalFloatSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalFloat(getUnmarshalInfo(t), name) + case reflect.Int64: + if pointer { + if slice { + return makeUnmarshalInt64PtrSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalInt64Ptr(getUnmarshalInfo(t), name) + } + if slice { + return makeUnmarshalInt64Slice(getUnmarshalInfo(t), name) + } + return makeUnmarshalInt64(getUnmarshalInfo(t), name) + case reflect.Uint64: + if pointer { + if slice { + return makeUnmarshalUInt64PtrSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalUInt64Ptr(getUnmarshalInfo(t), name) + } + if slice { + return makeUnmarshalUInt64Slice(getUnmarshalInfo(t), name) + } + return makeUnmarshalUInt64(getUnmarshalInfo(t), name) + case reflect.Int32: + if pointer { + if slice { + return makeUnmarshalInt32PtrSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalInt32Ptr(getUnmarshalInfo(t), name) + } + if slice { + return makeUnmarshalInt32Slice(getUnmarshalInfo(t), name) + } + return makeUnmarshalInt32(getUnmarshalInfo(t), name) + case reflect.Uint32: + if pointer { + if slice { + return makeUnmarshalUInt32PtrSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalUInt32Ptr(getUnmarshalInfo(t), name) + } + if slice { + return makeUnmarshalUInt32Slice(getUnmarshalInfo(t), name) + } + return makeUnmarshalUInt32(getUnmarshalInfo(t), name) + case reflect.Bool: + if pointer { + if slice { + return makeUnmarshalBoolPtrSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalBoolPtr(getUnmarshalInfo(t), name) + } + if slice { + return makeUnmarshalBoolSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalBool(getUnmarshalInfo(t), name) + case reflect.String: + if pointer { + if slice { + return makeUnmarshalStringPtrSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalStringPtr(getUnmarshalInfo(t), name) + } + if slice { + return makeUnmarshalStringSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalString(getUnmarshalInfo(t), name) + default: // bytes + if pointer { + if slice { + return makeUnmarshalBytesPtrSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalBytesPtr(getUnmarshalInfo(t), name) + } + if slice { + return makeUnmarshalBytesSlice(getUnmarshalInfo(t), name) + } + return makeUnmarshalBytes(getUnmarshalInfo(t), name) + } + } + // We'll never have both pointer and slice for basic types. if pointer && slice && t.Kind() != reflect.Struct { panic("both pointer and slice for basic type in " + t.Name()) @@ -1741,6 +1849,9 @@ func makeUnmarshalMap(f *reflect.StructField) unmarshaler { if t == "stdduration" { valTags = append(valTags, t) } + if t == "wktptr" { + valTags = append(valTags, t) + } } unmarshalKey := typeUnmarshaler(kt, f.Tag.Get("protobuf_key")) unmarshalVal := typeUnmarshaler(vt, strings.Join(valTags, ",")) diff --git a/proto/wrappers.go b/proto/wrappers.go new file mode 100644 index 0000000000..818a112f48 --- /dev/null +++ b/proto/wrappers.go @@ -0,0 +1,1888 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2018, The GoGo Authors. All rights reserved. +// http://github.com/gogo/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. +// +// 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 proto + +import ( + "io" + "reflect" +) + +func makeDoubleMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + t := ptr.asPointerTo(u.typ).Interface().(*float64) + v := &float64Value{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + t := ptr.asPointerTo(u.typ).Interface().(*float64) + v := &float64Value{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeDoublePtrMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + if ptr.isNil() { + return 0 + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*float64) + v := &float64Value{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + if ptr.isNil() { + return b, nil + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*float64) + v := &float64Value{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeDoubleSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(u.typ) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(float64) + v := &float64Value{t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(u.typ) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(float64) + v := &float64Value{t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeDoublePtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*float64) + v := &float64Value{*t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*float64) + v := &float64Value{*t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeUnmarshalDouble(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &float64Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(sub.typ).Elem() + s.Set(reflect.ValueOf(m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalDoublePtr(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &float64Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() + s.Set(reflect.ValueOf(&m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalDoublePtrSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &float64Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(reflect.PtrTo(sub.typ)) + newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeUnmarshalDoubleSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &float64Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(sub.typ) + newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeFloatMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + t := ptr.asPointerTo(u.typ).Interface().(*float32) + v := &float32Value{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + t := ptr.asPointerTo(u.typ).Interface().(*float32) + v := &float32Value{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeFloatPtrMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + if ptr.isNil() { + return 0 + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*float32) + v := &float32Value{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + if ptr.isNil() { + return b, nil + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*float32) + v := &float32Value{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeFloatSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(u.typ) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(float32) + v := &float32Value{t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(u.typ) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(float32) + v := &float32Value{t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeFloatPtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*float32) + v := &float32Value{*t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*float32) + v := &float32Value{*t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeUnmarshalFloat(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &float32Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(sub.typ).Elem() + s.Set(reflect.ValueOf(m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalFloatPtr(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &float32Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() + s.Set(reflect.ValueOf(&m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalFloatPtrSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &float32Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(reflect.PtrTo(sub.typ)) + newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeUnmarshalFloatSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &float32Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(sub.typ) + newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeInt64Marshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + t := ptr.asPointerTo(u.typ).Interface().(*int64) + v := &int64Value{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + t := ptr.asPointerTo(u.typ).Interface().(*int64) + v := &int64Value{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeInt64PtrMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + if ptr.isNil() { + return 0 + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*int64) + v := &int64Value{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + if ptr.isNil() { + return b, nil + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*int64) + v := &int64Value{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeInt64SliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(u.typ) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(int64) + v := &int64Value{t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(u.typ) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(int64) + v := &int64Value{t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeInt64PtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*int64) + v := &int64Value{*t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*int64) + v := &int64Value{*t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeUnmarshalInt64(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &int64Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(sub.typ).Elem() + s.Set(reflect.ValueOf(m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalInt64Ptr(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &int64Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() + s.Set(reflect.ValueOf(&m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalInt64PtrSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &int64Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(reflect.PtrTo(sub.typ)) + newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeUnmarshalInt64Slice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &int64Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(sub.typ) + newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeUInt64Marshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + t := ptr.asPointerTo(u.typ).Interface().(*uint64) + v := &uint64Value{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + t := ptr.asPointerTo(u.typ).Interface().(*uint64) + v := &uint64Value{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeUInt64PtrMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + if ptr.isNil() { + return 0 + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*uint64) + v := &uint64Value{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + if ptr.isNil() { + return b, nil + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*uint64) + v := &uint64Value{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeUInt64SliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(u.typ) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(uint64) + v := &uint64Value{t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(u.typ) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(uint64) + v := &uint64Value{t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeUInt64PtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*uint64) + v := &uint64Value{*t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*uint64) + v := &uint64Value{*t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeUnmarshalUInt64(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &uint64Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(sub.typ).Elem() + s.Set(reflect.ValueOf(m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalUInt64Ptr(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &uint64Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() + s.Set(reflect.ValueOf(&m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalUInt64PtrSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &uint64Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(reflect.PtrTo(sub.typ)) + newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeUnmarshalUInt64Slice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &uint64Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(sub.typ) + newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeInt32Marshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + t := ptr.asPointerTo(u.typ).Interface().(*int32) + v := &int32Value{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + t := ptr.asPointerTo(u.typ).Interface().(*int32) + v := &int32Value{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeInt32PtrMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + if ptr.isNil() { + return 0 + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*int32) + v := &int32Value{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + if ptr.isNil() { + return b, nil + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*int32) + v := &int32Value{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeInt32SliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(u.typ) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(int32) + v := &int32Value{t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(u.typ) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(int32) + v := &int32Value{t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeInt32PtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*int32) + v := &int32Value{*t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*int32) + v := &int32Value{*t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeUnmarshalInt32(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &int32Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(sub.typ).Elem() + s.Set(reflect.ValueOf(m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalInt32Ptr(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &int32Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() + s.Set(reflect.ValueOf(&m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalInt32PtrSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &int32Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(reflect.PtrTo(sub.typ)) + newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeUnmarshalInt32Slice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &int32Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(sub.typ) + newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeUInt32Marshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + t := ptr.asPointerTo(u.typ).Interface().(*uint32) + v := &uint32Value{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + t := ptr.asPointerTo(u.typ).Interface().(*uint32) + v := &uint32Value{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeUInt32PtrMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + if ptr.isNil() { + return 0 + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*uint32) + v := &uint32Value{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + if ptr.isNil() { + return b, nil + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*uint32) + v := &uint32Value{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeUInt32SliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(u.typ) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(uint32) + v := &uint32Value{t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(u.typ) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(uint32) + v := &uint32Value{t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeUInt32PtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*uint32) + v := &uint32Value{*t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*uint32) + v := &uint32Value{*t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeUnmarshalUInt32(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &uint32Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(sub.typ).Elem() + s.Set(reflect.ValueOf(m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalUInt32Ptr(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &uint32Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() + s.Set(reflect.ValueOf(&m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalUInt32PtrSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &uint32Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(reflect.PtrTo(sub.typ)) + newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeUnmarshalUInt32Slice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &uint32Value{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(sub.typ) + newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeBoolMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + t := ptr.asPointerTo(u.typ).Interface().(*bool) + v := &boolValue{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + t := ptr.asPointerTo(u.typ).Interface().(*bool) + v := &boolValue{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeBoolPtrMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + if ptr.isNil() { + return 0 + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*bool) + v := &boolValue{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + if ptr.isNil() { + return b, nil + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*bool) + v := &boolValue{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeBoolSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(u.typ) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(bool) + v := &boolValue{t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(u.typ) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(bool) + v := &boolValue{t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeBoolPtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*bool) + v := &boolValue{*t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*bool) + v := &boolValue{*t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeUnmarshalBool(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &boolValue{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(sub.typ).Elem() + s.Set(reflect.ValueOf(m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalBoolPtr(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &boolValue{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() + s.Set(reflect.ValueOf(&m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalBoolPtrSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &boolValue{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(reflect.PtrTo(sub.typ)) + newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeUnmarshalBoolSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &boolValue{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(sub.typ) + newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeStringMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + t := ptr.asPointerTo(u.typ).Interface().(*string) + v := &stringValue{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + t := ptr.asPointerTo(u.typ).Interface().(*string) + v := &stringValue{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeStringPtrMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + if ptr.isNil() { + return 0 + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*string) + v := &stringValue{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + if ptr.isNil() { + return b, nil + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*string) + v := &stringValue{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeStringSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(u.typ) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(string) + v := &stringValue{t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(u.typ) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(string) + v := &stringValue{t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeStringPtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*string) + v := &stringValue{*t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*string) + v := &stringValue{*t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeUnmarshalString(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &stringValue{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(sub.typ).Elem() + s.Set(reflect.ValueOf(m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalStringPtr(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &stringValue{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() + s.Set(reflect.ValueOf(&m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalStringPtrSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &stringValue{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(reflect.PtrTo(sub.typ)) + newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeUnmarshalStringSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &stringValue{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(sub.typ) + newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeBytesMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + t := ptr.asPointerTo(u.typ).Interface().(*[]byte) + v := &byteValue{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + t := ptr.asPointerTo(u.typ).Interface().(*[]byte) + v := &byteValue{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeBytesPtrMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + if ptr.isNil() { + return 0 + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*[]byte) + v := &byteValue{*t} + siz := Size(v) + return tagsize + SizeVarint(uint64(siz)) + siz + }, func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + if ptr.isNil() { + return b, nil + } + t := ptr.asPointerTo(reflect.PtrTo(u.typ)).Elem().Interface().(*[]byte) + v := &byteValue{*t} + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(len(buf))) + b = append(b, buf...) + return b, nil + } +} + +func makeBytesSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(u.typ) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().([]byte) + v := &byteValue{t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(u.typ) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().([]byte) + v := &byteValue{t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeBytesPtrSliceMarshaler(u *marshalInfo) (sizer, marshaler) { + return func(ptr pointer, tagsize int) int { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + n := 0 + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*[]byte) + v := &byteValue{*t} + siz := Size(v) + n += siz + SizeVarint(uint64(siz)) + tagsize + } + return n + }, + func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) { + s := ptr.getSlice(reflect.PtrTo(u.typ)) + for i := 0; i < s.Len(); i++ { + elem := s.Index(i) + t := elem.Interface().(*[]byte) + v := &byteValue{*t} + siz := Size(v) + buf, err := Marshal(v) + if err != nil { + return nil, err + } + b = appendVarint(b, wiretag) + b = appendVarint(b, uint64(siz)) + b = append(b, buf...) + } + + return b, nil + } +} + +func makeUnmarshalBytes(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &byteValue{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(sub.typ).Elem() + s.Set(reflect.ValueOf(m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalBytesPtr(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &byteValue{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + s := f.asPointerTo(reflect.PtrTo(sub.typ)).Elem() + s.Set(reflect.ValueOf(&m.Value)) + return b[x:], nil + } +} + +func makeUnmarshalBytesPtrSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &byteValue{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(reflect.PtrTo(sub.typ)) + newSlice := reflect.Append(slice, reflect.ValueOf(&m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} + +func makeUnmarshalBytesSlice(sub *unmarshalInfo, name string) unmarshaler { + return func(b []byte, f pointer, w int) ([]byte, error) { + if w != WireBytes { + return nil, errInternalBadWireType + } + x, n := decodeVarint(b) + if n == 0 { + return nil, io.ErrUnexpectedEOF + } + b = b[n:] + if x > uint64(len(b)) { + return nil, io.ErrUnexpectedEOF + } + m := &byteValue{} + if err := Unmarshal(b[:x], m); err != nil { + return nil, err + } + slice := f.getSlice(sub.typ) + newSlice := reflect.Append(slice, reflect.ValueOf(m.Value)) + slice.Set(newSlice) + return b[x:], nil + } +} diff --git a/proto/wrappers_gogo.go b/proto/wrappers_gogo.go new file mode 100644 index 0000000000..c338e8dbf0 --- /dev/null +++ b/proto/wrappers_gogo.go @@ -0,0 +1,113 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2018, The GoGo Authors. All rights reserved. +// http://github.com/gogo/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. +// +// 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 proto + +type float64Value struct { + Value float64 `protobuf:"fixed64,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *float64Value) Reset() { *m = float64Value{} } +func (*float64Value) ProtoMessage() {} +func (*float64Value) String() string { return "float64" } + +type float32Value struct { + Value float32 `protobuf:"fixed32,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *float32Value) Reset() { *m = float32Value{} } +func (*float32Value) ProtoMessage() {} +func (*float32Value) String() string { return "float32" } + +type int64Value struct { + Value int64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *int64Value) Reset() { *m = int64Value{} } +func (*int64Value) ProtoMessage() {} +func (*int64Value) String() string { return "int64" } + +type uint64Value struct { + Value uint64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *uint64Value) Reset() { *m = uint64Value{} } +func (*uint64Value) ProtoMessage() {} +func (*uint64Value) String() string { return "uint64" } + +type int32Value struct { + Value int32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *int32Value) Reset() { *m = int32Value{} } +func (*int32Value) ProtoMessage() {} +func (*int32Value) String() string { return "int32" } + +type uint32Value struct { + Value uint32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *uint32Value) Reset() { *m = uint32Value{} } +func (*uint32Value) ProtoMessage() {} +func (*uint32Value) String() string { return "uint32" } + +type boolValue struct { + Value bool `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *boolValue) Reset() { *m = boolValue{} } +func (*boolValue) ProtoMessage() {} +func (*boolValue) String() string { return "bool" } + +type stringValue struct { + Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *stringValue) Reset() { *m = stringValue{} } +func (*stringValue) ProtoMessage() {} +func (*stringValue) String() string { return "string" } + +type byteValue struct { + Value []byte `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *byteValue) Reset() { *m = byteValue{} } +func (*byteValue) ProtoMessage() {} +func (*byteValue) String() string { return "[]byte" } + +func init() { + RegisterType((*float64Value)(nil), "gogo.protobuf.proto.DoubleValue") + RegisterType((*float32Value)(nil), "gogo.protobuf.proto.FloatValue") + RegisterType((*int64Value)(nil), "gogo.protobuf.proto.Int64Value") + RegisterType((*uint64Value)(nil), "gogo.protobuf.proto.UInt64Value") + RegisterType((*int32Value)(nil), "gogo.protobuf.proto.Int32Value") + RegisterType((*uint32Value)(nil), "gogo.protobuf.proto.UInt32Value") + RegisterType((*boolValue)(nil), "gogo.protobuf.proto.BoolValue") + RegisterType((*stringValue)(nil), "gogo.protobuf.proto.StringValue") + RegisterType((*byteValue)(nil), "gogo.protobuf.proto.BytesValue") +} diff --git a/protoc-gen-gogo/generator/generator.go b/protoc-gen-gogo/generator/generator.go index f155fbc82b..0e580ab1af 100644 --- a/protoc-gen-gogo/generator/generator.go +++ b/protoc-gen-gogo/generator/generator.go @@ -1752,7 +1752,11 @@ func (g *Generator) goTag(message *Descriptor, field *descriptor.FieldDescriptor if gogoproto.IsStdDuration(field) { stdduration = ",stdduration" } - return strconv.Quote(fmt.Sprintf("%s,%d,%s%s%s%s%s%s%s%s%s%s%s%s%s", + wktptr := "" + if gogoproto.IsWktPtr(field) { + wktptr = ",wktptr" + } + return strconv.Quote(fmt.Sprintf("%s,%d,%s%s%s%s%s%s%s%s%s%s%s%s%s%s", wiretype, field.GetNumber(), optrepreq, @@ -1767,10 +1771,14 @@ func (g *Generator) goTag(message *Descriptor, field *descriptor.FieldDescriptor castkey, castvalue, stdtime, - stdduration)) + stdduration, + wktptr)) } func needsStar(field *descriptor.FieldDescriptorProto, proto3 bool, allowOneOf bool) bool { + if gogoproto.IsStdBytes(field) { + return false + } if isRepeated(field) && (*field.Type != descriptor.FieldDescriptorProto_TYPE_MESSAGE || gogoproto.IsCustomType(field)) && (*field.Type != descriptor.FieldDescriptorProto_TYPE_GROUP) { @@ -1880,6 +1888,24 @@ func (g *Generator) GoType(message *Descriptor, field *descriptor.FieldDescripto case gogoproto.IsStdDuration(field): g.customImports = append(g.customImports, "time") typ = "time.Duration" + case gogoproto.IsStdDouble(field): + typ = "float64" + case gogoproto.IsStdFloat(field): + typ = "float32" + case gogoproto.IsStdInt64(field): + typ = "int64" + case gogoproto.IsStdUInt64(field): + typ = "uint64" + case gogoproto.IsStdInt32(field): + typ = "int32" + case gogoproto.IsStdUInt32(field): + typ = "uint32" + case gogoproto.IsStdBool(field): + typ = "bool" + case gogoproto.IsStdString(field): + typ = "string" + case gogoproto.IsStdBytes(field): + typ = "[]byte" } if needsStar(field, g.file.proto3 && field.Extendee == nil, message != nil && message.allowOneof()) { typ = "*" + typ @@ -1952,7 +1978,7 @@ func (g *Generator) GoMapType(d *Descriptor, field *descriptor.FieldDescriptorPr if !gogoproto.IsNullable(m.ValueAliasField) { valType = strings.TrimPrefix(valType, "*") } - if !gogoproto.IsStdTime(field) && !gogoproto.IsStdDuration(field) && !gogoproto.IsCustomType(field) && !gogoproto.IsCastType(field) { + if !gogoproto.IsStdType(m.ValueAliasField) && !gogoproto.IsCustomType(field) && !gogoproto.IsCastType(field) { g.RecordTypeUse(m.ValueAliasField.GetTypeName()) } default: @@ -1960,7 +1986,9 @@ func (g *Generator) GoMapType(d *Descriptor, field *descriptor.FieldDescriptorPr if !gogoproto.IsNullable(m.ValueAliasField) { valType = strings.TrimPrefix(valType, "*") } - g.RecordTypeUse(m.ValueAliasField.GetTypeName()) + if !gogoproto.IsStdType(field) { + g.RecordTypeUse(m.ValueAliasField.GetTypeName()) + } } else { valType = strings.TrimPrefix(valType, "*") } @@ -2192,7 +2220,7 @@ func (g *Generator) generateMessage(message *Descriptor) { fieldFullPath := fmt.Sprintf("%s,%d,%d", message.path, messageFieldPath, i) g.PrintComments(fieldFullPath) g.P(Annotate(message.file, fieldFullPath, fieldName), "\t", typename, "\t`", tag, "`", fieldDeprecated) - if !gogoproto.IsStdTime(field) && !gogoproto.IsStdDuration(field) && !gogoproto.IsCustomType(field) && !gogoproto.IsCastType(field) { + if !gogoproto.IsStdType(field) && !gogoproto.IsCustomType(field) && !gogoproto.IsCastType(field) { g.RecordTypeUse(field.GetTypeName()) } } @@ -2227,7 +2255,7 @@ func (g *Generator) generateMessage(message *Descriptor) { // over all its fields to be able to mark as used any imported types // used by those fields. for _, field := range message.Field { - if !gogoproto.IsStdTime(field) && !gogoproto.IsStdDuration(field) && !gogoproto.IsCustomType(field) && !gogoproto.IsCastType(field) { + if !gogoproto.IsStdType(field) && !gogoproto.IsCustomType(field) && !gogoproto.IsCastType(field) { g.RecordTypeUse(field.GetTypeName()) } } @@ -2537,7 +2565,7 @@ func (g *Generator) generateMessage(message *Descriptor) { tag := "protobuf:" + g.goTag(message, field, wiretype) fieldFullPath := fmt.Sprintf("%s,%d,%d", message.path, messageFieldPath, i) g.P("type ", Annotate(message.file, fieldFullPath, oneofTypeName[field]), " struct{ ", Annotate(message.file, fieldFullPath, fieldNames[field]), " ", fieldTypes[field], " `", tag, "` }") - if !gogoproto.IsStdTime(field) && !gogoproto.IsStdDuration(field) && !gogoproto.IsCustomType(field) && !gogoproto.IsCastType(field) { + if !gogoproto.IsStdType(field) && !gogoproto.IsCustomType(field) && !gogoproto.IsCastType(field) { g.RecordTypeUse(field.GetTypeName()) } oneofTypes = append(oneofTypes, oneofTypeName[field]) @@ -2654,8 +2682,17 @@ func (g *Generator) generateMessage(message *Descriptor) { } else { goTyp, _ := g.GoType(message, field) goTypName := GoTypeToName(goTyp) - if !gogoproto.IsNullable(field) && gogoproto.IsStdDuration(field) { + if !gogoproto.IsNullable(field) && (gogoproto.IsStdDuration(field) || + gogoproto.IsStdDouble(field) || gogoproto.IsStdFloat(field) || + gogoproto.IsStdInt64(field) || gogoproto.IsStdUInt64(field) || + gogoproto.IsStdInt32(field) || gogoproto.IsStdUInt32(field)) { g.P("return 0") + } else if !gogoproto.IsNullable(field) && gogoproto.IsStdBool(field) { + g.P("return false") + } else if !gogoproto.IsNullable(field) && gogoproto.IsStdString(field) { + g.P("return \"\"") + } else if !gogoproto.IsNullable(field) && gogoproto.IsStdBytes(field) { + g.P("return []byte{}") } else { g.P("return ", goTypName, "{}") } @@ -2821,27 +2858,40 @@ func (g *Generator) generateMessage(message *Descriptor) { g.Out() g.P(`}`) val = "dAtA" - } else if gogoproto.IsStdTime(field) { + } else if gogoproto.IsStdType(field) { pkg := g.useTypes() + ptr := "" + fnname := "" if gogoproto.IsNullable(field) { - g.P(`dAtA, err := `, pkg, `.StdTimeMarshal(*`, val, `)`) - } else { - g.P(`dAtA, err := `, pkg, `.StdTimeMarshal(`, val, `)`) + ptr = "*" } - g.P(`if err != nil {`) - g.In() - g.P(`return err`) - g.Out() - g.P(`}`) - val = "dAtA" - pre, post = "b.EncodeRawBytes(", ")" - } else if gogoproto.IsStdDuration(field) { - pkg := g.useTypes() - if gogoproto.IsNullable(field) { - g.P(`dAtA, err := `, pkg, `.StdDurationMarshal(*`, val, `)`) + if gogoproto.IsStdTime(field) { + fnname = "Time" + } else if gogoproto.IsStdDuration(field) { + fnname = "Duration" + } else if gogoproto.IsStdDouble(field) { + fnname = "Double" + } else if gogoproto.IsStdFloat(field) { + fnname = "Float" + } else if gogoproto.IsStdInt64(field) { + fnname = "Int64" + } else if gogoproto.IsStdUInt64(field) { + fnname = "UInt64" + } else if gogoproto.IsStdInt32(field) { + fnname = "Int32" + } else if gogoproto.IsStdUInt32(field) { + fnname = "UInt32" + } else if gogoproto.IsStdBool(field) { + fnname = "Bool" + } else if gogoproto.IsStdString(field) { + fnname = "String" + } else if gogoproto.IsStdBytes(field) { + fnname = "Bytes" + ptr = "" } else { - g.P(`dAtA, err := `, pkg, `.StdDurationMarshal(`, val, `)`) + panic("internal error") } + g.P(`dAtA, err := `, pkg, `.Std`, fnname, `Marshal(`, ptr, val, `)`) g.P(`if err != nil {`) g.In() g.P(`return err`) @@ -2912,7 +2962,7 @@ func (g *Generator) generateMessage(message *Descriptor) { dec = "b.DecodeGroup(msg)" // handled specially below case descriptor.FieldDescriptorProto_TYPE_MESSAGE: - if gogoproto.IsStdTime(field) || gogoproto.IsStdDuration(field) { + if gogoproto.IsStdType(field) { dec = "b.DecodeRawBytes(true)" } else { g.P("msg := new(", fieldTypes[field][1:], ")") // drop star @@ -2953,35 +3003,65 @@ func (g *Generator) generateMessage(message *Descriptor) { g.P(`c := &cc`) g.P(`err = c.Unmarshal(`, val, `)`) val = "*c" - } else if gogoproto.IsStdTime(field) { - pkg := g.useTypes() - g.P(`if err != nil {`) - g.In() - g.P(`return true, err`) - g.Out() - g.P(`}`) - g.P(`c := new(time.Time)`) - g.P(`if err2 := `, pkg, `.StdTimeUnmarshal(c, `, val, `); err2 != nil {`) - g.In() - g.P(`return true, err`) - g.Out() - g.P(`}`) - val = "c" - } else if gogoproto.IsStdDuration(field) { + } else if gogoproto.IsStdType(field) { + var stdtype string + var fnname string + makename := "new" + ptr := "" + if gogoproto.IsStdTime(field) { + stdtype = "time.Time" + fnname = "Time" + } else if gogoproto.IsStdDuration(field) { + stdtype = "time.Duration" + fnname = "Duration" + } else if gogoproto.IsStdDouble(field) { + stdtype = "float64" + fnname = "Double" + } else if gogoproto.IsStdFloat(field) { + stdtype = "float32" + fnname = "Float" + } else if gogoproto.IsStdInt64(field) { + stdtype = "int64" + fnname = "Int64" + } else if gogoproto.IsStdUInt64(field) { + stdtype = "uint64" + fnname = "UInt64" + } else if gogoproto.IsStdInt32(field) { + stdtype = "int32" + fnname = "Int32" + } else if gogoproto.IsStdUInt32(field) { + stdtype = "uint32" + fnname = "UInt32" + } else if gogoproto.IsStdBool(field) { + stdtype = "bool" + fnname = "Bool" + } else if gogoproto.IsStdString(field) { + stdtype = "string" + fnname = "String" + } else if gogoproto.IsStdBytes(field) { + stdtype = "[]byte, 0" + fnname = "Bytes" + makename = "make" + ptr = "&" + } else { + panic("internal error") + } + pkg := g.useTypes() g.P(`if err != nil {`) g.In() g.P(`return true, err`) g.Out() g.P(`}`) - g.P(`c := new(time.Duration)`) - g.P(`if err2 := `, pkg, `.StdDurationUnmarshal(c, `, val, `); err2 != nil {`) + g.P(`c := `, makename, `(`, stdtype, `)`) + g.P(`if err2 := `, pkg, `.Std`, fnname, `Unmarshal(`, ptr, `c, `, val, `); err2 != nil {`) g.In() g.P(`return true, err`) g.Out() g.P(`}`) val = "c" } + if cast != "" { val = cast + "(" + val + ")" } @@ -2993,7 +3073,7 @@ func (g *Generator) generateMessage(message *Descriptor) { val += " != 0" case descriptor.FieldDescriptorProto_TYPE_GROUP, descriptor.FieldDescriptorProto_TYPE_MESSAGE: - if !gogoproto.IsStdTime(field) && !gogoproto.IsStdDuration(field) { + if !gogoproto.IsStdType(field) { val = "msg" } } @@ -3051,18 +3131,36 @@ func (g *Generator) generateMessage(message *Descriptor) { case descriptor.FieldDescriptorProto_TYPE_GROUP: fixed = g.Pkg["proto"] + ".Size(" + val + ")" case descriptor.FieldDescriptorProto_TYPE_MESSAGE: - if gogoproto.IsStdTime(field) { - if gogoproto.IsNullable(field) { - val = "*" + val - } + if gogoproto.IsStdType(field) { pkg := g.useTypes() - g.P("s := ", pkg, ".SizeOfStdTime(", val, ")") - } else if gogoproto.IsStdDuration(field) { - if gogoproto.IsNullable(field) { + if gogoproto.IsNullable(field) && !gogoproto.IsStdBytes(field) { val = "*" + val } - pkg := g.useTypes() - g.P("s := ", pkg, ".SizeOfStdDuration(", val, ")") + if gogoproto.IsStdTime(field) { + g.P("s := ", pkg, ".SizeOfStdTime(", val, ")") + } else if gogoproto.IsStdDuration(field) { + g.P("s := ", pkg, ".SizeOfStdDuration(", val, ")") + } else if gogoproto.IsStdDouble(field) { + g.P("s := ", pkg, ".SizeOfStdDouble(", val, ")") + } else if gogoproto.IsStdFloat(field) { + g.P("s := ", pkg, ".SizeOfStdFloat(", val, ")") + } else if gogoproto.IsStdInt64(field) { + g.P("s := ", pkg, ".SizeOfStdInt64(", val, ")") + } else if gogoproto.IsStdUInt64(field) { + g.P("s := ", pkg, ".SizeOfStdUInt64(", val, ")") + } else if gogoproto.IsStdInt32(field) { + g.P("s := ", pkg, ".SizeOfStdInt32(", val, ")") + } else if gogoproto.IsStdUInt32(field) { + g.P("s := ", pkg, ".SizeOfStdUInt32(", val, ")") + } else if gogoproto.IsStdBool(field) { + g.P("s := ", pkg, ".SizeOfStdBool(", val, ")") + } else if gogoproto.IsStdString(field) { + g.P("s := ", pkg, ".SizeOfStdString(", val, ")") + } else if gogoproto.IsStdBytes(field) { + g.P("s := ", pkg, ".SizeOfStdBytes(", val, ")") + } else { + panic("internal error") + } } else { g.P("s := ", g.Pkg["proto"], ".Size(", val, ")") } diff --git a/protoc-gen-gogo/generator/helper.go b/protoc-gen-gogo/generator/helper.go index 8104f066c4..697bbf52d1 100644 --- a/protoc-gen-gogo/generator/helper.go +++ b/protoc-gen-gogo/generator/helper.go @@ -262,6 +262,13 @@ func (g *Generator) GetMapValueField(field, valField *descriptor.FieldDescriptor } } + wktptr := gogoproto.IsWktPtr(field) + if wktptr { + if err := proto.SetExtension(valField.Options, gogoproto.E_Wktpointer, &wktptr); err != nil { + g.Fail(err.Error()) + } + } + if valType := gogoproto.GetCastValue(field); len(valType) > 0 { if err := proto.SetExtension(valField.Options, gogoproto.E_Casttype, &valType); err != nil { g.Fail(err.Error()) diff --git a/test/stdtypes/Makefile b/test/stdtypes/Makefile index 82c4c8c0b2..a8d105cce0 100644 --- a/test/stdtypes/Makefile +++ b/test/stdtypes/Makefile @@ -31,7 +31,8 @@ regenerate: go install github.com/gogo/protobuf/protoc-gen-gogo protoc-min-version --version="3.0.0" --gogo_out=\ Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\ - Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types\ + Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\ + Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types\ :. \ --proto_path=../../../../../:../../protobuf/:. stdtypes.proto diff --git a/test/stdtypes/stdtypes.proto b/test/stdtypes/stdtypes.proto index fb69b73278..9542e98da5 100644 --- a/test/stdtypes/stdtypes.proto +++ b/test/stdtypes/stdtypes.proto @@ -34,6 +34,7 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "google/protobuf/duration.proto"; import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; option (gogoproto.testgen_all) = true; option (gogoproto.populate_all) = true; @@ -52,6 +53,35 @@ message StdTypes { google.protobuf.Duration nullableDuration = 2 [(gogoproto.stdduration) = true]; google.protobuf.Timestamp timestamp = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; google.protobuf.Duration duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; + + google.protobuf.DoubleValue nullableDouble = 5 [(gogoproto.wktpointer) = true]; + google.protobuf.DoubleValue nonnullDouble = 6 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + google.protobuf.FloatValue nullableFloat = 7 [(gogoproto.wktpointer) = true]; + google.protobuf.FloatValue nonnullFloat = 8 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + google.protobuf.Int64Value nullableInt64 = 9 [(gogoproto.wktpointer) = true]; + google.protobuf.Int64Value nonnullInt64 = 10 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + google.protobuf.UInt64Value nullableUInt64 = 11 [(gogoproto.wktpointer) = true]; + google.protobuf.UInt64Value nonnullUInt64 = 12 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + google.protobuf.Int32Value nullableInt32 = 13 [(gogoproto.wktpointer) = true]; + google.protobuf.Int32Value nonnullInt32 = 14 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + google.protobuf.UInt32Value nullableUInt32 = 15 [(gogoproto.wktpointer) = true]; + google.protobuf.UInt32Value nonnullUInt32 = 16 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + google.protobuf.BoolValue nullableBool = 17 [(gogoproto.wktpointer) = true]; + google.protobuf.BoolValue nonnullBool = 18 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + google.protobuf.StringValue nullableString = 19 [(gogoproto.wktpointer) = true]; + google.protobuf.StringValue nonnullString = 20 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + google.protobuf.BytesValue nullableBytes = 21 [(gogoproto.wktpointer) = true]; + google.protobuf.BytesValue nonnullBytes = 22 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + } message RepStdTypes { @@ -59,6 +89,33 @@ message RepStdTypes { repeated google.protobuf.Duration nullableDurations = 2 [(gogoproto.stdduration) = true]; repeated google.protobuf.Timestamp timestamps = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; repeated google.protobuf.Duration durations = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; + + repeated google.protobuf.DoubleValue nullableDouble = 5 [(gogoproto.wktpointer) = true]; + repeated google.protobuf.DoubleValue nonnullDouble = 6 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + repeated google.protobuf.FloatValue nullableFloat = 7 [(gogoproto.wktpointer) = true]; + repeated google.protobuf.FloatValue nonnullFloat = 8 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + repeated google.protobuf.Int64Value nullableInt64 = 9 [(gogoproto.wktpointer) = true]; + repeated google.protobuf.Int64Value nonnullInt64 = 10 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + repeated google.protobuf.UInt64Value nullableUInt64 = 11 [(gogoproto.wktpointer) = true]; + repeated google.protobuf.UInt64Value nonnullUInt64 = 12 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + repeated google.protobuf.Int32Value nullableInt32 = 13 [(gogoproto.wktpointer) = true]; + repeated google.protobuf.Int32Value nonnullInt32 = 14 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + repeated google.protobuf.UInt32Value nullableUInt32 = 15 [(gogoproto.wktpointer) = true]; + repeated google.protobuf.UInt32Value nonnullUInt32 = 16 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + repeated google.protobuf.BoolValue nullableBool = 17 [(gogoproto.wktpointer) = true]; + repeated google.protobuf.BoolValue nonnullBool = 18 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + repeated google.protobuf.StringValue nullableString = 19 [(gogoproto.wktpointer) = true]; + repeated google.protobuf.StringValue nonnullString = 20 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + repeated google.protobuf.BytesValue nullableBytes = 21 [(gogoproto.wktpointer) = true]; + repeated google.protobuf.BytesValue nonnullBytes = 22 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; } message MapStdTypes { @@ -67,12 +124,48 @@ message MapStdTypes { map nullableDuration = 3 [(gogoproto.stdduration) = true]; map duration = 4 [(gogoproto.stdduration) = true, (gogoproto.nullable) = false]; + + map nullableDouble = 5 [(gogoproto.wktpointer) = true]; + map nonnullDouble = 6 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + map nullableFloat = 7 [(gogoproto.wktpointer) = true]; + map nonnullFloat = 8 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + map nullableInt64 = 9 [(gogoproto.wktpointer) = true]; + map nonnullInt64 = 10 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + map nullableUInt64 = 11 [(gogoproto.wktpointer) = true]; + map nonnullUInt64 = 12 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + map nullableInt32 = 13 [(gogoproto.wktpointer) = true]; + map nonnullInt32 = 14 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + map nullableUInt32 = 15 [(gogoproto.wktpointer) = true]; + map nonnullUInt32 = 16 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + map nullableBool = 17 [(gogoproto.wktpointer) = true]; + map nonnullBool = 18 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + map nullableString = 19 [(gogoproto.wktpointer) = true]; + map nonnullString = 20 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; + + map nullableBytes = 21 [(gogoproto.wktpointer) = true]; + map nonnullBytes = 22 [(gogoproto.wktpointer) = true, (gogoproto.nullable) = false]; } message OneofStdTypes { oneof OneOfStdTimes { google.protobuf.Timestamp timestamp = 1 [(gogoproto.stdtime) = true]; google.protobuf.Duration duration = 2 [(gogoproto.stdduration) = true]; + google.protobuf.DoubleValue repDouble = 3 [(gogoproto.wktpointer) = true]; + google.protobuf.FloatValue repFloat = 4 [(gogoproto.wktpointer) = true]; + google.protobuf.Int64Value repInt64 = 5 [(gogoproto.wktpointer) = true]; + google.protobuf.UInt64Value repUInt64 = 6 [(gogoproto.wktpointer) = true]; + google.protobuf.Int32Value repInt32 = 7 [(gogoproto.wktpointer) = true]; + google.protobuf.UInt32Value repUInt32 = 8 [(gogoproto.wktpointer) = true]; + google.protobuf.BoolValue repBool = 9 [(gogoproto.wktpointer) = true]; + google.protobuf.StringValue repString = 10 [(gogoproto.wktpointer) = true]; + google.protobuf.BytesValue repBytes = 11 [(gogoproto.wktpointer) = true]; } } diff --git a/types/wrappers_gogo.go b/types/wrappers_gogo.go new file mode 100644 index 0000000000..7dda2924cd --- /dev/null +++ b/types/wrappers_gogo.go @@ -0,0 +1,300 @@ +// Protocol Buffers for Go with Gadgets +// +// Copyright (c) 2018, The GoGo Authors. All rights reserved. +// http://github.com/gogo/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. +// +// 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 types + +func NewPopulatedStdDouble(r randyWrappers, easy bool) *float64 { + v := NewPopulatedDoubleValue(r, easy) + return &v.Value +} + +func SizeOfStdDouble(v float64) int { + pv := &DoubleValue{Value: v} + return pv.Size() +} + +func StdDoubleMarshal(v float64) ([]byte, error) { + size := SizeOfStdDouble(v) + buf := make([]byte, size) + _, err := StdDoubleMarshalTo(v, buf) + return buf, err +} + +func StdDoubleMarshalTo(v float64, data []byte) (int, error) { + pv := &DoubleValue{Value: v} + return pv.MarshalTo(data) +} + +func StdDoubleUnmarshal(v *float64, data []byte) error { + pv := &DoubleValue{} + if err := pv.Unmarshal(data); err != nil { + return err + } + *v = pv.Value + return nil +} +func NewPopulatedStdFloat(r randyWrappers, easy bool) *float32 { + v := NewPopulatedFloatValue(r, easy) + return &v.Value +} + +func SizeOfStdFloat(v float32) int { + pv := &FloatValue{Value: v} + return pv.Size() +} + +func StdFloatMarshal(v float32) ([]byte, error) { + size := SizeOfStdFloat(v) + buf := make([]byte, size) + _, err := StdFloatMarshalTo(v, buf) + return buf, err +} + +func StdFloatMarshalTo(v float32, data []byte) (int, error) { + pv := &FloatValue{Value: v} + return pv.MarshalTo(data) +} + +func StdFloatUnmarshal(v *float32, data []byte) error { + pv := &FloatValue{} + if err := pv.Unmarshal(data); err != nil { + return err + } + *v = pv.Value + return nil +} +func NewPopulatedStdInt64(r randyWrappers, easy bool) *int64 { + v := NewPopulatedInt64Value(r, easy) + return &v.Value +} + +func SizeOfStdInt64(v int64) int { + pv := &Int64Value{Value: v} + return pv.Size() +} + +func StdInt64Marshal(v int64) ([]byte, error) { + size := SizeOfStdInt64(v) + buf := make([]byte, size) + _, err := StdInt64MarshalTo(v, buf) + return buf, err +} + +func StdInt64MarshalTo(v int64, data []byte) (int, error) { + pv := &Int64Value{Value: v} + return pv.MarshalTo(data) +} + +func StdInt64Unmarshal(v *int64, data []byte) error { + pv := &Int64Value{} + if err := pv.Unmarshal(data); err != nil { + return err + } + *v = pv.Value + return nil +} +func NewPopulatedStdUInt64(r randyWrappers, easy bool) *uint64 { + v := NewPopulatedUInt64Value(r, easy) + return &v.Value +} + +func SizeOfStdUInt64(v uint64) int { + pv := &UInt64Value{Value: v} + return pv.Size() +} + +func StdUInt64Marshal(v uint64) ([]byte, error) { + size := SizeOfStdUInt64(v) + buf := make([]byte, size) + _, err := StdUInt64MarshalTo(v, buf) + return buf, err +} + +func StdUInt64MarshalTo(v uint64, data []byte) (int, error) { + pv := &UInt64Value{Value: v} + return pv.MarshalTo(data) +} + +func StdUInt64Unmarshal(v *uint64, data []byte) error { + pv := &UInt64Value{} + if err := pv.Unmarshal(data); err != nil { + return err + } + *v = pv.Value + return nil +} +func NewPopulatedStdInt32(r randyWrappers, easy bool) *int32 { + v := NewPopulatedInt32Value(r, easy) + return &v.Value +} + +func SizeOfStdInt32(v int32) int { + pv := &Int32Value{Value: v} + return pv.Size() +} + +func StdInt32Marshal(v int32) ([]byte, error) { + size := SizeOfStdInt32(v) + buf := make([]byte, size) + _, err := StdInt32MarshalTo(v, buf) + return buf, err +} + +func StdInt32MarshalTo(v int32, data []byte) (int, error) { + pv := &Int32Value{Value: v} + return pv.MarshalTo(data) +} + +func StdInt32Unmarshal(v *int32, data []byte) error { + pv := &Int32Value{} + if err := pv.Unmarshal(data); err != nil { + return err + } + *v = pv.Value + return nil +} +func NewPopulatedStdUInt32(r randyWrappers, easy bool) *uint32 { + v := NewPopulatedUInt32Value(r, easy) + return &v.Value +} + +func SizeOfStdUInt32(v uint32) int { + pv := &UInt32Value{Value: v} + return pv.Size() +} + +func StdUInt32Marshal(v uint32) ([]byte, error) { + size := SizeOfStdUInt32(v) + buf := make([]byte, size) + _, err := StdUInt32MarshalTo(v, buf) + return buf, err +} + +func StdUInt32MarshalTo(v uint32, data []byte) (int, error) { + pv := &UInt32Value{Value: v} + return pv.MarshalTo(data) +} + +func StdUInt32Unmarshal(v *uint32, data []byte) error { + pv := &UInt32Value{} + if err := pv.Unmarshal(data); err != nil { + return err + } + *v = pv.Value + return nil +} +func NewPopulatedStdBool(r randyWrappers, easy bool) *bool { + v := NewPopulatedBoolValue(r, easy) + return &v.Value +} + +func SizeOfStdBool(v bool) int { + pv := &BoolValue{Value: v} + return pv.Size() +} + +func StdBoolMarshal(v bool) ([]byte, error) { + size := SizeOfStdBool(v) + buf := make([]byte, size) + _, err := StdBoolMarshalTo(v, buf) + return buf, err +} + +func StdBoolMarshalTo(v bool, data []byte) (int, error) { + pv := &BoolValue{Value: v} + return pv.MarshalTo(data) +} + +func StdBoolUnmarshal(v *bool, data []byte) error { + pv := &BoolValue{} + if err := pv.Unmarshal(data); err != nil { + return err + } + *v = pv.Value + return nil +} +func NewPopulatedStdString(r randyWrappers, easy bool) *string { + v := NewPopulatedStringValue(r, easy) + return &v.Value +} + +func SizeOfStdString(v string) int { + pv := &StringValue{Value: v} + return pv.Size() +} + +func StdStringMarshal(v string) ([]byte, error) { + size := SizeOfStdString(v) + buf := make([]byte, size) + _, err := StdStringMarshalTo(v, buf) + return buf, err +} + +func StdStringMarshalTo(v string, data []byte) (int, error) { + pv := &StringValue{Value: v} + return pv.MarshalTo(data) +} + +func StdStringUnmarshal(v *string, data []byte) error { + pv := &StringValue{} + if err := pv.Unmarshal(data); err != nil { + return err + } + *v = pv.Value + return nil +} +func NewPopulatedStdBytes(r randyWrappers, easy bool) []byte { + v := NewPopulatedBytesValue(r, easy) + return v.Value +} + +func SizeOfStdBytes(v []byte) int { + pv := &BytesValue{Value: v} + return pv.Size() +} + +func StdBytesMarshal(v []byte) ([]byte, error) { + size := SizeOfStdBytes(v) + buf := make([]byte, size) + _, err := StdBytesMarshalTo(v, buf) + return buf, err +} + +func StdBytesMarshalTo(v []byte, data []byte) (int, error) { + pv := &BytesValue{Value: v} + return pv.MarshalTo(data) +} + +func StdBytesUnmarshal(v *[]byte, data []byte) error { + pv := &BytesValue{} + if err := pv.Unmarshal(data); err != nil { + return err + } + *v = pv.Value + return nil +}