diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5da55550..49f82e85 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,8 @@ jobs: - run: go vet ./... + - run: go vet -tags protoopaque ./testproto/hybrid/... + - run: make genall - run: git --no-pager diff --exit-code diff --git a/Makefile b/Makefile index 4c9f6c0a..3ea711f4 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,26 @@ gen-testproto: get-grpc-testproto gen-wkt-testproto install testproto/unsafe/unsafe.proto \ testproto/unique/unique.proto \ || exit 1; + $(PROTOBUF_ROOT)/src/protoc \ + --proto_path=testproto \ + --proto_path=include \ + --go_out=. --plugin protoc-gen-go="${GOBIN}/protoc-gen-go" \ + --go_opt=default_api_level=API_OPAQUE \ + --go-vtproto_out=allow-empty=true:. --plugin protoc-gen-go-vtproto="${GOBIN}/protoc-gen-go-vtproto" \ + --go-vtproto_opt=default_api_level=API_OPAQUE \ + -I$(PROTOBUF_ROOT)/src \ + testproto/opaque/opaque.proto \ + || exit 1; + $(PROTOBUF_ROOT)/src/protoc \ + --proto_path=testproto \ + --proto_path=include \ + --go_out=. --plugin protoc-gen-go="${GOBIN}/protoc-gen-go" \ + --go_opt=default_api_level=API_HYBRID \ + --go-vtproto_out=allow-empty=true:. --plugin protoc-gen-go-vtproto="${GOBIN}/protoc-gen-go-vtproto" \ + --go-vtproto_opt=default_api_level=API_HYBRID \ + -I$(PROTOBUF_ROOT)/src \ + testproto/hybrid/hybrid.proto \ + || exit 1; $(PROTOBUF_ROOT)/src/protoc \ --proto_path=testproto \ --proto_path=include \ @@ -77,6 +97,20 @@ gen-testproto: get-grpc-testproto gen-wkt-testproto install testproto/empty/empty.proto \ || exit 1; +# Not part of genall: the output is checked in because the vendored protoc 21.12 +# predates editions. Regenerating needs PROTOC pointed at protoc >= 32. +PROTOC ?= protoc + +gen-editions-testproto: install + $(PROTOC) \ + --proto_path=testproto \ + --proto_path=include \ + --go_out=. --plugin protoc-gen-go="${GOBIN}/protoc-gen-go" \ + --go-vtproto_out=allow-empty=true:. --plugin protoc-gen-go-vtproto="${GOBIN}/protoc-gen-go-vtproto" \ + testproto/editions/editions.proto \ + testproto/editions/editions2023.proto \ + || exit 1; + get-grpc-testproto: install $(PROTOBUF_ROOT)/src/protoc \ --proto_path=. \ diff --git a/README.md b/README.md index 647ddb93..6c624c99 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,20 @@ message Label { 9. (Optional) Switch your RPC framework to use the optimized helpers (see following sections) +## Editions and API levels + +`vtprotobuf` accepts `proto2`, `proto3` and editions 2023 and 2024 input, and generates code for all three `protoc-gen-go` API levels. + +- **Pass the same `default_api_level` (and any `apilevelM`) to both plugins.** `protoc-gen-go` and `protoc-gen-go-vtproto` each resolve the API level independently; if they disagree, `vtprotobuf` generates open-layout code against an opaque struct and the package fails to compile. + +- **Hybrid** files get a `//go:build !protoopaque` constraint, matching the variant `protoc-gen-go` generates without that tag. Under `-tags protoopaque` the `vtprotobuf` helpers are absent rather than broken, so guard their use with a type assertion as described for `buildTag` above. + +- **`wrap=true` is incompatible with the opaque API**, which does not export the struct fields the wrapper package would have to reach; it is rejected. + +- **`[lazy = true]` is rejected.** `vtprotobuf` cannot honour the lazy unmarshalling contract, and silently ignoring it would drop fields. + +- Under the opaque API, reading or writing a field with explicit presence costs one atomic operation on the presence bitfield. + ## `vtprotobuf` package and well-known types Your generated `_vtproto.pb.go` files will have a dependency on this Go package to access some helper functions as well as the optimized code for ProtoBuf [well-known types](https://protobuf.dev/reference/protobuf/google.protobuf/). `vtprotobuf` will detect these types embedded in your own Messages and generate optimized code to marshal and unmarshal them. diff --git a/features/clone/clone.go b/features/clone/clone.go index 9e5d73e5..369baa19 100644 --- a/features/clone/clone.go +++ b/features/clone/clone.go @@ -39,10 +39,8 @@ func (p *clone) Name() string { } func (p *clone) GenerateFile(file *protogen.File) bool { - proto3 := file.Desc.Syntax() == protoreflect.Proto3 - for _, message := range file.Messages { - p.processMessage(proto3, message) + p.processMessage(message) } return p.once @@ -50,7 +48,7 @@ func (p *clone) GenerateFile(file *protogen.File) bool { // cloneOneofField generates the statements for cloning a oneof field func (p *clone) cloneOneofField(lhsBase, rhsBase string, oneof *protogen.Oneof) { - fieldname := oneof.GoName + fieldname := p.OneofName(oneof) ccInterfaceName := "is" + oneof.GoIdent.GoName lhs := lhsBase + "." + fieldname rhs := rhsBase + "." + fieldname @@ -58,8 +56,8 @@ func (p *clone) cloneOneofField(lhsBase, rhsBase string, oneof *protogen.Oneof) if p.IsWellKnownType(oneof.Parent) { p.P(`switch c := `, rhs, `.(type) {`) for _, f := range oneof.Fields { - p.P(`case *`, f.GoIdent, `:`) - p.P(lhs, `= (*`, f.GoIdent, `)((*`, p.WellKnownFieldMap(f), `)(c).`, cloneName, `())`) + p.P(`case *`, p.OneofWrapperIdent(f), `:`) + p.P(lhs, `= (*`, p.OneofWrapperIdent(f), `)((*`, p.WellKnownFieldMap(f), `)(c).`, cloneName, `())`) } p.P(`}`) } else { @@ -98,7 +96,7 @@ func (p *clone) cloneFieldSingular(lhs, rhs string, kind protoreflect.Kind, mess } // cloneField generates the code for cloning a field in a protobuf. -func (p *clone) cloneField(lhsBase, rhsBase string, allFieldsNullable bool, field *protogen.Field) { +func (p *clone) cloneField(lhsBase, rhsBase string, wrapper bool, field *protogen.Field) { // At this point, if we encounter a non-synthetic oneof, we assume it to be the representative // field for that oneof. if field.Oneof != nil && !field.Oneof.Desc.IsSynthetic() { @@ -106,13 +104,18 @@ func (p *clone) cloneField(lhsBase, rhsBase string, allFieldsNullable bool, fiel return } - if !isReference(allFieldsNullable, field) { + pointer := !wrapper && p.FieldStorageIsPointer(field) + if !isReference(pointer, field) { panic("method should not be invoked for non-reference fields") } fieldname := field.GoName - lhs := lhsBase + "." + fieldname rhs := rhsBase + "." + fieldname + if !wrapper { + fieldname = p.FieldName(field) + rhs = p.FieldSliceExpr(rhsBase, field) + } + lhs := lhsBase + "." + fieldname // At this point, we are only looking at reference types (pointers, maps, slices, interfaces), which can all // be nil. @@ -141,7 +144,11 @@ func (p *clone) cloneField(lhsBase, rhsBase string, allFieldsNullable bool, fiel p.cloneFieldSingular("tmpContainer[k]", "v", fieldKind, msg) p.P(`}`) } - p.P(lhs, ` = tmpContainer`) + if p.FieldStorageIsPointer(field) { + p.P(lhs, ` = &tmpContainer`) + } else { + p.P(lhs, ` = tmpContainer`) + } } else if isScalar(fieldKind) { p.P(`tmpVal := *`, rhs) p.P(lhs, ` = &tmpVal`) @@ -151,10 +158,10 @@ func (p *clone) cloneField(lhsBase, rhsBase string, allFieldsNullable bool, fiel p.P(`}`) } -func (p *clone) generateCloneMethodsForMessage(proto3 bool, message *protogen.Message) { +func (p *clone) generateCloneMethodsForMessage(message *protogen.Message) { ccTypeName := message.GoIdent.GoName p.P(`func (m *`, ccTypeName, `) `, cloneName, `() *`, ccTypeName, ` {`) - p.body(!proto3, ccTypeName, message) + p.body(ccTypeName, message) p.P(`}`) p.P() @@ -169,7 +176,7 @@ func (p *clone) generateCloneMethodsForMessage(proto3 bool, message *protogen.Me // body generates the code for the actual cloning logic of a structure containing the given fields. // In practice, those can be the fields of a message. // The object to be cloned is assumed to be called "m". -func (p *clone) body(allFieldsNullable bool, ccTypeName string, message *protogen.Message) { +func (p *clone) body(ccTypeName string, message *protogen.Message) { // The method body for a message or a oneof wrapper always starts with a nil check. p.P(`if m == nil {`) // We use an explicitly typed nil to avoid returning the nil interface in the oneof wrapper @@ -196,8 +203,9 @@ func (p *clone) body(allFieldsNullable bool, ccTypeName string, message *protoge continue } - if !isReference(allFieldsNullable, field) { - p.P(`r.`, field.GoName, ` = m.`, field.GoName) + fieldname := p.FieldName(field) + if !isReference(p.FieldStorageIsPointer(field), field) { + p.P(`r.`, fieldname, ` = m.`, fieldname) continue } // Shortcut: for types where we know that an optimized clone method exists, we can call it directly as it is @@ -205,10 +213,10 @@ func (p *clone) body(allFieldsNullable bool, ccTypeName string, message *protoge if field.Desc.Cardinality() != protoreflect.Repeated { switch { case p.IsWellKnownType(field.Message): - p.P(`r.`, field.GoName, ` = (*`, field.Message.GoIdent, `)((*`, p.WellKnownTypeMap(field.Message), `)(m.`, field.GoName, `).`, cloneName, `())`) + p.P(`r.`, fieldname, ` = (*`, field.Message.GoIdent, `)((*`, p.WellKnownTypeMap(field.Message), `)(m.`, fieldname, `).`, cloneName, `())`) continue case p.IsLocalMessage(field.Message): - p.P(`r.`, field.GoName, ` = m.`, field.GoName, `.`, cloneName, `()`) + p.P(`r.`, fieldname, ` = m.`, fieldname, `.`, cloneName, `()`) continue } } @@ -217,9 +225,11 @@ func (p *clone) body(allFieldsNullable bool, ccTypeName string, message *protoge // Generate explicit assignment statements for all reference fields. for _, field := range refFields { - p.cloneField("r", "m", allFieldsNullable, field) + p.cloneField("r", "m", false, field) } + p.CopyPresence("r", "m", message) + if !p.Wrapper() && !p.ShouldIgnoreUnknownFields(message) { // Clone unknown fields, if any p.P(`if len(m.unknownFields) > 0 {`) @@ -262,7 +272,7 @@ func (p *clone) bodyForOneOf(ccTypeName string, field *protogen.Field) { } // Generate explicit assignment statements for reference field. - p.cloneField("r", "m", false, field) + p.cloneField("r", "m", true, field) p.P(`return r`) } @@ -270,7 +280,7 @@ func (p *clone) bodyForOneOf(ccTypeName string, field *protogen.Field) { // generateCloneMethodsForOneof generates the clone method for the oneof wrapper type of a // field in a oneof. func (p *clone) generateCloneMethodsForOneof(message *protogen.Message, field *protogen.Field) { - ccTypeName := field.GoIdent.GoName + ccTypeName := p.OneofWrapperIdent(field).GoName ccInterfaceName := "is" + field.Oneof.GoIdent.GoName if p.IsWellKnownType(message) { p.P(`func (m *`, ccTypeName, `) `, cloneName, `() *`, ccTypeName, ` {`) @@ -296,9 +306,9 @@ func (p *clone) processMessageOneofs(message *protogen.Message) { } } -func (p *clone) processMessage(proto3 bool, message *protogen.Message) { +func (p *clone) processMessage(message *protogen.Message) { for _, nested := range message.Messages { - p.processMessage(proto3, nested) + p.processMessage(nested) } if message.Desc.IsMapEntry() { @@ -307,13 +317,14 @@ func (p *clone) processMessage(proto3 bool, message *protogen.Message) { p.once = true - p.generateCloneMethodsForMessage(proto3, message) + p.generateCloneMethodsForMessage(message) p.processMessageOneofs(message) } // isReference checks whether the Go equivalent of the given field is of reference type, i.e., can be nil. -func isReference(allFieldsNullable bool, field *protogen.Field) bool { - if allFieldsNullable || field.Oneof != nil || field.Message != nil || field.Desc.Cardinality() == protoreflect.Repeated || field.Desc.Kind() == protoreflect.BytesKind { +func isReference(pointer bool, field *protogen.Field) bool { + realOneof := field.Oneof != nil && !field.Oneof.Desc.IsSynthetic() + if pointer || realOneof || field.Message != nil || field.Desc.Cardinality() == protoreflect.Repeated || field.Desc.Kind() == protoreflect.BytesKind { return true } if !isScalar(field.Desc.Kind()) { diff --git a/features/equal/equal.go b/features/equal/equal.go index bbba98ba..1d2413a0 100644 --- a/features/equal/equal.go +++ b/features/equal/equal.go @@ -32,9 +32,8 @@ var _ generator.FeatureGenerator = (*equal)(nil) func (p *equal) Name() string { return "equal" } func (p *equal) GenerateFile(file *protogen.File) bool { - proto3 := file.Desc.Syntax() == protoreflect.Proto3 for _, message := range file.Messages { - p.message(proto3, message) + p.message(message) } return p.once } @@ -42,9 +41,9 @@ func (p *equal) GenerateFile(file *protogen.File) bool { const equalName = "EqualVT" const equalMessageName = "EqualMessageVT" -func (p *equal) message(proto3 bool, message *protogen.Message) { +func (p *equal) message(message *protogen.Message) { for _, nested := range message.Messages { - p.message(proto3, nested) + p.message(nested) } if message.Desc.IsMapEntry() { @@ -74,7 +73,7 @@ func (p *equal) message(proto3 bool, message *protogen.Message) { continue } - fieldname := field.Oneof.GoName + fieldname := p.OneofName(field.Oneof) if _, ok := oneofs[fieldname]; ok { continue } @@ -90,7 +89,7 @@ func (p *equal) message(proto3 bool, message *protogen.Message) { if p.IsWellKnownType(message) { p.P(`switch c := this.`, fieldname, `.(type) {`) for _, f := range field.Oneof.Fields { - p.P(`case *`, f.GoIdent, `:`) + p.P(`case *`, p.OneofWrapperIdent(f), `:`) p.P(`if !(*`, p.WellKnownFieldMap(f), `)(c).`, equalName, `(that.`, fieldname, `) {`) p.P(`return false`) p.P(`}`) @@ -107,7 +106,7 @@ func (p *equal) message(proto3 bool, message *protogen.Message) { for _, field := range message.Fields { oneof := field.Oneof != nil && !field.Oneof.Desc.IsSynthetic() - nullable := field.Message != nil || (field.Oneof != nil && field.Oneof.Desc.IsSynthetic()) || (!proto3 && !oneof) + nullable := field.Message != nil || field.Desc.HasPresence() if !oneof { p.field(field, nullable) } @@ -141,7 +140,7 @@ func (p *equal) message(proto3 bool, message *protogen.Message) { } func (p *equal) oneof(field *protogen.Field) { - ccTypeName := field.GoIdent.GoName + ccTypeName := p.OneofWrapperIdent(field).GoName ccInterfaceName := fmt.Sprintf("is%s", field.Oneof.GoIdent.GoName) fieldname := field.GoName @@ -188,11 +187,17 @@ func (p *equal) oneof(field *protogen.Field) { } func (p *equal) field(field *protogen.Field, nullable bool) { - fieldname := field.GoName - repeated := field.Desc.Cardinality() == protoreflect.Repeated - lhs := fmt.Sprintf("this.%s", fieldname) - rhs := fmt.Sprintf("that.%s", fieldname) + lhs := p.FieldSliceExpr("this", field) + rhs := p.FieldSliceExpr("that", field) + + if !repeated && p.UsesPresenceBit(field) && !p.FieldStorageIsPointer(field) { + // Unset and set-to-zero differ only in the presence bit. + p.P(`if `, p.FieldPresent("this", field), ` != `, p.FieldPresent("that", field), ` {`) + p.P(`return false`) + p.P(`}`) + nullable = false + } if repeated { p.P(`if len(`, lhs, `) != len(`, rhs, `) {`) diff --git a/features/marshal/marshalto.go b/features/marshal/marshalto.go index d0451d04..d0d957ae 100644 --- a/features/marshal/marshalto.go +++ b/features/marshal/marshalto.go @@ -113,18 +113,29 @@ func (p *marshal) mapField(kvField *protogen.Field, varName string) { } func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { + // Oneof wrappers keep the exported field name at every API level. fieldname := field.GoName + store, deref := `m.`+fieldname, `` + present, absent := store+` != nil`, store+` == nil` + if !oneof { + fieldname = p.FieldName(field) + store = p.FieldSliceExpr("m", field) + present, absent = p.FieldPresent("m", field), p.FieldAbsent("m", field) + if p.FieldStorageIsPointer(field) { + deref = `*` + } + } nullable := field.Message != nil || (!oneof && field.Desc.HasPresence()) repeated := field.Desc.Cardinality() == protoreflect.Repeated if repeated { - p.P(`if len(m.`, fieldname, `) > 0 {`) + p.P(`if len(`, store, `) > 0 {`) } else if nullable { if field.Desc.Cardinality() == protoreflect.Required { - p.P(`if m.`, fieldname, ` == nil {`) + p.P(`if `, absent, ` {`) p.P(`return 0, `, p.Ident("fmt", "Errorf"), `("proto: required field `, field.Desc.Name(), ` not set")`) p.P(`} else {`) } else { - p.P(`if m.`, fieldname, ` != nil {`) + p.P(`if `, present, ` {`) } } packed := field.Desc.IsPacked() @@ -136,54 +147,54 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { switch field.Desc.Kind() { case protoreflect.DoubleKind: if packed { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.P(`f`, numGen.Next(), ` := `, p.Ident("math", "Float64bits"), `(float64(`, val, `))`) p.encodeFixed64("f", numGen.Current()) p.P(`}`) - p.encodeVarint(`len(m.`, fieldname, `) * 8`) + p.encodeVarint(`len(`, store, `) * 8`) p.encodeKey(fieldNumber, wireType) } else if repeated { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.P(`f`, numGen.Next(), ` := `, p.Ident("math", "Float64bits"), `(float64(`, val, `))`) p.encodeFixed64("f", numGen.Current()) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else if nullable { - p.encodeFixed64(p.Ident("math", "Float64bits"), `(float64(*m.`+fieldname, `))`) + p.encodeFixed64(p.Ident("math", "Float64bits"), `(float64(`+deref+store, `))`) p.encodeKey(fieldNumber, wireType) } else if !oneof { - p.P(`if m.`, fieldname, ` != 0 {`) - p.encodeFixed64(p.Ident("math", "Float64bits"), `(float64(m.`, fieldname, `))`) + p.P(`if `, store, ` != 0 {`) + p.encodeFixed64(p.Ident("math", "Float64bits"), `(float64(`, store, `))`) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else { - p.encodeFixed64(p.Ident("math", "Float64bits"), `(float64(m.`+fieldname, `))`) + p.encodeFixed64(p.Ident("math", "Float64bits"), `(float64(`+store, `))`) p.encodeKey(fieldNumber, wireType) } case protoreflect.FloatKind: if packed { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.P(`f`, numGen.Next(), ` := `, p.Ident("math", "Float32bits"), `(float32(`, val, `))`) p.encodeFixed32("f" + numGen.Current()) p.P(`}`) - p.encodeVarint(`len(m.`, fieldname, `) * 4`) + p.encodeVarint(`len(`, store, `) * 4`) p.encodeKey(fieldNumber, wireType) } else if repeated { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.P(`f`, numGen.Next(), ` := `, p.Ident("math", "Float32bits"), `(float32(`, val, `))`) p.encodeFixed32("f" + numGen.Current()) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else if nullable { - p.encodeFixed32(p.Ident("math", "Float32bits"), `(float32(*m.`+fieldname, `))`) + p.encodeFixed32(p.Ident("math", "Float32bits"), `(float32(`+deref+store, `))`) p.encodeKey(fieldNumber, wireType) } else if !oneof { - p.P(`if m.`, fieldname, ` != 0 {`) - p.encodeFixed32(p.Ident("math", "Float32bits"), `(float32(m.`+fieldname, `))`) + p.P(`if `, store, ` != 0 {`) + p.encodeFixed32(p.Ident("math", "Float32bits"), `(float32(`+store, `))`) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else { - p.encodeFixed32(p.Ident("math", "Float32bits"), `(float32(m.`+fieldname, `))`) + p.encodeFixed32(p.Ident("math", "Float32bits"), `(float32(`+store, `))`) p.encodeKey(fieldNumber, wireType) } case protoreflect.Int64Kind, protoreflect.Uint64Kind, protoreflect.Int32Kind, protoreflect.Uint32Kind, protoreflect.EnumKind: @@ -192,7 +203,7 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { total := "pksize" + numGen.Next() p.P(`var `, total, ` int`) - p.P(`for _, num := range m.`, fieldname, ` {`) + p.P(`for _, num := range `, store, ` {`) p.P(total, ` += `, p.Helper("SizeOfVarint"), `(uint64(num))`) p.P(`}`) @@ -201,10 +212,10 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { switch field.Desc.Kind() { case protoreflect.Int64Kind, protoreflect.Int32Kind, protoreflect.EnumKind: - p.P(`for _, num1 := range m.`, fieldname, ` {`) + p.P(`for _, num1 := range `, store, ` {`) p.P(`num := uint64(num1)`) default: - p.P(`for _, num := range m.`, fieldname, ` {`) + p.P(`for _, num := range `, store, ` {`) } p.P(`for num >= 1<<7 {`) p.P(`dAtA[`, jvar, `] = uint8(uint64(num)&0x7f|0x80)`) @@ -218,73 +229,73 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { p.encodeVarint(total) p.encodeKey(fieldNumber, wireType) } else if repeated { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.encodeVarint(val) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else if nullable { - p.encodeVarint(`*m.`, fieldname) + p.encodeVarint(deref, store) p.encodeKey(fieldNumber, wireType) } else if !oneof { - p.P(`if m.`, fieldname, ` != 0 {`) - p.encodeVarint(`m.`, fieldname) + p.P(`if `, store, ` != 0 {`) + p.encodeVarint(store) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else { - p.encodeVarint(`m.`, fieldname) + p.encodeVarint(store) p.encodeKey(fieldNumber, wireType) } case protoreflect.Fixed64Kind, protoreflect.Sfixed64Kind: if packed { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.encodeFixed64(val) p.P(`}`) - p.encodeVarint(`len(m.`, fieldname, `) * 8`) + p.encodeVarint(`len(`, store, `) * 8`) p.encodeKey(fieldNumber, wireType) } else if repeated { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.encodeFixed64(val) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else if nullable { - p.encodeFixed64("*m.", fieldname) + p.encodeFixed64(deref, store) p.encodeKey(fieldNumber, wireType) } else if !oneof { - p.P(`if m.`, fieldname, ` != 0 {`) - p.encodeFixed64("m.", fieldname) + p.P(`if `, store, ` != 0 {`) + p.encodeFixed64(store) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else { - p.encodeFixed64("m.", fieldname) + p.encodeFixed64(store) p.encodeKey(fieldNumber, wireType) } case protoreflect.Fixed32Kind, protoreflect.Sfixed32Kind: if packed { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.encodeFixed32(val) p.P(`}`) - p.encodeVarint(`len(m.`, fieldname, `) * 4`) + p.encodeVarint(`len(`, store, `) * 4`) p.encodeKey(fieldNumber, wireType) } else if repeated { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.encodeFixed32(val) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else if nullable { - p.encodeFixed32("*m." + fieldname) + p.encodeFixed32(deref + store) p.encodeKey(fieldNumber, wireType) } else if !oneof { - p.P(`if m.`, fieldname, ` != 0 {`) - p.encodeFixed32("m." + fieldname) + p.P(`if `, store, ` != 0 {`) + p.encodeFixed32(store) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else { - p.encodeFixed32("m." + fieldname) + p.encodeFixed32(store) p.encodeKey(fieldNumber, wireType) } case protoreflect.BoolKind: if packed { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.P(`i--`) p.P(`if `, val, ` {`) p.P(`dAtA[i] = 1`) @@ -292,10 +303,10 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { p.P(`dAtA[i] = 0`) p.P(`}`) p.P(`}`) - p.encodeVarint(`len(m.`, fieldname, `)`) + p.encodeVarint(`len(`, store, `)`) p.encodeKey(fieldNumber, wireType) } else if repeated { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.P(`i--`) p.P(`if `, val, ` {`) p.P(`dAtA[i] = 1`) @@ -306,16 +317,16 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { p.P(`}`) } else if nullable { p.P(`i--`) - p.P(`if *m.`, fieldname, ` {`) + p.P(`if `, deref, store, ` {`) p.P(`dAtA[i] = 1`) p.P(`} else {`) p.P(`dAtA[i] = 0`) p.P(`}`) p.encodeKey(fieldNumber, wireType) } else if !oneof { - p.P(`if m.`, fieldname, ` {`) + p.P(`if `, store, ` {`) p.P(`i--`) - p.P(`if m.`, fieldname, ` {`) + p.P(`if `, store, ` {`) p.P(`dAtA[i] = 1`) p.P(`} else {`) p.P(`dAtA[i] = 0`) @@ -324,7 +335,7 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { p.P(`}`) } else { p.P(`i--`) - p.P(`if m.`, fieldname, ` {`) + p.P(`if `, store, ` {`) p.P(`dAtA[i] = 1`) p.P(`} else {`) p.P(`dAtA[i] = 0`) @@ -333,33 +344,33 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { } case protoreflect.StringKind: if repeated { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.P(`i -= len(`, val, `)`) p.P(`copy(dAtA[i:], `, val, `)`) p.encodeVarint(`len(`, val, `)`) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else if nullable { - p.P(`i -= len(*m.`, fieldname, `)`) - p.P(`copy(dAtA[i:], *m.`, fieldname, `)`) - p.encodeVarint(`len(*m.`, fieldname, `)`) + p.P(`i -= len(`, deref, store, `)`) + p.P(`copy(dAtA[i:], `, deref, store, `)`) + p.encodeVarint(`len(`, deref, store, `)`) p.encodeKey(fieldNumber, wireType) } else if !oneof { - p.P(`if len(m.`, fieldname, `) > 0 {`) - p.P(`i -= len(m.`, fieldname, `)`) - p.P(`copy(dAtA[i:], m.`, fieldname, `)`) - p.encodeVarint(`len(m.`, fieldname, `)`) + p.P(`if len(`, store, `) > 0 {`) + p.P(`i -= len(`, store, `)`) + p.P(`copy(dAtA[i:], `, store, `)`) + p.encodeVarint(`len(`, store, `)`) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else { - p.P(`i -= len(m.`, fieldname, `)`) - p.P(`copy(dAtA[i:], m.`, fieldname, `)`) - p.encodeVarint(`len(m.`, fieldname, `)`) + p.P(`i -= len(`, store, `)`) + p.P(`copy(dAtA[i:], `, store, `)`) + p.encodeVarint(`len(`, store, `)`) p.encodeKey(fieldNumber, wireType) } case protoreflect.GroupKind: p.encodeKey(fieldNumber, protowire.EndGroupType) - p.marshalBackward(`m.`+fieldname, false, field.Message) + p.marshalBackward(store, false, field.Message) p.encodeKey(fieldNumber, protowire.StartGroupType) case protoreflect.MessageKind: if field.Desc.IsMap() { @@ -370,8 +381,8 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { var val string if p.Stable && keyKind != protoreflect.BoolKind { keysName := `keysFor` + fieldname - p.P(keysName, ` := make([]`, goTypK, `, 0, len(m.`, fieldname, `))`) - p.P(`for k := range m.`, fieldname, ` {`) + p.P(keysName, ` := make([]`, goTypK, `, 0, len(`, store, `))`) + p.P(`for k := range `, store, ` {`) p.P(keysName, ` = append(`, keysName, `, `, goTypK, `(k))`) p.P(`}`) p.P(p.Ident("sort", "Slice"), `(`, keysName, `, func(i, j int) bool {`) @@ -379,13 +390,13 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { p.P(`})`) val = p.reverseListRange(keysName) } else { - p.P(`for k := range m.`, fieldname, ` {`) + p.P(`for k := range `, store, ` {`) val = "k" } if p.Stable { - p.P(`v := m.`, fieldname, `[`, goTypK, `(`, val, `)]`) + p.P(`v := `, store, `[`, goTypK, `(`, val, `)]`) } else { - p.P(`v := m.`, fieldname, `[`, val, `]`) + p.P(`v := `, store, `[`, val, `]`) } p.P(`baseI := i`) @@ -399,33 +410,33 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { p.encodeKey(fieldNumber, wireType) p.P(`}`) } else if repeated { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.marshalBackward(val, true, field.Message) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else { - p.marshalBackward(`m.`+fieldname, true, field.Message) + p.marshalBackward(store, true, field.Message) p.encodeKey(fieldNumber, wireType) } case protoreflect.BytesKind: if repeated { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.P(`i -= len(`, val, `)`) p.P(`copy(dAtA[i:], `, val, `)`) p.encodeVarint(`len(`, val, `)`) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else if !oneof && !field.Desc.HasPresence() { - p.P(`if len(m.`, fieldname, `) > 0 {`) - p.P(`i -= len(m.`, fieldname, `)`) - p.P(`copy(dAtA[i:], m.`, fieldname, `)`) - p.encodeVarint(`len(m.`, fieldname, `)`) + p.P(`if len(`, store, `) > 0 {`) + p.P(`i -= len(`, store, `)`) + p.P(`copy(dAtA[i:], `, store, `)`) + p.encodeVarint(`len(`, store, `)`) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else { - p.P(`i -= len(m.`, fieldname, `)`) - p.P(`copy(dAtA[i:], m.`, fieldname, `)`) - p.encodeVarint(`len(m.`, fieldname, `)`) + p.P(`i -= len(`, store, `)`) + p.P(`copy(dAtA[i:], `, store, `)`) + p.encodeVarint(`len(`, store, `)`) p.encodeKey(fieldNumber, wireType) } case protoreflect.Sint32Kind: @@ -434,13 +445,13 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { total := "pksize" + numGen.Next() p.P(`var `, total, ` int`) - p.P(`for _, num := range m.`, fieldname, ` {`) + p.P(`for _, num := range `, store, ` {`) p.P(total, ` += `, p.Helper("SizeOfZigzag"), `(uint64(num))`) p.P(`}`) p.P(`i -= `, total) p.P(jvar, `:= i`) - p.P(`for _, num := range m.`, fieldname, ` {`) + p.P(`for _, num := range `, store, ` {`) xvar := "x" + numGen.Next() p.P(xvar, ` := (uint32(num) << 1) ^ uint32((num >> 31))`) p.P(`for `, xvar, ` >= 1<<7 {`) @@ -455,21 +466,21 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { p.encodeVarint(total) p.encodeKey(fieldNumber, wireType) } else if repeated { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.P(`x`, numGen.Next(), ` := (uint32(`, val, `) << 1) ^ uint32((`, val, ` >> 31))`) p.encodeVarint(`x`, numGen.Current()) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else if nullable { - p.encodeVarint(`(uint32(*m.`, fieldname, `) << 1) ^ uint32((*m.`, fieldname, ` >> 31))`) + p.encodeVarint(`(uint32(`, deref, store, `) << 1) ^ uint32((`, deref, store, ` >> 31))`) p.encodeKey(fieldNumber, wireType) } else if !oneof { - p.P(`if m.`, fieldname, ` != 0 {`) - p.encodeVarint(`(uint32(m.`, fieldname, `) << 1) ^ uint32((m.`, fieldname, ` >> 31))`) + p.P(`if `, store, ` != 0 {`) + p.encodeVarint(`(uint32(`, store, `) << 1) ^ uint32((`, store, ` >> 31))`) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else { - p.encodeVarint(`(uint32(m.`, fieldname, `) << 1) ^ uint32((m.`, fieldname, ` >> 31))`) + p.encodeVarint(`(uint32(`, store, `) << 1) ^ uint32((`, store, ` >> 31))`) p.encodeKey(fieldNumber, wireType) } case protoreflect.Sint64Kind: @@ -478,13 +489,13 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { total := "pksize" + numGen.Next() p.P(`var `, total, ` int`) - p.P(`for _, num := range m.`, fieldname, ` {`) + p.P(`for _, num := range `, store, ` {`) p.P(total, ` += `, p.Helper("SizeOfZigzag"), `(uint64(num))`) p.P(`}`) p.P(`i -= `, total) p.P(jvar, `:= i`) - p.P(`for _, num := range m.`, fieldname, ` {`) + p.P(`for _, num := range `, store, ` {`) xvar := "x" + numGen.Next() p.P(xvar, ` := (uint64(num) << 1) ^ uint64((num >> 63))`) p.P(`for `, xvar, ` >= 1<<7 {`) @@ -499,21 +510,21 @@ func (p *marshal) field(oneof bool, numGen *counter, field *protogen.Field) { p.encodeVarint(total) p.encodeKey(fieldNumber, wireType) } else if repeated { - val := p.reverseListRange(`m.`, fieldname) + val := p.reverseListRange(store) p.P(`x`, numGen.Next(), ` := (uint64(`, val, `) << 1) ^ uint64((`, val, ` >> 63))`) p.encodeVarint("x" + numGen.Current()) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else if nullable { - p.encodeVarint(`(uint64(*m.`, fieldname, `) << 1) ^ uint64((*m.`, fieldname, ` >> 63))`) + p.encodeVarint(`(uint64(`, deref, store, `) << 1) ^ uint64((`, deref, store, ` >> 63))`) p.encodeKey(fieldNumber, wireType) } else if !oneof { - p.P(`if m.`, fieldname, ` != 0 {`) - p.encodeVarint(`(uint64(m.`, fieldname, `) << 1) ^ uint64((m.`, fieldname, ` >> 63))`) + p.P(`if `, store, ` != 0 {`) + p.encodeVarint(`(uint64(`, store, `) << 1) ^ uint64((`, store, ` >> 63))`) p.encodeKey(fieldNumber, wireType) p.P(`}`) } else { - p.encodeVarint(`(uint64(m.`, fieldname, `) << 1) ^ uint64((m.`, fieldname, ` >> 63))`) + p.encodeVarint(`(uint64(`, store, `) << 1) ^ uint64((`, store, ` >> 63))`) p.encodeKey(fieldNumber, wireType) } default: @@ -629,10 +640,10 @@ func (p *marshal) message(message *protogen.Message) { p.field(false, &numGen, field) } else { if p.IsWellKnownType(message) { - p.P(`if m, ok := m.`, field.Oneof.GoName, `.(*`, field.GoIdent, `); ok {`) + p.P(`if m, ok := `, p.OneofStore("m", field.Oneof), `.(*`, p.OneofWrapperIdent(field), `); ok {`) p.P(`msg := ((*`, p.WellKnownFieldMap(field), `)(m))`) } else { - p.P(`if msg, ok := m.`, field.Oneof.GoName, `.(*`, field.GoIdent.GoName, `); ok {`) + p.P(`if msg, ok := `, p.OneofStore("m", field.Oneof), `.(*`, p.OneofWrapperIdent(field).GoName, `); ok {`) } marshalForwardOneOf("msg") p.P(`}`) @@ -647,7 +658,7 @@ func (p *marshal) message(message *protogen.Message) { field := message.Fields[i] oneof := field.Oneof != nil && !field.Oneof.Desc.IsSynthetic() if oneof { - fieldname := field.Oneof.GoName + fieldname := p.OneofName(field.Oneof) if _, ok := oneofs[fieldname]; ok { continue } @@ -655,7 +666,7 @@ func (p *marshal) message(message *protogen.Message) { if p.IsWellKnownType(message) { p.P(`switch c := m.`, fieldname, `.(type) {`) for _, f := range field.Oneof.Fields { - p.P(`case *`, f.GoIdent, `:`) + p.P(`case *`, p.OneofWrapperIdent(f), `:`) marshalForwardOneOf(`(*`, p.WellKnownFieldMap(f), `)(c)`) } p.P(`}`) @@ -687,7 +698,7 @@ func (p *marshal) message(message *protogen.Message) { if field.Oneof == nil || field.Oneof.Desc.IsSynthetic() { continue } - ccTypeName := field.GoIdent.GoName + ccTypeName := p.OneofWrapperIdent(field).GoName p.P(`func (m *`, ccTypeName, `) `, p.methodMarshalTo(), `(dAtA []byte) (int, error) {`) p.P(`size := m.SizeVT()`) p.P(`return m.`, p.methodMarshalToSizedBuffer(), `(dAtA[:size])`) diff --git a/features/pool/pool.go b/features/pool/pool.go index 4f7efdca..5e6cecbe 100644 --- a/features/pool/pool.go +++ b/features/pool/pool.go @@ -51,9 +51,24 @@ func (p *pool) message(message *protogen.Message) { p.P(`if m != nil {`) var saved []*protogen.Field for _, field := range message.Fields { - fieldName := field.GoName - - if field.Desc.IsList() { + fieldName := p.FieldName(field) + + if field.Desc.IsList() && p.FieldStorageIsPointer(field) { + // Keep the pointer so the slice survives m.Reset(). + ptr := fmt.Sprintf("f%d", len(saved)) + p.P(ptr, ` := m.`, fieldName) + p.P(`if `, ptr, ` != nil {`) + p.P(`for _, mm := range *`, ptr, `{`) + if p.ShouldPool(field.Message) { + p.P(`mm.ResetVT()`) + } else { + p.P(`mm.Reset()`) + } + p.P(`}`) + p.P(`*`, ptr, ` = (*`, ptr, `)[:0]`) + p.P(`}`) + saved = append(saved, field) + } else if field.Desc.IsList() { switch field.Desc.Kind() { case protoreflect.MessageKind, protoreflect.GroupKind: p.P(`for _, mm := range m.`, fieldName, `{`) @@ -70,8 +85,8 @@ func (p *pool) message(message *protogen.Message) { saved = append(saved, field) } else if field.Oneof != nil && !field.Oneof.Desc.IsSynthetic() { if p.ShouldPool(field.Message) { - p.P(`if oneof, ok := m.`, field.Oneof.GoName, `.(*`, field.GoIdent, `); ok {`) - p.P(`oneof.`, fieldName, `.ReturnToVTPool()`) + p.P(`if oneof, ok := `, p.OneofStore("m", field.Oneof), `.(*`, p.OneofWrapperIdent(field), `); ok {`) + p.P(`oneof.`, field.GoName, `.ReturnToVTPool()`) p.P(`}`) } } else { @@ -81,6 +96,10 @@ func (p *pool) message(message *protogen.Message) { p.P(`m.`, fieldName, `.ReturnToVTPool()`) } case protoreflect.BytesKind: + // Retaining the buffer would contradict the bit m.Reset() cleared. + if p.UsesPresenceBit(field) { + break + } p.P(fmt.Sprintf("f%d", len(saved)), ` := m.`, fieldName, `[:0]`) saved = append(saved, field) } @@ -89,7 +108,7 @@ func (p *pool) message(message *protogen.Message) { p.P(`m.Reset()`) for i, field := range saved { - p.P(`m.`, field.GoName, ` = `, fmt.Sprintf("f%d", i)) + p.P(`m.`, p.FieldName(field), ` = `, fmt.Sprintf("f%d", i)) } p.P(`}`) p.P(`}`) diff --git a/features/size/size.go b/features/size/size.go index d7ac60f3..653d0ad2 100644 --- a/features/size/size.go +++ b/features/size/size.go @@ -59,13 +59,22 @@ func (p *size) messageSize(varName, sizeName string, message *protogen.Message) } func (p *size) field(oneof bool, field *protogen.Field, sizeName string) { - fieldname := field.GoName + // Oneof wrappers keep the exported field name at every API level. + store, deref := `m.`+field.GoName, `` + present := store + ` != nil` + if !oneof { + store = p.FieldSliceExpr("m", field) + present = p.FieldPresent("m", field) + if p.FieldStorageIsPointer(field) { + deref = `*` + } + } nullable := field.Message != nil || (!oneof && field.Desc.HasPresence()) repeated := field.Desc.Cardinality() == protoreflect.Repeated if repeated { - p.P(`if len(m.`, fieldname, `) > 0 {`) + p.P(`if len(`, store, `) > 0 {`) } else if nullable { - p.P(`if m.`, fieldname, ` != nil {`) + p.P(`if `, present, ` {`) } packed := field.Desc.IsPacked() wireType := generator.ProtoWireType(field.Desc.Kind()) @@ -77,11 +86,11 @@ func (p *size) field(oneof bool, field *protogen.Field, sizeName string) { switch field.Desc.Kind() { case protoreflect.DoubleKind, protoreflect.Fixed64Kind, protoreflect.Sfixed64Kind: if packed { - p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(len(m.`, fieldname, `)*8))`, `+len(m.`, fieldname, `)*8`) + p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(len(`, store, `)*8))`, `+len(`, store, `)*8`) } else if repeated { - p.P(`n+=`, strconv.Itoa(key+8), `*len(m.`, fieldname, `)`) + p.P(`n+=`, strconv.Itoa(key+8), `*len(`, store, `)`) } else if !oneof && !nullable { - p.P(`if m.`, fieldname, ` != 0 {`) + p.P(`if `, store, ` != 0 {`) p.P(`n+=`, strconv.Itoa(key+8)) p.P(`}`) } else { @@ -89,11 +98,11 @@ func (p *size) field(oneof bool, field *protogen.Field, sizeName string) { } case protoreflect.FloatKind, protoreflect.Fixed32Kind, protoreflect.Sfixed32Kind: if packed { - p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(len(m.`, fieldname, `)*4))`, `+len(m.`, fieldname, `)*4`) + p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(len(`, store, `)*4))`, `+len(`, store, `)*4`) } else if repeated { - p.P(`n+=`, strconv.Itoa(key+4), `*len(m.`, fieldname, `)`) + p.P(`n+=`, strconv.Itoa(key+4), `*len(`, store, `)`) } else if !oneof && !nullable { - p.P(`if m.`, fieldname, ` != 0 {`) + p.P(`if `, store, ` != 0 {`) p.P(`n+=`, strconv.Itoa(key+4)) p.P(`}`) } else { @@ -102,30 +111,30 @@ func (p *size) field(oneof bool, field *protogen.Field, sizeName string) { case protoreflect.Int64Kind, protoreflect.Uint64Kind, protoreflect.Uint32Kind, protoreflect.EnumKind, protoreflect.Int32Kind: if packed { p.P(`l = 0`) - p.P(`for _, e := range m.`, fieldname, ` {`) + p.P(`for _, e := range `, store, ` {`) p.P(`l+=`, p.Helper("SizeOfVarint"), `(uint64(e))`) p.P(`}`) p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(l))+l`) } else if repeated { - p.P(`for _, e := range m.`, fieldname, ` {`) + p.P(`for _, e := range `, store, ` {`) p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(e))`) p.P(`}`) } else if nullable { - p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(*m.`, fieldname, `))`) + p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(`, deref, store, `))`) } else if !oneof { - p.P(`if m.`, fieldname, ` != 0 {`) - p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(m.`, fieldname, `))`) + p.P(`if `, store, ` != 0 {`) + p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(`, store, `))`) p.P(`}`) } else { - p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(m.`, fieldname, `))`) + p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(`, store, `))`) } case protoreflect.BoolKind: if packed { - p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(len(m.`, fieldname, `)))`, `+len(m.`, fieldname, `)*1`) + p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(len(`, store, `)))`, `+len(`, store, `)*1`) } else if repeated { - p.P(`n+=`, strconv.Itoa(key+1), `*len(m.`, fieldname, `)`) + p.P(`n+=`, strconv.Itoa(key+1), `*len(`, store, `)`) } else if !oneof && !nullable { - p.P(`if m.`, fieldname, ` {`) + p.P(`if `, store, ` {`) p.P(`n+=`, strconv.Itoa(key+1)) p.P(`}`) } else { @@ -133,31 +142,31 @@ func (p *size) field(oneof bool, field *protogen.Field, sizeName string) { } case protoreflect.StringKind: if repeated { - p.P(`for _, s := range m.`, fieldname, ` { `) + p.P(`for _, s := range `, store, ` { `) p.P(`l = len(s)`) p.P(`n+=`, strconv.Itoa(key), `+l+`, p.Helper("SizeOfVarint"), `(uint64(l))`) p.P(`}`) } else if nullable { - p.P(`l=len(*m.`, fieldname, `)`) + p.P(`l=len(`, deref, store, `)`) p.P(`n+=`, strconv.Itoa(key), `+l+`, p.Helper("SizeOfVarint"), `(uint64(l))`) } else if !oneof { - p.P(`l=len(m.`, fieldname, `)`) + p.P(`l=len(`, store, `)`) p.P(`if l > 0 {`) p.P(`n+=`, strconv.Itoa(key), `+l+`, p.Helper("SizeOfVarint"), `(uint64(l))`) p.P(`}`) } else { - p.P(`l=len(m.`, fieldname, `)`) + p.P(`l=len(`, store, `)`) p.P(`n+=`, strconv.Itoa(key), `+l+`, p.Helper("SizeOfVarint"), `(uint64(l))`) } case protoreflect.GroupKind: - p.messageSize("m."+fieldname, sizeName, field.Message) + p.messageSize(store, sizeName, field.Message) p.P(`n+=l+`, strconv.Itoa(2*key)) case protoreflect.MessageKind: if field.Desc.IsMap() { fieldKeySize := generator.KeySize(field.Desc.Number(), generator.ProtoWireType(field.Desc.Kind())) keyKeySize := generator.KeySize(1, generator.ProtoWireType(field.Message.Fields[0].Desc.Kind())) valueKeySize := generator.KeySize(2, generator.ProtoWireType(field.Message.Fields[1].Desc.Kind())) - p.P(`for k, v := range m.`, fieldname, ` { `) + p.P(`for k, v := range `, store, ` { `) p.P(`_ = k`) p.P(`_ = v`) sum := []interface{}{strconv.Itoa(keyKeySize)} @@ -219,48 +228,48 @@ func (p *size) field(oneof bool, field *protogen.Field, sizeName string) { p.P(`n+=mapEntrySize+`, fieldKeySize, `+`, p.Helper("SizeOfVarint"), `(uint64(mapEntrySize))`) p.P(`}`) } else if field.Desc.IsList() { - p.P(`for _, e := range m.`, fieldname, ` { `) + p.P(`for _, e := range `, store, ` { `) p.messageSize("e", sizeName, field.Message) p.P(`n+=`, strconv.Itoa(key), `+l+`, p.Helper("SizeOfVarint"), `(uint64(l))`) p.P(`}`) } else { - p.messageSize("m."+fieldname, sizeName, field.Message) + p.messageSize(store, sizeName, field.Message) p.P(`n+=`, strconv.Itoa(key), `+l+`, p.Helper("SizeOfVarint"), `(uint64(l))`) } case protoreflect.BytesKind: if repeated { - p.P(`for _, b := range m.`, fieldname, ` { `) + p.P(`for _, b := range `, store, ` { `) p.P(`l = len(b)`) p.P(`n+=`, strconv.Itoa(key), `+l+`, p.Helper("SizeOfVarint"), `(uint64(l))`) p.P(`}`) } else if !oneof && !field.Desc.HasPresence() { - p.P(`l=len(m.`, fieldname, `)`) + p.P(`l=len(`, store, `)`) p.P(`if l > 0 {`) p.P(`n+=`, strconv.Itoa(key), `+l+`, p.Helper("SizeOfVarint"), `(uint64(l))`) p.P(`}`) } else { - p.P(`l=len(m.`, fieldname, `)`) + p.P(`l=len(`, store, `)`) p.P(`n+=`, strconv.Itoa(key), `+l+`, p.Helper("SizeOfVarint"), `(uint64(l))`) } case protoreflect.Sint32Kind, protoreflect.Sint64Kind: if packed { p.P(`l = 0`) - p.P(`for _, e := range m.`, fieldname, ` {`) + p.P(`for _, e := range `, store, ` {`) p.P(`l+=`, p.Helper("SizeOfZigzag"), `(uint64(e))`) p.P(`}`) p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfVarint"), `(uint64(l))+l`) } else if repeated { - p.P(`for _, e := range m.`, fieldname, ` {`) + p.P(`for _, e := range `, store, ` {`) p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfZigzag"), `(uint64(e))`) p.P(`}`) } else if nullable { - p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfZigzag"), `(uint64(*m.`, fieldname, `))`) + p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfZigzag"), `(uint64(`, deref, store, `))`) } else if !oneof { - p.P(`if m.`, fieldname, ` != 0 {`) - p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfZigzag"), `(uint64(m.`, fieldname, `))`) + p.P(`if `, store, ` != 0 {`) + p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfZigzag"), `(uint64(`, store, `))`) p.P(`}`) } else { - p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfZigzag"), `(uint64(m.`, fieldname, `))`) + p.P(`n+=`, strconv.Itoa(key), `+`, p.Helper("SizeOfZigzag"), `(uint64(`, store, `))`) } default: panic("not implemented") @@ -269,7 +278,7 @@ func (p *size) field(oneof bool, field *protogen.Field, sizeName string) { // See https://github.com/planetscale/vtprotobuf/issues/61 // Size is always keysize + 1 so just hardcode that here if oneof && field.Desc.Kind() == protoreflect.MessageKind && !field.Desc.IsMap() && !field.Desc.IsList() { - p.P("} else { n += ", strconv.Itoa(key + 1), " }") + p.P("} else { n += ", strconv.Itoa(key+1), " }") } else if repeated || nullable { p.P(`}`) } @@ -301,7 +310,7 @@ func (p *size) message(message *protogen.Message) { if !oneof { p.field(false, field, sizeName) } else { - fieldname := field.Oneof.GoName + fieldname := p.OneofName(field.Oneof) if _, ok := oneofs[fieldname]; ok { continue } @@ -309,7 +318,7 @@ func (p *size) message(message *protogen.Message) { if p.IsWellKnownType(message) { p.P(`switch c := m.`, fieldname, `.(type) {`) for _, f := range field.Oneof.Fields { - p.P(`case *`, f.GoIdent, `:`) + p.P(`case *`, p.OneofWrapperIdent(f), `:`) p.P(`n += (*`, p.WellKnownFieldMap(f), `)(c).`, sizeName, `()`) } p.P(`}`) @@ -331,7 +340,7 @@ func (p *size) message(message *protogen.Message) { if field.Oneof == nil || field.Oneof.Desc.IsSynthetic() { continue } - ccTypeName := field.GoIdent + ccTypeName := p.OneofWrapperIdent(field) if p.IsWellKnownType(message) && p.IsLocalMessage(message) { ccTypeName.GoImportPath = "" } diff --git a/features/unmarshal/unmarshal.go b/features/unmarshal/unmarshal.go index c5540a51..2b2d96d2 100644 --- a/features/unmarshal/unmarshal.go +++ b/features/unmarshal/unmarshal.go @@ -38,9 +38,8 @@ type unmarshal struct { var _ generator.FeatureGenerator = (*unmarshal)(nil) func (p *unmarshal) GenerateFile(file *protogen.File) bool { - proto3 := file.Desc.Syntax() == protoreflect.Proto3 for _, message := range file.Messages { - p.message(proto3, message) + p.message(message) } return p.once @@ -283,139 +282,161 @@ func (p *unmarshal) noStarOrSliceType(field *protogen.Field) string { return typ } -func (p *unmarshal) fieldItem(field *protogen.Field, fieldname string, message *protogen.Message, proto3 bool) { +func (p *unmarshal) setPresentValue(field *protogen.Field, fieldname, value string) { + if p.FieldStorageIsPointer(field) { + p.P(`m.`, fieldname, ` = &`, value) + } else { + p.P(`m.`, fieldname, ` = `, value) + } + p.FieldSetPresent("m", field) +} + +// listStore allocates the indirection the opaque layout puts in front of +// repeated message fields, and returns the slice expression. +func (p *unmarshal) listStore(field *protogen.Field, fieldname string) string { + store := `m.` + fieldname + if !p.FieldStorageIsPointer(field) { + return store + } + goType, _ := p.FieldGoType(field) + p.P(`if `, store, ` == nil {`) + p.P(store, ` = &`, goType, `{}`) + p.P(`}`) + return `(*` + store + `)` +} + +func (p *unmarshal) fieldItem(field *protogen.Field, fieldname string, message *protogen.Message) { repeated := field.Desc.Cardinality() == protoreflect.Repeated typ := p.noStarOrSliceType(field) oneof := field.Oneof != nil && !field.Oneof.Desc.IsSynthetic() - nullable := field.Oneof != nil && field.Oneof.Desc.IsSynthetic() switch field.Desc.Kind() { case protoreflect.DoubleKind: p.P(`var v uint64`) p.decodeFixed64("v", "uint64") if oneof { - p.P(`m.`, fieldname, ` = &`, field.GoIdent, `{`, field.GoName, ": ", typ, "(", p.Ident("math", `Float64frombits`), `(v))}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), `{`, field.GoName, ": ", typ, "(", p.Ident("math", `Float64frombits`), `(v))}`) } else if repeated { p.P(`v2 := `, typ, "(", p.Ident("math", "Float64frombits"), `(v))`) p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v2)`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = `, typ, "(", p.Ident("math", "Float64frombits"), `(v))`) } else { p.P(`v2 := `, typ, "(", p.Ident("math", "Float64frombits"), `(v))`) - p.P(`m.`, fieldname, ` = &v2`) + p.setPresentValue(field, fieldname, "v2") } case protoreflect.FloatKind: p.P(`var v uint32`) p.decodeFixed32("v", "uint32") if oneof { - p.P(`m.`, fieldname, ` = &`, field.GoIdent, `{`, field.GoName, ": ", typ, "(", p.Ident("math", "Float32frombits"), `(v))}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), `{`, field.GoName, ": ", typ, "(", p.Ident("math", "Float32frombits"), `(v))}`) } else if repeated { p.P(`v2 := `, typ, "(", p.Ident("math", "Float32frombits"), `(v))`) p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v2)`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = `, typ, "(", p.Ident("math", "Float32frombits"), `(v))`) } else { p.P(`v2 := `, typ, "(", p.Ident("math", "Float32frombits"), `(v))`) - p.P(`m.`, fieldname, ` = &v2`) + p.setPresentValue(field, fieldname, "v2") } case protoreflect.Int64Kind: if oneof { p.P(`var v `, typ) p.decodeVarint("v", typ) - p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: v}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), "{", field.GoName, `: v}`) } else if repeated { p.P(`var v `, typ) p.decodeVarint("v", typ) p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = 0`) p.decodeVarint("m."+fieldname, typ) } else { p.P(`var v `, typ) p.decodeVarint("v", typ) - p.P(`m.`, fieldname, ` = &v`) + p.setPresentValue(field, fieldname, "v") } case protoreflect.Uint64Kind: if oneof { p.P(`var v `, typ) p.decodeVarint("v", typ) - p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: v}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), "{", field.GoName, `: v}`) } else if repeated { p.P(`var v `, typ) p.decodeVarint("v", typ) p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = 0`) p.decodeVarint("m."+fieldname, typ) } else { p.P(`var v `, typ) p.decodeVarint("v", typ) - p.P(`m.`, fieldname, ` = &v`) + p.setPresentValue(field, fieldname, "v") } case protoreflect.Int32Kind: if oneof { p.P(`var v `, typ) p.decodeVarint("v", typ) - p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: v}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), "{", field.GoName, `: v}`) } else if repeated { p.P(`var v `, typ) p.decodeVarint("v", typ) p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = 0`) p.decodeVarint("m."+fieldname, typ) } else { p.P(`var v `, typ) p.decodeVarint("v", typ) - p.P(`m.`, fieldname, ` = &v`) + p.setPresentValue(field, fieldname, "v") } case protoreflect.Fixed64Kind: if oneof { p.P(`var v `, typ) p.decodeFixed64("v", typ) - p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: v}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), "{", field.GoName, `: v}`) } else if repeated { p.P(`var v `, typ) p.decodeFixed64("v", typ) p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = 0`) p.decodeFixed64("m."+fieldname, typ) } else { p.P(`var v `, typ) p.decodeFixed64("v", typ) - p.P(`m.`, fieldname, ` = &v`) + p.setPresentValue(field, fieldname, "v") } case protoreflect.Fixed32Kind: if oneof { p.P(`var v `, typ) p.decodeFixed32("v", typ) - p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: v}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), "{", field.GoName, `: v}`) } else if repeated { p.P(`var v `, typ) p.decodeFixed32("v", typ) p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = 0`) p.decodeFixed32("m."+fieldname, typ) } else { p.P(`var v `, typ) p.decodeFixed32("v", typ) - p.P(`m.`, fieldname, ` = &v`) + p.setPresentValue(field, fieldname, "v") } case protoreflect.BoolKind: p.P(`var v int`) p.decodeVarint("v", "int") if oneof { p.P(`b := `, typ, `(v != 0)`) - p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: b}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), "{", field.GoName, `: b}`) } else if repeated { p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, `, typ, `(v != 0))`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = `, typ, `(v != 0)`) } else { p.P(`b := `, typ, `(v != 0)`) - p.P(`m.`, fieldname, ` = &b`) + p.setPresentValue(field, fieldname, "b") } case protoreflect.StringKind: unique := proto.GetExtension(field.Desc.Options(), vtproto.E_Options).(*vtproto.Opts).GetUnique() @@ -449,14 +470,14 @@ func (p *unmarshal) fieldItem(field *protogen.Field, fieldname string, message * p.P(`}`) } if oneof { - p.P(`m.`, fieldname, ` = &`, field.GoIdent, `{`, field.GoName, ": ", str, `}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), `{`, field.GoName, ": ", str, `}`) } else if repeated { p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, `, str, `)`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = `, str) } else { p.P(`s := `, str) - p.P(`m.`, fieldname, ` = &s`) + p.setPresentValue(field, fieldname, "s") } p.P(`iNdEx = postIndex`) case protoreflect.GroupKind: @@ -495,7 +516,7 @@ func (p *unmarshal) fieldItem(field *protogen.Field, fieldname string, message * if oneof { buf := `dAtA[iNdEx:postIndex]` msgname := p.noStarOrSliceType(field) - p.P(`if oneof, ok := m.`, fieldname, `.(*`, field.GoIdent, `); ok {`) + p.P(`if oneof, ok := m.`, fieldname, `.(*`, p.OneofWrapperIdent(field), `); ok {`) p.decodeMessage("oneof."+field.GoName, buf, field.Message) p.P(`} else {`) if p.ShouldPool(message) && p.ShouldPool(field.Message) { @@ -504,7 +525,7 @@ func (p *unmarshal) fieldItem(field *protogen.Field, fieldname string, message * p.P(`v := &`, msgname, `{}`) } p.decodeMessage("v", buf, field.Message) - p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: v}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), "{", field.GoName, `: v}`) p.P(`}`) } else if field.Desc.IsMap() { unique := proto.GetExtension(field.Desc.Options(), vtproto.E_Options).(*vtproto.Opts).GetUnique() @@ -547,19 +568,20 @@ func (p *unmarshal) fieldItem(field *protogen.Field, fieldname string, message * p.P(`}`) p.P(`m.`, fieldname, `[mapkey] = mapvalue`) } else if repeated { + list := p.listStore(field, fieldname) if p.ShouldPool(message) { - p.P(`if len(m.`, fieldname, `) == cap(m.`, fieldname, `) {`) - p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, &`, field.Message.GoIdent, `{})`) + p.P(`if len(`, list, `) == cap(`, list, `) {`) + p.P(list, ` = append(`, list, `, &`, field.Message.GoIdent, `{})`) p.P(`} else {`) - p.P(`m.`, fieldname, ` = m.`, fieldname, `[:len(m.`, fieldname, `) + 1]`) - p.P(`if m.`, fieldname, `[len(m.`, fieldname, `) - 1] == nil {`) - p.P(`m.`, fieldname, `[len(m.`, fieldname, `) - 1] = &`, field.Message.GoIdent, `{}`) + p.P(list, ` = `, list, `[:len(`, list, `) + 1]`) + p.P(`if `, list, `[len(`, list, `) - 1] == nil {`) + p.P(list, `[len(`, list, `) - 1] = &`, field.Message.GoIdent, `{}`) p.P(`}`) p.P(`}`) } else { - p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, &`, field.Message.GoIdent, `{})`) + p.P(list, ` = append(`, list, `, &`, field.Message.GoIdent, `{})`) } - varname := fmt.Sprintf("m.%s[len(m.%s) - 1]", fieldname, fieldname) + varname := fmt.Sprintf("%s[len(%s) - 1]", list, list) buf := `dAtA[iNdEx:postIndex]` p.decodeMessage(varname, buf, field.Message) } else { @@ -594,7 +616,7 @@ func (p *unmarshal) fieldItem(field *protogen.Field, fieldname string, message * p.P(`v := make([]byte, postIndex-iNdEx)`) p.P(`copy(v, dAtA[iNdEx:postIndex])`) } - p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: v}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), "{", field.GoName, `: v}`) } else if repeated { if p.unsafe { p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, dAtA[iNdEx:postIndex])`) @@ -611,120 +633,122 @@ func (p *unmarshal) fieldItem(field *protogen.Field, fieldname string, message * p.P(`m.`, fieldname, ` = []byte{}`) p.P(`}`) } + // Bytes have no pointer to carry presence under the opaque layout. + p.FieldSetPresent("m", field) } p.P(`iNdEx = postIndex`) case protoreflect.Uint32Kind: if oneof { p.P(`var v `, typ) p.decodeVarint("v", typ) - p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: v}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), "{", field.GoName, `: v}`) } else if repeated { p.P(`var v `, typ) p.decodeVarint("v", typ) p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = 0`) p.decodeVarint("m."+fieldname, typ) } else { p.P(`var v `, typ) p.decodeVarint("v", typ) - p.P(`m.`, fieldname, ` = &v`) + p.setPresentValue(field, fieldname, "v") } case protoreflect.EnumKind: if oneof { p.P(`var v `, typ) p.decodeVarint("v", typ) - p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: v}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), "{", field.GoName, `: v}`) } else if repeated { p.P(`var v `, typ) p.decodeVarint("v", typ) p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = 0`) p.decodeVarint("m."+fieldname, typ) } else { p.P(`var v `, typ) p.decodeVarint("v", typ) - p.P(`m.`, fieldname, ` = &v`) + p.setPresentValue(field, fieldname, "v") } case protoreflect.Sfixed32Kind: if oneof { p.P(`var v `, typ) p.decodeFixed32("v", typ) - p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: v}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), "{", field.GoName, `: v}`) } else if repeated { p.P(`var v `, typ) p.decodeFixed32("v", typ) p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = 0`) p.decodeFixed32("m."+fieldname, typ) } else { p.P(`var v `, typ) p.decodeFixed32("v", typ) - p.P(`m.`, fieldname, ` = &v`) + p.setPresentValue(field, fieldname, "v") } case protoreflect.Sfixed64Kind: if oneof { p.P(`var v `, typ) p.decodeFixed64("v", typ) - p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: v}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), "{", field.GoName, `: v}`) } else if repeated { p.P(`var v `, typ) p.decodeFixed64("v", typ) p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = 0`) p.decodeFixed64("m."+fieldname, typ) } else { p.P(`var v `, typ) p.decodeFixed64("v", typ) - p.P(`m.`, fieldname, ` = &v`) + p.setPresentValue(field, fieldname, "v") } case protoreflect.Sint32Kind: p.P(`var v `, typ) p.decodeVarint("v", typ) p.P(`v = `, typ, `((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31))`) if oneof { - p.P(`m.`, fieldname, ` = &`, field.GoIdent, "{", field.GoName, `: v}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), "{", field.GoName, `: v}`) } else if repeated { p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, v)`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = v`) } else { - p.P(`m.`, fieldname, ` = &v`) + p.setPresentValue(field, fieldname, "v") } case protoreflect.Sint64Kind: p.P(`var v uint64`) p.decodeVarint("v", "uint64") p.P(`v = (v >> 1) ^ uint64((int64(v&1)<<63)>>63)`) if oneof { - p.P(`m.`, fieldname, ` = &`, field.GoIdent, `{`, field.GoName, ": ", typ, `(v)}`) + p.P(`m.`, fieldname, ` = &`, p.OneofWrapperIdent(field), `{`, field.GoName, ": ", typ, `(v)}`) } else if repeated { p.P(`m.`, fieldname, ` = append(m.`, fieldname, `, `, typ, `(v))`) - } else if proto3 && !nullable { + } else if !field.Desc.HasPresence() { p.P(`m.`, fieldname, ` = `, typ, `(v)`) } else { p.P(`v2 := `, typ, `(v)`) - p.P(`m.`, fieldname, ` = &v2`) + p.setPresentValue(field, fieldname, "v2") } default: panic("not implemented") } } -func (p *unmarshal) field(proto3, oneof bool, field *protogen.Field, message *protogen.Message, required protoreflect.FieldNumbers) { - fieldname := field.GoName - errFieldname := fieldname +func (p *unmarshal) field(oneof bool, field *protogen.Field, message *protogen.Message, required protoreflect.FieldNumbers) { + fieldname := p.FieldName(field) + errFieldname := field.GoName if field.Oneof != nil && !field.Oneof.Desc.IsSynthetic() { - fieldname = field.Oneof.GoName + fieldname = p.OneofName(field.Oneof) } p.P(`case `, strconv.Itoa(int(field.Desc.Number())), `:`) wireType := generator.ProtoWireType(field.Desc.Kind()) if field.Desc.IsList() && wireType != protowire.BytesType { p.P(`if wireType == `, strconv.Itoa(int(wireType)), `{`) - p.fieldItem(field, fieldname, message, false) + p.fieldItem(field, fieldname, message) p.P(`} else if wireType == `, strconv.Itoa(int(protowire.BytesType)), `{`) p.P(`var packedLen int`) p.decodeVarint("packedLen", "int") @@ -768,7 +792,7 @@ func (p *unmarshal) field(proto3, oneof bool, field *protogen.Field, message *pr p.P(`}`) p.P(`for iNdEx < postIndex {`) - p.fieldItem(field, fieldname, message, false) + p.fieldItem(field, fieldname, message) p.P(`}`) p.P(`} else {`) p.P(`return `, p.Ident("fmt", "Errorf"), `("proto: wrong wireType = %d for field `, errFieldname, `", wireType)`) @@ -777,7 +801,7 @@ func (p *unmarshal) field(proto3, oneof bool, field *protogen.Field, message *pr p.P(`if wireType != `, strconv.Itoa(int(wireType)), `{`) p.P(`return `, p.Ident("fmt", "Errorf"), `("proto: wrong wireType = %d for field `, errFieldname, `", wireType)`) p.P(`}`) - p.fieldItem(field, fieldname, message, proto3) + p.fieldItem(field, fieldname, message) } if field.Desc.Cardinality() == protoreflect.Required { @@ -794,9 +818,9 @@ func (p *unmarshal) field(proto3, oneof bool, field *protogen.Field, message *pr } } -func (p *unmarshal) message(proto3 bool, message *protogen.Message) { +func (p *unmarshal) message(message *protogen.Message) { for _, nested := range message.Messages { - p.message(proto3, nested) + p.message(nested) } if message.Desc.IsMapEntry() { @@ -827,7 +851,7 @@ func (p *unmarshal) message(proto3 bool, message *protogen.Message) { p.P(`}`) p.P(`switch fieldNum {`) for _, field := range message.Fields { - p.field(proto3, false, field, message, required) + p.field(false, field, message, required) } p.P(`default:`) p.P(`iNdEx=preIndex`) diff --git a/generator/generator.go b/generator/generator.go index a575ed45..d41d2867 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -11,6 +11,8 @@ import ( "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/runtime/protoimpl" + "google.golang.org/protobuf/types/descriptorpb" + "google.golang.org/protobuf/types/gofeaturespb" "google.golang.org/protobuf/types/pluginpb" "github.com/planetscale/vtprotobuf/generator/pattern" @@ -71,10 +73,20 @@ type Generator struct { local map[protoreflect.FullName]bool } -const SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL) +const SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL | + pluginpb.CodeGeneratorResponse_FEATURE_SUPPORTS_EDITIONS) + +// Editions range mirrors protoc-gen-go. The equivalent constants live in +// google.golang.org/protobuf/internal/editionssupport, which is not importable. +const ( + SupportedEditionsMinimum = descriptorpb.Edition_EDITION_PROTO2 + SupportedEditionsMaximum = descriptorpb.Edition_EDITION_2024 +) func NewGenerator(plugin *protogen.Plugin, featureNames []string, cfg *Config) (*Generator, error) { plugin.SupportedFeatures = SupportedFeatures + plugin.SupportedEditionsMinimum = SupportedEditionsMinimum + plugin.SupportedEditionsMaximum = SupportedEditionsMaximum features, err := findFeatures(featureNames) if err != nil { @@ -107,11 +119,53 @@ func (gen *Generator) Generate() { importPath = file.GoImportPath } + if err := gen.validate(file); err != nil { + gen.plugin.Error(err) + continue + } + gf := gen.plugin.NewGeneratedFile(file.GeneratedFilenamePrefix+"_vtproto.pb.go", importPath) gen.generateFile(gf, file) } } +// validate rejects the layouts vtproto cannot generate correct code for. +func (gen *Generator) validate(file *protogen.File) error { + var walk func(messages []*protogen.Message) error + walk = func(messages []*protogen.Message) error { + for _, message := range messages { + if isOpaque(message) && gen.cfg.Wrap { + return fmt.Errorf("%s: the wrap option is incompatible with the opaque API, "+ + "whose struct fields are unexported", message.Desc.FullName()) + } + for _, field := range message.Fields { + if isLazy(field) { + return fmt.Errorf("%s: lazy fields are not supported", field.Desc.FullName()) + } + } + if err := walk(message.Messages); err != nil { + return err + } + } + return nil + } + return walk(file.Messages) +} + +// buildConstraint returns the //go:build constraint for a generated file, and +// the equivalent legacy "// +build" line, which is empty when the constraint +// cannot be expressed in that syntax. +func buildConstraint(userTag string, level gofeaturespb.GoFeatures_APILevel) (constraint, legacy string) { + if level != gofeaturespb.GoFeatures_API_HYBRID { + return userTag, userTag + } + if userTag == "" { + return "!protoopaque", "!protoopaque" + } + // "(a || b) && !c" has no legacy equivalent. + return "(" + userTag + ") && !protoopaque", "" +} + func (gen *Generator) generateFile(gf *protogen.GeneratedFile, file *protogen.File) { p := &GeneratedFile{ GeneratedFile: gf, @@ -119,10 +173,13 @@ func (gen *Generator) generateFile(gf *protogen.GeneratedFile, file *protogen.Fi LocalPackages: gen.local, } - if p.Config.BuildTag != "" { + switch constraint, legacy := buildConstraint(p.Config.BuildTag, file.APILevel); { + case legacy != "": // Support both forms of tags for maximum compatibility - p.P("//go:build ", p.Config.BuildTag) - p.P("// +build ", p.Config.BuildTag) + p.P("//go:build ", constraint) + p.P("// +build ", legacy) + case constraint != "": + p.P("//go:build ", constraint) } p.P("// Code generated by protoc-gen-go-vtproto. DO NOT EDIT.") if bi, ok := debug.ReadBuildInfo(); ok { @@ -133,7 +190,6 @@ func (gen *Generator) generateFile(gf *protogen.GeneratedFile, file *protogen.Fi p.P("package ", file.GoPackageName) p.P() - protoimplPackage := protogen.GoImportPath("google.golang.org/protobuf/runtime/protoimpl") p.P("const (") p.P("// Verify that this generated code is sufficiently up-to-date.") p.P("_ = ", protoimplPackage.Ident("EnforceVersion"), "(", protoimpl.GenVersion, " - ", protoimplPackage.Ident("MinVersion"), ")") diff --git a/generator/generator_test.go b/generator/generator_test.go new file mode 100644 index 00000000..16f76dd2 --- /dev/null +++ b/generator/generator_test.go @@ -0,0 +1,75 @@ +package generator + +import ( + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protodesc" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/descriptorpb" + "google.golang.org/protobuf/types/gofeaturespb" +) + +type lazyFieldDescriptor struct { + protoreflect.FieldDescriptor +} + +func (lazyFieldDescriptor) IsLazy() bool { return true } + +func TestValidateRejectsWrapWithOpaqueAPI(t *testing.T) { + msg := testMessageDescriptor(t) + gen := &Generator{cfg: &Config{Wrap: true}} + + err := gen.validate(&protogen.File{Messages: []*protogen.Message{{ + Desc: msg, + APILevel: gofeaturespb.GoFeatures_API_OPAQUE, + }}}) + + require.ErrorContains(t, err, "wrap option is incompatible with the opaque API") +} + +func TestValidateRejectsLazyFields(t *testing.T) { + msg := testMessageDescriptor(t) + field := msg.Fields().ByName("lazy_field") + gen := &Generator{cfg: &Config{}} + + err := gen.validate(&protogen.File{Messages: []*protogen.Message{{ + Desc: msg, + Fields: []*protogen.Field{{ + Desc: lazyFieldDescriptor{FieldDescriptor: field}, + }}, + }}}) + + require.ErrorContains(t, err, "lazy fields are not supported") +} + +func testMessageDescriptor(t *testing.T) protoreflect.MessageDescriptor { + t.Helper() + + fd, err := protodesc.NewFile(&descriptorpb.FileDescriptorProto{ + Name: proto.String("test.proto"), + Package: proto.String("testpb"), + Syntax: proto.String("proto2"), + MessageType: []*descriptorpb.DescriptorProto{ + {Name: proto.String("Inner")}, + { + Name: proto.String("TestMessage"), + Field: []*descriptorpb.FieldDescriptorProto{{ + Name: proto.String("lazy_field"), + Number: proto.Int32(1), + Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(), + Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(), + TypeName: proto.String(".testpb.Inner"), + Options: &descriptorpb.FieldOptions{ + Lazy: proto.Bool(true), + }, + }}, + }, + }, + }, nil) + require.NoError(t, err) + + return fd.Messages().ByName("TestMessage") +} diff --git a/generator/layout.go b/generator/layout.go new file mode 100644 index 00000000..466875c4 --- /dev/null +++ b/generator/layout.go @@ -0,0 +1,214 @@ +// Copyright (c) 2021 PlanetScale Inc. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package generator + +import ( + "strconv" + "unicode" + "unicode/utf8" + + "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/gofeaturespb" +) + +var protoimplPackage = protogen.GoImportPath("google.golang.org/protobuf/runtime/protoimpl") + +// The helpers here are the only place that knows how a message's Go struct is +// laid out. HYBRID counts as OPEN: the variant protoc-gen-go emits by default +// for a hybrid file has the open layout, and the file generated alongside it +// carries a !protoopaque build constraint. + +func isOpaque(message *protogen.Message) bool { + return message != nil && message.APILevel == gofeaturespb.GoFeatures_API_OPAQUE +} + +// isLazy reports whether the field is marked for lazy decoding. protoreflect +// does not expose this, so assert for it the way protoc-gen-go does. +func isLazy(field *protogen.Field) bool { + lazy, ok := field.Desc.(interface{ IsLazy() bool }) + return ok && lazy.IsLazy() +} + +// FieldName returns the name of the Go struct field backing field. Features +// build accesses as "m." + FieldName(field), which is what keeps the opaque +// name mangling confined to this file. +func (p *GeneratedFile) FieldName(field *protogen.Field) string { + if isOpaque(field.Parent) { + return "xxx_hidden_" + field.GoName + } + return field.GoName +} + +func (p *GeneratedFile) OneofName(oneof *protogen.Oneof) string { + if isOpaque(oneof.Parent) { + return "xxx_hidden_" + oneof.GoName + } + return oneof.GoName +} + +func (p *GeneratedFile) fieldStore(recv string, field *protogen.Field) string { + return recv + "." + p.FieldName(field) +} + +// FieldStorageIsPointer reports whether the Go struct field is a pointer. +// Pointers that are part of the type itself, as in messages and slices, do not +// count. +func (p *GeneratedFile) FieldStorageIsPointer(field *protogen.Field) bool { + if !isOpaque(field.Parent) { + // Mirrors FieldGoType's pointer computation without calling it: FieldGoType + // resolves QualifiedGoIdent for message/enum types as a side effect, which + // would register an unwanted import here even when the caller only wants + // the bool and never prints the resolved type. + switch { + case field.Desc.IsWeak(): + return false + case field.Desc.IsList(), field.Desc.IsMap(): + return false + case field.Desc.Kind() == protoreflect.BytesKind: + return false + case field.Desc.Kind() == protoreflect.MessageKind, field.Desc.Kind() == protoreflect.GroupKind: + return false + default: + return field.Desc.HasPresence() + } + } + switch { + case field.Desc.IsMap(): + return false + case field.Desc.IsList(): + return field.Message != nil + case field.Desc.Kind() == protoreflect.StringKind: + // Strings keep their pointer even though a presence bit also tracks them. + return field.Desc.HasPresence() + default: + return false + } +} + +// FieldSliceExpr returns the expression to read a repeated field as a plain +// slice, emitting a local first if the layout stores the slice behind a pointer. +func (p *GeneratedFile) FieldSliceExpr(recv string, field *protogen.Field) string { + store := p.fieldStore(recv, field) + if !field.Desc.IsList() || field.Message == nil || field.Desc.IsMap() || !isOpaque(field.Parent) { + return store + } + local := "vt" + recv + field.GoName + goType, _ := p.FieldGoType(field) + p.P(`var `, local, ` `, goType) + p.P(`if `, local, `p := `, store, `; `, local, `p != nil {`) + p.P(local, ` = *`, local, `p`) + p.P(`}`) + return local +} + +func (p *GeneratedFile) presenceWord(recv string, field *protogen.Field) (word, index string) { + idx := presenceIndex(field) + return "&(" + recv + ".XXX_presence[" + strconv.Itoa(idx/32) + "])", strconv.Itoa(idx) +} + +func (p *GeneratedFile) FieldPresent(recv string, field *protogen.Field) string { + if p.UsesPresenceBit(field) { + word, idx := p.presenceWord(recv, field) + return p.QualifiedGoIdent(protoimplPackage.Ident("X")) + ".Present(" + word + ", " + idx + ")" + } + return p.fieldStore(recv, field) + " != nil" +} + +func (p *GeneratedFile) FieldAbsent(recv string, field *protogen.Field) string { + if p.UsesPresenceBit(field) { + return "!" + p.FieldPresent(recv, field) + } + return p.fieldStore(recv, field) + " == nil" +} + +// FieldSetPresent emits the statement marking field as present. SetPresent +// rather than SetPresentNonAtomic: UnmarshalVT may run on a message another +// goroutine holds, and neighbouring fields share a presence word. +func (p *GeneratedFile) FieldSetPresent(recv string, field *protogen.Field) { + if !p.UsesPresenceBit(field) { + return + } + word, idx := p.presenceWord(recv, field) + p.P(protoimplPackage.Ident("X"), ".SetPresent(", word, ", ", idx, ", ", + strconv.Itoa(numPresenceFields(field.Parent)), ")") +} + +func (p *GeneratedFile) CopyPresence(dst, src string, message *protogen.Message) { + if !p.hasPresenceArray(message) { + return + } + p.P(dst, ".XXX_presence = ", src, ".XXX_presence") +} + +func (p *GeneratedFile) hasPresenceArray(message *protogen.Message) bool { + for _, field := range message.Fields { + if p.UsesPresenceBit(field) { + return true + } + } + return false +} + +func (p *GeneratedFile) OneofStore(recv string, oneof *protogen.Oneof) string { + return recv + "." + p.OneofName(oneof) +} + +// OneofWrapperIdent returns the wrapper struct type for a oneof member, which +// the opaque API unexports. +func (p *GeneratedFile) OneofWrapperIdent(field *protogen.Field) protogen.GoIdent { + id := field.GoIdent + if isOpaque(field.Parent) { + r, sz := utf8.DecodeRuneInString(id.GoName) + id.GoName = string(unicode.ToLower(r)) + id.GoName[sz:] + } + return id +} + +// UsesPresenceBit reports whether presence lives in the XXX_presence bitfield +// rather than in a nil pointer. Mirrors filedesc.UsePresenceForField, which is +// internal. +func (p *GeneratedFile) UsesPresenceBit(field *protogen.Field) bool { + if !isOpaque(field.Parent) { + return false + } + switch { + case field.Desc.IsList(), field.Desc.IsMap(): + return false + case field.Oneof != nil && !field.Oneof.Desc.IsSynthetic(): + return false + case field.Message != nil: + return false + } + return field.Desc.HasPresence() +} + +// presenceIndex returns the field's slot in the bitfield: its position among the +// emitted struct fields, where a whole oneof takes one slot accounted at its +// last member. Mirrors opaqueFieldPresenceIndex in protoc-gen-go. +func presenceIndex(field *protogen.Field) int { + idx := 0 + for _, f := range field.Parent.Fields { + if f == field { + break + } + if f.Oneof == nil || isLastOneofField(f) { + idx++ + } + } + return idx +} + +func numPresenceFields(message *protogen.Message) int { + if len(message.Fields) == 0 { + return 0 + } + return presenceIndex(message.Fields[len(message.Fields)-1]) + 1 +} + +func isLastOneofField(field *protogen.Field) bool { + fields := field.Oneof.Fields + return fields[len(fields)-1] == field +} diff --git a/testproto/editions/editions.pb.go b/testproto/editions/editions.pb.go new file mode 100644 index 00000000..8d2ace2c --- /dev/null +++ b/testproto/editions/editions.pb.go @@ -0,0 +1,237 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.10 +// protoc v6.32.1 +// source: editions/editions.proto + +package editions + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type EditionsMessage struct { + state protoimpl.MessageState `protogen:"opaque.v1"` + xxx_hidden_ExplicitInt32 int32 `protobuf:"varint,1,opt,name=explicit_int32,json=explicitInt32"` + xxx_hidden_ExplicitString *string `protobuf:"bytes,2,opt,name=explicit_string,json=explicitString"` + xxx_hidden_ImplicitInt32 int32 `protobuf:"varint,11,opt,name=implicit_int32,json=implicitInt32"` + xxx_hidden_ImplicitString string `protobuf:"bytes,12,opt,name=implicit_string,json=implicitString"` + xxx_hidden_RequiredInt32 int32 `protobuf:"varint,21,req,name=required_int32,json=requiredInt32"` + XXX_raceDetectHookData protoimpl.RaceDetectHookData + XXX_presence [1]uint32 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EditionsMessage) Reset() { + *x = EditionsMessage{} + mi := &file_editions_editions_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EditionsMessage) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EditionsMessage) ProtoMessage() {} + +func (x *EditionsMessage) ProtoReflect() protoreflect.Message { + mi := &file_editions_editions_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +func (x *EditionsMessage) GetExplicitInt32() int32 { + if x != nil { + return x.xxx_hidden_ExplicitInt32 + } + return 0 +} + +func (x *EditionsMessage) GetExplicitString() string { + if x != nil { + if x.xxx_hidden_ExplicitString != nil { + return *x.xxx_hidden_ExplicitString + } + return "" + } + return "" +} + +func (x *EditionsMessage) GetImplicitInt32() int32 { + if x != nil { + return x.xxx_hidden_ImplicitInt32 + } + return 0 +} + +func (x *EditionsMessage) GetImplicitString() string { + if x != nil { + return x.xxx_hidden_ImplicitString + } + return "" +} + +func (x *EditionsMessage) GetRequiredInt32() int32 { + if x != nil { + return x.xxx_hidden_RequiredInt32 + } + return 0 +} + +func (x *EditionsMessage) SetExplicitInt32(v int32) { + x.xxx_hidden_ExplicitInt32 = v + protoimpl.X.SetPresent(&(x.XXX_presence[0]), 0, 5) +} + +func (x *EditionsMessage) SetExplicitString(v string) { + x.xxx_hidden_ExplicitString = &v + protoimpl.X.SetPresent(&(x.XXX_presence[0]), 1, 5) +} + +func (x *EditionsMessage) SetImplicitInt32(v int32) { + x.xxx_hidden_ImplicitInt32 = v +} + +func (x *EditionsMessage) SetImplicitString(v string) { + x.xxx_hidden_ImplicitString = v +} + +func (x *EditionsMessage) SetRequiredInt32(v int32) { + x.xxx_hidden_RequiredInt32 = v + protoimpl.X.SetPresent(&(x.XXX_presence[0]), 4, 5) +} + +func (x *EditionsMessage) HasExplicitInt32() bool { + if x == nil { + return false + } + return protoimpl.X.Present(&(x.XXX_presence[0]), 0) +} + +func (x *EditionsMessage) HasExplicitString() bool { + if x == nil { + return false + } + return protoimpl.X.Present(&(x.XXX_presence[0]), 1) +} + +func (x *EditionsMessage) HasRequiredInt32() bool { + if x == nil { + return false + } + return protoimpl.X.Present(&(x.XXX_presence[0]), 4) +} + +func (x *EditionsMessage) ClearExplicitInt32() { + protoimpl.X.ClearPresent(&(x.XXX_presence[0]), 0) + x.xxx_hidden_ExplicitInt32 = 0 +} + +func (x *EditionsMessage) ClearExplicitString() { + protoimpl.X.ClearPresent(&(x.XXX_presence[0]), 1) + x.xxx_hidden_ExplicitString = nil +} + +func (x *EditionsMessage) ClearRequiredInt32() { + protoimpl.X.ClearPresent(&(x.XXX_presence[0]), 4) + x.xxx_hidden_RequiredInt32 = 0 +} + +type EditionsMessage_builder struct { + _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. + + // The default under editions is explicit presence. + ExplicitInt32 *int32 + ExplicitString *string + // What a mechanically migrated proto3 field looks like. + ImplicitInt32 int32 + ImplicitString string + RequiredInt32 *int32 +} + +func (b0 EditionsMessage_builder) Build() *EditionsMessage { + m0 := &EditionsMessage{} + b, x := &b0, m0 + _, _ = b, x + if b.ExplicitInt32 != nil { + protoimpl.X.SetPresentNonAtomic(&(x.XXX_presence[0]), 0, 5) + x.xxx_hidden_ExplicitInt32 = *b.ExplicitInt32 + } + if b.ExplicitString != nil { + protoimpl.X.SetPresentNonAtomic(&(x.XXX_presence[0]), 1, 5) + x.xxx_hidden_ExplicitString = b.ExplicitString + } + x.xxx_hidden_ImplicitInt32 = b.ImplicitInt32 + x.xxx_hidden_ImplicitString = b.ImplicitString + if b.RequiredInt32 != nil { + protoimpl.X.SetPresentNonAtomic(&(x.XXX_presence[0]), 4, 5) + x.xxx_hidden_RequiredInt32 = *b.RequiredInt32 + } + return m0 +} + +var File_editions_editions_proto protoreflect.FileDescriptor + +const file_editions_editions_proto_rawDesc = "" + + "\n" + + "\x17editions/editions.proto\"\xed\x01\n" + + "\x0fEditionsMessage\x12%\n" + + "\x0eexplicit_int32\x18\x01 \x01(\x05R\rexplicitInt32\x12'\n" + + "\x0fexplicit_string\x18\x02 \x01(\tR\x0eexplicitString\x12,\n" + + "\x0eimplicit_int32\x18\v \x01(\x05B\x05\xaa\x01\x02\b\x02R\rimplicitInt32\x12.\n" + + "\x0fimplicit_string\x18\f \x01(\tB\x05\xaa\x01\x02\b\x02R\x0eimplicitString\x12,\n" + + "\x0erequired_int32\x18\x15 \x01(\x05B\x05\xaa\x01\x02\b\x03R\rrequiredInt32B\x14Z\x12testproto/editionsb\beditionsp\xe9\a" + +var file_editions_editions_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_editions_editions_proto_goTypes = []any{ + (*EditionsMessage)(nil), // 0: EditionsMessage +} +var file_editions_editions_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_editions_editions_proto_init() } +func file_editions_editions_proto_init() { + if File_editions_editions_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_editions_editions_proto_rawDesc), len(file_editions_editions_proto_rawDesc)), + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_editions_editions_proto_goTypes, + DependencyIndexes: file_editions_editions_proto_depIdxs, + MessageInfos: file_editions_editions_proto_msgTypes, + }.Build() + File_editions_editions_proto = out.File + file_editions_editions_proto_goTypes = nil + file_editions_editions_proto_depIdxs = nil +} diff --git a/testproto/editions/editions.proto b/testproto/editions/editions.proto new file mode 100644 index 00000000..495a6087 --- /dev/null +++ b/testproto/editions/editions.proto @@ -0,0 +1,15 @@ +edition = "2024"; + +option go_package = "testproto/editions"; + +message EditionsMessage { + // The default under editions is explicit presence. + int32 explicit_int32 = 1; + string explicit_string = 2; + + // What a mechanically migrated proto3 field looks like. + int32 implicit_int32 = 11 [features.field_presence = IMPLICIT]; + string implicit_string = 12 [features.field_presence = IMPLICIT]; + + int32 required_int32 = 21 [features.field_presence = LEGACY_REQUIRED]; +} diff --git a/testproto/editions/editions2023.pb.go b/testproto/editions/editions2023.pb.go new file mode 100644 index 00000000..c6b12a85 --- /dev/null +++ b/testproto/editions/editions2023.pb.go @@ -0,0 +1,160 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.10 +// protoc v6.32.1 +// source: editions/editions2023.proto + +package editions + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// OpenMessage uses the open API, edition 2023's default; editions.proto covers +// the opaque default of edition 2024. +type OpenMessage struct { + state protoimpl.MessageState `protogen:"open.v1"` + ExplicitInt32 *int32 `protobuf:"varint,1,opt,name=explicit_int32,json=explicitInt32" json:"explicit_int32,omitempty"` + ExplicitString *string `protobuf:"bytes,2,opt,name=explicit_string,json=explicitString" json:"explicit_string,omitempty"` + ImplicitInt32 int32 `protobuf:"varint,11,opt,name=implicit_int32,json=implicitInt32" json:"implicit_int32,omitempty"` + ImplicitString string `protobuf:"bytes,12,opt,name=implicit_string,json=implicitString" json:"implicit_string,omitempty"` + RequiredInt32 *int32 `protobuf:"varint,21,req,name=required_int32,json=requiredInt32" json:"required_int32,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *OpenMessage) Reset() { + *x = OpenMessage{} + mi := &file_editions_editions2023_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *OpenMessage) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OpenMessage) ProtoMessage() {} + +func (x *OpenMessage) ProtoReflect() protoreflect.Message { + mi := &file_editions_editions2023_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OpenMessage.ProtoReflect.Descriptor instead. +func (*OpenMessage) Descriptor() ([]byte, []int) { + return file_editions_editions2023_proto_rawDescGZIP(), []int{0} +} + +func (x *OpenMessage) GetExplicitInt32() int32 { + if x != nil && x.ExplicitInt32 != nil { + return *x.ExplicitInt32 + } + return 0 +} + +func (x *OpenMessage) GetExplicitString() string { + if x != nil && x.ExplicitString != nil { + return *x.ExplicitString + } + return "" +} + +func (x *OpenMessage) GetImplicitInt32() int32 { + if x != nil { + return x.ImplicitInt32 + } + return 0 +} + +func (x *OpenMessage) GetImplicitString() string { + if x != nil { + return x.ImplicitString + } + return "" +} + +func (x *OpenMessage) GetRequiredInt32() int32 { + if x != nil && x.RequiredInt32 != nil { + return *x.RequiredInt32 + } + return 0 +} + +var File_editions_editions2023_proto protoreflect.FileDescriptor + +const file_editions_editions2023_proto_rawDesc = "" + + "\n" + + "\x1beditions/editions2023.proto\"\xe9\x01\n" + + "\vOpenMessage\x12%\n" + + "\x0eexplicit_int32\x18\x01 \x01(\x05R\rexplicitInt32\x12'\n" + + "\x0fexplicit_string\x18\x02 \x01(\tR\x0eexplicitString\x12,\n" + + "\x0eimplicit_int32\x18\v \x01(\x05B\x05\xaa\x01\x02\b\x02R\rimplicitInt32\x12.\n" + + "\x0fimplicit_string\x18\f \x01(\tB\x05\xaa\x01\x02\b\x02R\x0eimplicitString\x12,\n" + + "\x0erequired_int32\x18\x15 \x01(\x05B\x05\xaa\x01\x02\b\x03R\rrequiredInt32B\x14Z\x12testproto/editionsb\beditionsp\xe8\a" + +var ( + file_editions_editions2023_proto_rawDescOnce sync.Once + file_editions_editions2023_proto_rawDescData []byte +) + +func file_editions_editions2023_proto_rawDescGZIP() []byte { + file_editions_editions2023_proto_rawDescOnce.Do(func() { + file_editions_editions2023_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_editions_editions2023_proto_rawDesc), len(file_editions_editions2023_proto_rawDesc))) + }) + return file_editions_editions2023_proto_rawDescData +} + +var file_editions_editions2023_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_editions_editions2023_proto_goTypes = []any{ + (*OpenMessage)(nil), // 0: OpenMessage +} +var file_editions_editions2023_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_editions_editions2023_proto_init() } +func file_editions_editions2023_proto_init() { + if File_editions_editions2023_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_editions_editions2023_proto_rawDesc), len(file_editions_editions2023_proto_rawDesc)), + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_editions_editions2023_proto_goTypes, + DependencyIndexes: file_editions_editions2023_proto_depIdxs, + MessageInfos: file_editions_editions2023_proto_msgTypes, + }.Build() + File_editions_editions2023_proto = out.File + file_editions_editions2023_proto_goTypes = nil + file_editions_editions2023_proto_depIdxs = nil +} diff --git a/testproto/editions/editions2023.proto b/testproto/editions/editions2023.proto new file mode 100644 index 00000000..2d575bbb --- /dev/null +++ b/testproto/editions/editions2023.proto @@ -0,0 +1,15 @@ +edition = "2023"; + +option go_package = "testproto/editions"; + +// OpenMessage uses the open API, edition 2023's default; editions.proto covers +// the opaque default of edition 2024. +message OpenMessage { + int32 explicit_int32 = 1; + string explicit_string = 2; + + int32 implicit_int32 = 11 [features.field_presence = IMPLICIT]; + string implicit_string = 12 [features.field_presence = IMPLICIT]; + + int32 required_int32 = 21 [features.field_presence = LEGACY_REQUIRED]; +} diff --git a/testproto/editions/editions2023_vtproto.pb.go b/testproto/editions/editions2023_vtproto.pb.go new file mode 100644 index 00000000..c4894cc1 --- /dev/null +++ b/testproto/editions/editions2023_vtproto.pb.go @@ -0,0 +1,610 @@ +// Code generated by protoc-gen-go-vtproto. DO NOT EDIT. +// protoc-gen-go-vtproto version: (devel) +// source: editions/editions2023.proto + +package editions + +import ( + fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" + proto "google.golang.org/protobuf/proto" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +func (m *OpenMessage) CloneVT() *OpenMessage { + if m == nil { + return (*OpenMessage)(nil) + } + r := new(OpenMessage) + r.ImplicitInt32 = m.ImplicitInt32 + r.ImplicitString = m.ImplicitString + if rhs := m.ExplicitInt32; rhs != nil { + tmpVal := *rhs + r.ExplicitInt32 = &tmpVal + } + if rhs := m.ExplicitString; rhs != nil { + tmpVal := *rhs + r.ExplicitString = &tmpVal + } + if rhs := m.RequiredInt32; rhs != nil { + tmpVal := *rhs + r.RequiredInt32 = &tmpVal + } + if len(m.unknownFields) > 0 { + r.unknownFields = make([]byte, len(m.unknownFields)) + copy(r.unknownFields, m.unknownFields) + } + return r +} + +func (m *OpenMessage) CloneMessageVT() proto.Message { + return m.CloneVT() +} + +func (this *OpenMessage) EqualVT(that *OpenMessage) bool { + if this == that { + return true + } else if this == nil || that == nil { + return false + } + if p, q := this.ExplicitInt32, that.ExplicitInt32; (p == nil && q != nil) || (p != nil && (q == nil || *p != *q)) { + return false + } + if p, q := this.ExplicitString, that.ExplicitString; (p == nil && q != nil) || (p != nil && (q == nil || *p != *q)) { + return false + } + if this.ImplicitInt32 != that.ImplicitInt32 { + return false + } + if this.ImplicitString != that.ImplicitString { + return false + } + if p, q := this.RequiredInt32, that.RequiredInt32; (p == nil && q != nil) || (p != nil && (q == nil || *p != *q)) { + return false + } + return string(this.unknownFields) == string(that.unknownFields) +} + +func (this *OpenMessage) EqualMessageVT(thatMsg proto.Message) bool { + that, ok := thatMsg.(*OpenMessage) + if !ok { + return false + } + return this.EqualVT(that) +} +func (m *OpenMessage) MarshalVT() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVT(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *OpenMessage) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *OpenMessage) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if m.RequiredInt32 == nil { + return 0, fmt.Errorf("proto: required field required_int32 not set") + } else { + i = protohelpers.EncodeVarint(dAtA, i, uint64(*m.RequiredInt32)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa8 + } + if len(m.ImplicitString) > 0 { + i -= len(m.ImplicitString) + copy(dAtA[i:], m.ImplicitString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.ImplicitString))) + i-- + dAtA[i] = 0x62 + } + if m.ImplicitInt32 != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.ImplicitInt32)) + i-- + dAtA[i] = 0x58 + } + if m.ExplicitString != nil { + i -= len(*m.ExplicitString) + copy(dAtA[i:], *m.ExplicitString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(*m.ExplicitString))) + i-- + dAtA[i] = 0x12 + } + if m.ExplicitInt32 != nil { + i = protohelpers.EncodeVarint(dAtA, i, uint64(*m.ExplicitInt32)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *OpenMessage) MarshalVTStrict() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVTStrict(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *OpenMessage) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *OpenMessage) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if m.RequiredInt32 == nil { + return 0, fmt.Errorf("proto: required field required_int32 not set") + } else { + i = protohelpers.EncodeVarint(dAtA, i, uint64(*m.RequiredInt32)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa8 + } + if len(m.ImplicitString) > 0 { + i -= len(m.ImplicitString) + copy(dAtA[i:], m.ImplicitString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.ImplicitString))) + i-- + dAtA[i] = 0x62 + } + if m.ImplicitInt32 != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.ImplicitInt32)) + i-- + dAtA[i] = 0x58 + } + if m.ExplicitString != nil { + i -= len(*m.ExplicitString) + copy(dAtA[i:], *m.ExplicitString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(*m.ExplicitString))) + i-- + dAtA[i] = 0x12 + } + if m.ExplicitInt32 != nil { + i = protohelpers.EncodeVarint(dAtA, i, uint64(*m.ExplicitInt32)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *OpenMessage) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ExplicitInt32 != nil { + n += 1 + protohelpers.SizeOfVarint(uint64(*m.ExplicitInt32)) + } + if m.ExplicitString != nil { + l = len(*m.ExplicitString) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) + } + if m.ImplicitInt32 != 0 { + n += 1 + protohelpers.SizeOfVarint(uint64(m.ImplicitInt32)) + } + l = len(m.ImplicitString) + if l > 0 { + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) + } + if m.RequiredInt32 != nil { + n += 2 + protohelpers.SizeOfVarint(uint64(*m.RequiredInt32)) + } + n += len(m.unknownFields) + return n +} + +func (m *OpenMessage) UnmarshalVT(dAtA []byte) error { + var hasFields [1]uint64 + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: OpenMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OpenMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExplicitInt32", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ExplicitInt32 = &v + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExplicitString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + s := string(dAtA[iNdEx:postIndex]) + m.ExplicitString = &s + iNdEx = postIndex + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitInt32", wireType) + } + m.ImplicitInt32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ImplicitInt32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ImplicitString = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 21: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RequiredInt32", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.RequiredInt32 = &v + hasFields[0] |= uint64(0x00000001) + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + if hasFields[0]&uint64(0x00000001) == 0 { + return fmt.Errorf("proto: required field required_int32 not set") + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OpenMessage) UnmarshalVTUnsafe(dAtA []byte) error { + var hasFields [1]uint64 + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: OpenMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OpenMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExplicitInt32", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ExplicitInt32 = &v + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExplicitString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var stringValue string + if intStringLen > 0 { + stringValue = unsafe.String(&dAtA[iNdEx], intStringLen) + } + s := stringValue + m.ExplicitString = &s + iNdEx = postIndex + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitInt32", wireType) + } + m.ImplicitInt32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ImplicitInt32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var stringValue string + if intStringLen > 0 { + stringValue = unsafe.String(&dAtA[iNdEx], intStringLen) + } + m.ImplicitString = stringValue + iNdEx = postIndex + case 21: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RequiredInt32", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.RequiredInt32 = &v + hasFields[0] |= uint64(0x00000001) + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + if hasFields[0]&uint64(0x00000001) == 0 { + return fmt.Errorf("proto: required field required_int32 not set") + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} diff --git a/testproto/editions/editions_test.go b/testproto/editions/editions_test.go new file mode 100644 index 00000000..959b2b8c --- /dev/null +++ b/testproto/editions/editions_test.go @@ -0,0 +1,78 @@ +package editions + +import ( + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" +) + +func TestOpaqueRoundTrip(t *testing.T) { + for _, msg := range []*EditionsMessage{ + EditionsMessage_builder{RequiredInt32: proto.Int32(0)}.Build(), + EditionsMessage_builder{ + ExplicitInt32: proto.Int32(1), + ExplicitString: proto.String("explicit"), + ImplicitInt32: 2, + ImplicitString: "implicit", + RequiredInt32: proto.Int32(3), + }.Build(), + // Explicit presence of a zero value must survive the round trip. + EditionsMessage_builder{ + ExplicitInt32: proto.Int32(0), + ExplicitString: proto.String(""), + RequiredInt32: proto.Int32(0), + }.Build(), + } { + vt, err := msg.MarshalVT() + require.NoError(t, err) + require.Equal(t, msg.SizeVT(), len(vt)) + + var got EditionsMessage + require.NoError(t, got.UnmarshalVT(vt)) + require.True(t, proto.Equal(msg, &got)) + require.True(t, msg.EqualVT(msg.CloneVT())) + } +} + +func TestOpenRoundTrip(t *testing.T) { + for _, msg := range []*OpenMessage{ + {RequiredInt32: proto.Int32(0)}, + { + ExplicitInt32: proto.Int32(1), + ExplicitString: proto.String("explicit"), + ImplicitInt32: 2, + ImplicitString: "implicit", + RequiredInt32: proto.Int32(3), + }, + { + ExplicitInt32: proto.Int32(0), + ExplicitString: proto.String(""), + RequiredInt32: proto.Int32(0), + }, + } { + vt, err := msg.MarshalVT() + require.NoError(t, err) + require.Equal(t, msg.SizeVT(), len(vt)) + + var got OpenMessage + require.NoError(t, got.UnmarshalVT(vt)) + require.True(t, proto.Equal(msg, &got)) + require.True(t, msg.EqualVT(msg.CloneVT())) + } +} + +func TestImplicitPresence(t *testing.T) { + require.True(t, (&OpenMessage{ImplicitInt32: 0, RequiredInt32: proto.Int32(0)}). + EqualVT(&OpenMessage{RequiredInt32: proto.Int32(0)})) + require.False(t, (&OpenMessage{ExplicitInt32: proto.Int32(0), RequiredInt32: proto.Int32(0)}). + EqualVT(&OpenMessage{RequiredInt32: proto.Int32(0)})) +} + +func TestRequiredFieldUnset(t *testing.T) { + _, err := (&OpenMessage{}).MarshalVT() + require.ErrorContains(t, err, "required field required_int32 not set") + + _, err = (&EditionsMessage{}).MarshalVT() + require.ErrorContains(t, err, "required field required_int32 not set") +} diff --git a/testproto/editions/editions_vtproto.pb.go b/testproto/editions/editions_vtproto.pb.go new file mode 100644 index 00000000..043aae90 --- /dev/null +++ b/testproto/editions/editions_vtproto.pb.go @@ -0,0 +1,617 @@ +// Code generated by protoc-gen-go-vtproto. DO NOT EDIT. +// protoc-gen-go-vtproto version: (devel) +// source: editions/editions.proto + +package editions + +import ( + fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" + proto "google.golang.org/protobuf/proto" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +func (m *EditionsMessage) CloneVT() *EditionsMessage { + if m == nil { + return (*EditionsMessage)(nil) + } + r := new(EditionsMessage) + r.xxx_hidden_ExplicitInt32 = m.xxx_hidden_ExplicitInt32 + r.xxx_hidden_ImplicitInt32 = m.xxx_hidden_ImplicitInt32 + r.xxx_hidden_ImplicitString = m.xxx_hidden_ImplicitString + r.xxx_hidden_RequiredInt32 = m.xxx_hidden_RequiredInt32 + if rhs := m.xxx_hidden_ExplicitString; rhs != nil { + tmpVal := *rhs + r.xxx_hidden_ExplicitString = &tmpVal + } + r.XXX_presence = m.XXX_presence + if len(m.unknownFields) > 0 { + r.unknownFields = make([]byte, len(m.unknownFields)) + copy(r.unknownFields, m.unknownFields) + } + return r +} + +func (m *EditionsMessage) CloneMessageVT() proto.Message { + return m.CloneVT() +} + +func (this *EditionsMessage) EqualVT(that *EditionsMessage) bool { + if this == that { + return true + } else if this == nil || that == nil { + return false + } + if protoimpl.X.Present(&(this.XXX_presence[0]), 0) != protoimpl.X.Present(&(that.XXX_presence[0]), 0) { + return false + } + if this.xxx_hidden_ExplicitInt32 != that.xxx_hidden_ExplicitInt32 { + return false + } + if p, q := this.xxx_hidden_ExplicitString, that.xxx_hidden_ExplicitString; (p == nil && q != nil) || (p != nil && (q == nil || *p != *q)) { + return false + } + if this.xxx_hidden_ImplicitInt32 != that.xxx_hidden_ImplicitInt32 { + return false + } + if this.xxx_hidden_ImplicitString != that.xxx_hidden_ImplicitString { + return false + } + if protoimpl.X.Present(&(this.XXX_presence[0]), 4) != protoimpl.X.Present(&(that.XXX_presence[0]), 4) { + return false + } + if this.xxx_hidden_RequiredInt32 != that.xxx_hidden_RequiredInt32 { + return false + } + return string(this.unknownFields) == string(that.unknownFields) +} + +func (this *EditionsMessage) EqualMessageVT(thatMsg proto.Message) bool { + that, ok := thatMsg.(*EditionsMessage) + if !ok { + return false + } + return this.EqualVT(that) +} +func (m *EditionsMessage) MarshalVT() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVT(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EditionsMessage) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *EditionsMessage) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if !protoimpl.X.Present(&(m.XXX_presence[0]), 4) { + return 0, fmt.Errorf("proto: required field required_int32 not set") + } else { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_RequiredInt32)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa8 + } + if len(m.xxx_hidden_ImplicitString) > 0 { + i -= len(m.xxx_hidden_ImplicitString) + copy(dAtA[i:], m.xxx_hidden_ImplicitString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.xxx_hidden_ImplicitString))) + i-- + dAtA[i] = 0x62 + } + if m.xxx_hidden_ImplicitInt32 != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_ImplicitInt32)) + i-- + dAtA[i] = 0x58 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 1) { + i -= len(*m.xxx_hidden_ExplicitString) + copy(dAtA[i:], *m.xxx_hidden_ExplicitString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(*m.xxx_hidden_ExplicitString))) + i-- + dAtA[i] = 0x12 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 0) { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_ExplicitInt32)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *EditionsMessage) MarshalVTStrict() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVTStrict(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EditionsMessage) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *EditionsMessage) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if !protoimpl.X.Present(&(m.XXX_presence[0]), 4) { + return 0, fmt.Errorf("proto: required field required_int32 not set") + } else { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_RequiredInt32)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa8 + } + if len(m.xxx_hidden_ImplicitString) > 0 { + i -= len(m.xxx_hidden_ImplicitString) + copy(dAtA[i:], m.xxx_hidden_ImplicitString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.xxx_hidden_ImplicitString))) + i-- + dAtA[i] = 0x62 + } + if m.xxx_hidden_ImplicitInt32 != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_ImplicitInt32)) + i-- + dAtA[i] = 0x58 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 1) { + i -= len(*m.xxx_hidden_ExplicitString) + copy(dAtA[i:], *m.xxx_hidden_ExplicitString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(*m.xxx_hidden_ExplicitString))) + i-- + dAtA[i] = 0x12 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 0) { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_ExplicitInt32)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *EditionsMessage) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if protoimpl.X.Present(&(m.XXX_presence[0]), 0) { + n += 1 + protohelpers.SizeOfVarint(uint64(m.xxx_hidden_ExplicitInt32)) + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 1) { + l = len(*m.xxx_hidden_ExplicitString) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) + } + if m.xxx_hidden_ImplicitInt32 != 0 { + n += 1 + protohelpers.SizeOfVarint(uint64(m.xxx_hidden_ImplicitInt32)) + } + l = len(m.xxx_hidden_ImplicitString) + if l > 0 { + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 4) { + n += 2 + protohelpers.SizeOfVarint(uint64(m.xxx_hidden_RequiredInt32)) + } + n += len(m.unknownFields) + return n +} + +func (m *EditionsMessage) UnmarshalVT(dAtA []byte) error { + var hasFields [1]uint64 + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EditionsMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EditionsMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExplicitInt32", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_ExplicitInt32 = v + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 0, 5) + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExplicitString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + s := string(dAtA[iNdEx:postIndex]) + m.xxx_hidden_ExplicitString = &s + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 1, 5) + iNdEx = postIndex + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitInt32", wireType) + } + m.xxx_hidden_ImplicitInt32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.xxx_hidden_ImplicitInt32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.xxx_hidden_ImplicitString = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 21: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RequiredInt32", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_RequiredInt32 = v + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 4, 5) + hasFields[0] |= uint64(0x00000001) + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + if hasFields[0]&uint64(0x00000001) == 0 { + return fmt.Errorf("proto: required field required_int32 not set") + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EditionsMessage) UnmarshalVTUnsafe(dAtA []byte) error { + var hasFields [1]uint64 + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EditionsMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EditionsMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExplicitInt32", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_ExplicitInt32 = v + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 0, 5) + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExplicitString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var stringValue string + if intStringLen > 0 { + stringValue = unsafe.String(&dAtA[iNdEx], intStringLen) + } + s := stringValue + m.xxx_hidden_ExplicitString = &s + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 1, 5) + iNdEx = postIndex + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitInt32", wireType) + } + m.xxx_hidden_ImplicitInt32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.xxx_hidden_ImplicitInt32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var stringValue string + if intStringLen > 0 { + stringValue = unsafe.String(&dAtA[iNdEx], intStringLen) + } + m.xxx_hidden_ImplicitString = stringValue + iNdEx = postIndex + case 21: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RequiredInt32", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_RequiredInt32 = v + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 4, 5) + hasFields[0] |= uint64(0x00000001) + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + if hasFields[0]&uint64(0x00000001) == 0 { + return fmt.Errorf("proto: required field required_int32 not set") + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} diff --git a/testproto/hybrid/hybrid.pb.go b/testproto/hybrid/hybrid.pb.go new file mode 100644 index 00000000..c9a41bd3 --- /dev/null +++ b/testproto/hybrid/hybrid.pb.go @@ -0,0 +1,168 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.10 +// protoc v3.21.12 +// source: hybrid/hybrid.proto + +//go:build !protoopaque + +package hybrid + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type HybridMessage struct { + state protoimpl.MessageState `protogen:"hybrid.v1"` + ImplicitInt32 int32 `protobuf:"varint,1,opt,name=implicit_int32,json=implicitInt32,proto3" json:"implicit_int32,omitempty"` + OptionalString *string `protobuf:"bytes,2,opt,name=optional_string,json=optionalString,proto3,oneof" json:"optional_string,omitempty"` + Children []*HybridMessage `protobuf:"bytes,3,rep,name=children,proto3" json:"children,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *HybridMessage) Reset() { + *x = HybridMessage{} + mi := &file_hybrid_hybrid_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *HybridMessage) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HybridMessage) ProtoMessage() {} + +func (x *HybridMessage) ProtoReflect() protoreflect.Message { + mi := &file_hybrid_hybrid_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +func (x *HybridMessage) GetImplicitInt32() int32 { + if x != nil { + return x.ImplicitInt32 + } + return 0 +} + +func (x *HybridMessage) GetOptionalString() string { + if x != nil && x.OptionalString != nil { + return *x.OptionalString + } + return "" +} + +func (x *HybridMessage) GetChildren() []*HybridMessage { + if x != nil { + return x.Children + } + return nil +} + +func (x *HybridMessage) SetImplicitInt32(v int32) { + x.ImplicitInt32 = v +} + +func (x *HybridMessage) SetOptionalString(v string) { + x.OptionalString = &v +} + +func (x *HybridMessage) SetChildren(v []*HybridMessage) { + x.Children = v +} + +func (x *HybridMessage) HasOptionalString() bool { + if x == nil { + return false + } + return x.OptionalString != nil +} + +func (x *HybridMessage) ClearOptionalString() { + x.OptionalString = nil +} + +type HybridMessage_builder struct { + _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. + + ImplicitInt32 int32 + OptionalString *string + Children []*HybridMessage +} + +func (b0 HybridMessage_builder) Build() *HybridMessage { + m0 := &HybridMessage{} + b, x := &b0, m0 + _, _ = b, x + x.ImplicitInt32 = b.ImplicitInt32 + x.OptionalString = b.OptionalString + x.Children = b.Children + return m0 +} + +var File_hybrid_hybrid_proto protoreflect.FileDescriptor + +const file_hybrid_hybrid_proto_rawDesc = "" + + "\n" + + "\x13hybrid/hybrid.proto\"\xa4\x01\n" + + "\rHybridMessage\x12%\n" + + "\x0eimplicit_int32\x18\x01 \x01(\x05R\rimplicitInt32\x12,\n" + + "\x0foptional_string\x18\x02 \x01(\tH\x00R\x0eoptionalString\x88\x01\x01\x12*\n" + + "\bchildren\x18\x03 \x03(\v2\x0e.HybridMessageR\bchildrenB\x12\n" + + "\x10_optional_stringB\x12Z\x10testproto/hybridb\x06proto3" + +var file_hybrid_hybrid_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_hybrid_hybrid_proto_goTypes = []any{ + (*HybridMessage)(nil), // 0: HybridMessage +} +var file_hybrid_hybrid_proto_depIdxs = []int32{ + 0, // 0: HybridMessage.children:type_name -> HybridMessage + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_hybrid_hybrid_proto_init() } +func file_hybrid_hybrid_proto_init() { + if File_hybrid_hybrid_proto != nil { + return + } + file_hybrid_hybrid_proto_msgTypes[0].OneofWrappers = []any{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_hybrid_hybrid_proto_rawDesc), len(file_hybrid_hybrid_proto_rawDesc)), + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_hybrid_hybrid_proto_goTypes, + DependencyIndexes: file_hybrid_hybrid_proto_depIdxs, + MessageInfos: file_hybrid_hybrid_proto_msgTypes, + }.Build() + File_hybrid_hybrid_proto = out.File + file_hybrid_hybrid_proto_goTypes = nil + file_hybrid_hybrid_proto_depIdxs = nil +} diff --git a/testproto/hybrid/hybrid.proto b/testproto/hybrid/hybrid.proto new file mode 100644 index 00000000..3d72f7e1 --- /dev/null +++ b/testproto/hybrid/hybrid.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +option go_package = "testproto/hybrid"; + +message HybridMessage { + int32 implicit_int32 = 1; + optional string optional_string = 2; + repeated HybridMessage children = 3; +} diff --git a/testproto/hybrid/hybrid_protoopaque.pb.go b/testproto/hybrid/hybrid_protoopaque.pb.go new file mode 100644 index 00000000..2e022cea --- /dev/null +++ b/testproto/hybrid/hybrid_protoopaque.pb.go @@ -0,0 +1,180 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.10 +// protoc v3.21.12 +// source: hybrid/hybrid.proto + +//go:build protoopaque + +package hybrid + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type HybridMessage struct { + state protoimpl.MessageState `protogen:"opaque.v1"` + xxx_hidden_ImplicitInt32 int32 `protobuf:"varint,1,opt,name=implicit_int32,json=implicitInt32,proto3"` + xxx_hidden_OptionalString *string `protobuf:"bytes,2,opt,name=optional_string,json=optionalString,proto3,oneof"` + xxx_hidden_Children *[]*HybridMessage `protobuf:"bytes,3,rep,name=children,proto3"` + XXX_raceDetectHookData protoimpl.RaceDetectHookData + XXX_presence [1]uint32 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *HybridMessage) Reset() { + *x = HybridMessage{} + mi := &file_hybrid_hybrid_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *HybridMessage) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HybridMessage) ProtoMessage() {} + +func (x *HybridMessage) ProtoReflect() protoreflect.Message { + mi := &file_hybrid_hybrid_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +func (x *HybridMessage) GetImplicitInt32() int32 { + if x != nil { + return x.xxx_hidden_ImplicitInt32 + } + return 0 +} + +func (x *HybridMessage) GetOptionalString() string { + if x != nil { + if x.xxx_hidden_OptionalString != nil { + return *x.xxx_hidden_OptionalString + } + return "" + } + return "" +} + +func (x *HybridMessage) GetChildren() []*HybridMessage { + if x != nil { + if x.xxx_hidden_Children != nil { + return *x.xxx_hidden_Children + } + } + return nil +} + +func (x *HybridMessage) SetImplicitInt32(v int32) { + x.xxx_hidden_ImplicitInt32 = v +} + +func (x *HybridMessage) SetOptionalString(v string) { + x.xxx_hidden_OptionalString = &v + protoimpl.X.SetPresent(&(x.XXX_presence[0]), 1, 3) +} + +func (x *HybridMessage) SetChildren(v []*HybridMessage) { + x.xxx_hidden_Children = &v +} + +func (x *HybridMessage) HasOptionalString() bool { + if x == nil { + return false + } + return protoimpl.X.Present(&(x.XXX_presence[0]), 1) +} + +func (x *HybridMessage) ClearOptionalString() { + protoimpl.X.ClearPresent(&(x.XXX_presence[0]), 1) + x.xxx_hidden_OptionalString = nil +} + +type HybridMessage_builder struct { + _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. + + ImplicitInt32 int32 + OptionalString *string + Children []*HybridMessage +} + +func (b0 HybridMessage_builder) Build() *HybridMessage { + m0 := &HybridMessage{} + b, x := &b0, m0 + _, _ = b, x + x.xxx_hidden_ImplicitInt32 = b.ImplicitInt32 + if b.OptionalString != nil { + protoimpl.X.SetPresentNonAtomic(&(x.XXX_presence[0]), 1, 3) + x.xxx_hidden_OptionalString = b.OptionalString + } + x.xxx_hidden_Children = &b.Children + return m0 +} + +var File_hybrid_hybrid_proto protoreflect.FileDescriptor + +const file_hybrid_hybrid_proto_rawDesc = "" + + "\n" + + "\x13hybrid/hybrid.proto\"\xa4\x01\n" + + "\rHybridMessage\x12%\n" + + "\x0eimplicit_int32\x18\x01 \x01(\x05R\rimplicitInt32\x12,\n" + + "\x0foptional_string\x18\x02 \x01(\tH\x00R\x0eoptionalString\x88\x01\x01\x12*\n" + + "\bchildren\x18\x03 \x03(\v2\x0e.HybridMessageR\bchildrenB\x12\n" + + "\x10_optional_stringB\x12Z\x10testproto/hybridb\x06proto3" + +var file_hybrid_hybrid_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_hybrid_hybrid_proto_goTypes = []any{ + (*HybridMessage)(nil), // 0: HybridMessage +} +var file_hybrid_hybrid_proto_depIdxs = []int32{ + 0, // 0: HybridMessage.children:type_name -> HybridMessage + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_hybrid_hybrid_proto_init() } +func file_hybrid_hybrid_proto_init() { + if File_hybrid_hybrid_proto != nil { + return + } + file_hybrid_hybrid_proto_msgTypes[0].OneofWrappers = []any{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_hybrid_hybrid_proto_rawDesc), len(file_hybrid_hybrid_proto_rawDesc)), + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_hybrid_hybrid_proto_goTypes, + DependencyIndexes: file_hybrid_hybrid_proto_depIdxs, + MessageInfos: file_hybrid_hybrid_proto_msgTypes, + }.Build() + File_hybrid_hybrid_proto = out.File + file_hybrid_hybrid_proto_goTypes = nil + file_hybrid_hybrid_proto_depIdxs = nil +} diff --git a/testproto/hybrid/hybrid_test.go b/testproto/hybrid/hybrid_test.go new file mode 100644 index 00000000..bcb16f1e --- /dev/null +++ b/testproto/hybrid/hybrid_test.go @@ -0,0 +1,27 @@ +//go:build !protoopaque + +package hybrid + +import ( + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" +) + +func TestRoundTrip(t *testing.T) { + msg := &HybridMessage{ + ImplicitInt32: 1, + OptionalString: proto.String("s"), + Children: []*HybridMessage{{ImplicitInt32: 2}}, + } + + vt, err := msg.MarshalVT() + require.NoError(t, err) + require.Equal(t, msg.SizeVT(), len(vt)) + + var got HybridMessage + require.NoError(t, got.UnmarshalVT(vt)) + require.True(t, proto.Equal(msg, &got)) + require.True(t, msg.EqualVT(msg.CloneVT())) +} diff --git a/testproto/hybrid/hybrid_vtproto.pb.go b/testproto/hybrid/hybrid_vtproto.pb.go new file mode 100644 index 00000000..1b8d1ded --- /dev/null +++ b/testproto/hybrid/hybrid_vtproto.pb.go @@ -0,0 +1,507 @@ +//go:build !protoopaque +// +build !protoopaque + +// Code generated by protoc-gen-go-vtproto. DO NOT EDIT. +// protoc-gen-go-vtproto version: (devel) +// source: hybrid/hybrid.proto + +package hybrid + +import ( + fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" + proto "google.golang.org/protobuf/proto" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +func (m *HybridMessage) CloneVT() *HybridMessage { + if m == nil { + return (*HybridMessage)(nil) + } + r := new(HybridMessage) + r.ImplicitInt32 = m.ImplicitInt32 + if rhs := m.OptionalString; rhs != nil { + tmpVal := *rhs + r.OptionalString = &tmpVal + } + if rhs := m.Children; rhs != nil { + tmpContainer := make([]*HybridMessage, len(rhs)) + for k, v := range rhs { + tmpContainer[k] = v.CloneVT() + } + r.Children = tmpContainer + } + if len(m.unknownFields) > 0 { + r.unknownFields = make([]byte, len(m.unknownFields)) + copy(r.unknownFields, m.unknownFields) + } + return r +} + +func (m *HybridMessage) CloneMessageVT() proto.Message { + return m.CloneVT() +} + +func (this *HybridMessage) EqualVT(that *HybridMessage) bool { + if this == that { + return true + } else if this == nil || that == nil { + return false + } + if this.ImplicitInt32 != that.ImplicitInt32 { + return false + } + if p, q := this.OptionalString, that.OptionalString; (p == nil && q != nil) || (p != nil && (q == nil || *p != *q)) { + return false + } + if len(this.Children) != len(that.Children) { + return false + } + for i, vx := range this.Children { + vy := that.Children[i] + if p, q := vx, vy; p != q { + if p == nil { + p = &HybridMessage{} + } + if q == nil { + q = &HybridMessage{} + } + if !p.EqualVT(q) { + return false + } + } + } + return string(this.unknownFields) == string(that.unknownFields) +} + +func (this *HybridMessage) EqualMessageVT(thatMsg proto.Message) bool { + that, ok := thatMsg.(*HybridMessage) + if !ok { + return false + } + return this.EqualVT(that) +} +func (m *HybridMessage) MarshalVT() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVT(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *HybridMessage) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *HybridMessage) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if len(m.Children) > 0 { + for iNdEx := len(m.Children) - 1; iNdEx >= 0; iNdEx-- { + size, err := m.Children[iNdEx].MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x1a + } + } + if m.OptionalString != nil { + i -= len(*m.OptionalString) + copy(dAtA[i:], *m.OptionalString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(*m.OptionalString))) + i-- + dAtA[i] = 0x12 + } + if m.ImplicitInt32 != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.ImplicitInt32)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *HybridMessage) MarshalVTStrict() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVTStrict(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *HybridMessage) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *HybridMessage) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if len(m.Children) > 0 { + for iNdEx := len(m.Children) - 1; iNdEx >= 0; iNdEx-- { + size, err := m.Children[iNdEx].MarshalToSizedBufferVTStrict(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x1a + } + } + if m.OptionalString != nil { + i -= len(*m.OptionalString) + copy(dAtA[i:], *m.OptionalString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(*m.OptionalString))) + i-- + dAtA[i] = 0x12 + } + if m.ImplicitInt32 != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.ImplicitInt32)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *HybridMessage) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ImplicitInt32 != 0 { + n += 1 + protohelpers.SizeOfVarint(uint64(m.ImplicitInt32)) + } + if m.OptionalString != nil { + l = len(*m.OptionalString) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) + } + if len(m.Children) > 0 { + for _, e := range m.Children { + l = e.SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) + } + } + n += len(m.unknownFields) + return n +} + +func (m *HybridMessage) UnmarshalVT(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: HybridMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HybridMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitInt32", wireType) + } + m.ImplicitInt32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ImplicitInt32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + s := string(dAtA[iNdEx:postIndex]) + m.OptionalString = &s + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Children", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Children = append(m.Children, &HybridMessage{}) + if err := m.Children[len(m.Children)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *HybridMessage) UnmarshalVTUnsafe(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: HybridMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HybridMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitInt32", wireType) + } + m.ImplicitInt32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ImplicitInt32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var stringValue string + if intStringLen > 0 { + stringValue = unsafe.String(&dAtA[iNdEx], intStringLen) + } + s := stringValue + m.OptionalString = &s + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Children", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Children = append(m.Children, &HybridMessage{}) + if err := m.Children[len(m.Children)-1].UnmarshalVTUnsafe(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} diff --git a/testproto/opaque/opaque.pb.go b/testproto/opaque/opaque.pb.go new file mode 100644 index 00000000..929539f9 --- /dev/null +++ b/testproto/opaque/opaque.pb.go @@ -0,0 +1,826 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.10 +// protoc v3.21.12 +// source: opaque/opaque.proto + +package opaque + +import ( + _ "github.com/planetscale/vtprotobuf/vtproto" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type OpaqueEnum int32 + +const ( + OpaqueEnum_OPAQUE_ENUM_ZERO OpaqueEnum = 0 + OpaqueEnum_OPAQUE_ENUM_ONE OpaqueEnum = 1 +) + +// Enum value maps for OpaqueEnum. +var ( + OpaqueEnum_name = map[int32]string{ + 0: "OPAQUE_ENUM_ZERO", + 1: "OPAQUE_ENUM_ONE", + } + OpaqueEnum_value = map[string]int32{ + "OPAQUE_ENUM_ZERO": 0, + "OPAQUE_ENUM_ONE": 1, + } +) + +func (x OpaqueEnum) Enum() *OpaqueEnum { + p := new(OpaqueEnum) + *p = x + return p +} + +func (x OpaqueEnum) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (OpaqueEnum) Descriptor() protoreflect.EnumDescriptor { + return file_opaque_opaque_proto_enumTypes[0].Descriptor() +} + +func (OpaqueEnum) Type() protoreflect.EnumType { + return &file_opaque_opaque_proto_enumTypes[0] +} + +func (x OpaqueEnum) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +type Inner struct { + state protoimpl.MessageState `protogen:"opaque.v1"` + xxx_hidden_Value int32 `protobuf:"varint,1,opt,name=value,proto3"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Inner) Reset() { + *x = Inner{} + mi := &file_opaque_opaque_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Inner) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Inner) ProtoMessage() {} + +func (x *Inner) ProtoReflect() protoreflect.Message { + mi := &file_opaque_opaque_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +func (x *Inner) GetValue() int32 { + if x != nil { + return x.xxx_hidden_Value + } + return 0 +} + +func (x *Inner) SetValue(v int32) { + x.xxx_hidden_Value = v +} + +type Inner_builder struct { + _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. + + Value int32 +} + +func (b0 Inner_builder) Build() *Inner { + m0 := &Inner{} + b, x := &b0, m0 + _, _ = b, x + x.xxx_hidden_Value = b.Value + return m0 +} + +type OpaqueMessage struct { + state protoimpl.MessageState `protogen:"opaque.v1"` + xxx_hidden_ImplicitInt32 int32 `protobuf:"varint,1,opt,name=implicit_int32,json=implicitInt32,proto3"` + xxx_hidden_ImplicitString string `protobuf:"bytes,2,opt,name=implicit_string,json=implicitString,proto3"` + xxx_hidden_OptionalInt32 int32 `protobuf:"varint,11,opt,name=optional_int32,json=optionalInt32,proto3,oneof"` + xxx_hidden_OptionalDouble float64 `protobuf:"fixed64,12,opt,name=optional_double,json=optionalDouble,proto3,oneof"` + xxx_hidden_OptionalBool bool `protobuf:"varint,13,opt,name=optional_bool,json=optionalBool,proto3,oneof"` + xxx_hidden_OptionalEnum OpaqueEnum `protobuf:"varint,14,opt,name=optional_enum,json=optionalEnum,proto3,enum=OpaqueEnum,oneof"` + xxx_hidden_OptionalString *string `protobuf:"bytes,15,opt,name=optional_string,json=optionalString,proto3,oneof"` + xxx_hidden_OptionalBytes []byte `protobuf:"bytes,16,opt,name=optional_bytes,json=optionalBytes,proto3,oneof"` + xxx_hidden_Inner *Inner `protobuf:"bytes,21,opt,name=inner,proto3"` + xxx_hidden_RepeatedInt32 []int32 `protobuf:"varint,31,rep,packed,name=repeated_int32,json=repeatedInt32,proto3"` + xxx_hidden_RepeatedInner *[]*Inner `protobuf:"bytes,32,rep,name=repeated_inner,json=repeatedInner,proto3"` + xxx_hidden_MapInt32 map[string]int32 `protobuf:"bytes,41,rep,name=map_int32,json=mapInt32,proto3" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"` + xxx_hidden_Selected isOpaqueMessage_Selected `protobuf_oneof:"selected"` + XXX_raceDetectHookData protoimpl.RaceDetectHookData + XXX_presence [1]uint32 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *OpaqueMessage) Reset() { + *x = OpaqueMessage{} + mi := &file_opaque_opaque_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *OpaqueMessage) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OpaqueMessage) ProtoMessage() {} + +func (x *OpaqueMessage) ProtoReflect() protoreflect.Message { + mi := &file_opaque_opaque_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +func (x *OpaqueMessage) GetImplicitInt32() int32 { + if x != nil { + return x.xxx_hidden_ImplicitInt32 + } + return 0 +} + +func (x *OpaqueMessage) GetImplicitString() string { + if x != nil { + return x.xxx_hidden_ImplicitString + } + return "" +} + +func (x *OpaqueMessage) GetOptionalInt32() int32 { + if x != nil { + return x.xxx_hidden_OptionalInt32 + } + return 0 +} + +func (x *OpaqueMessage) GetOptionalDouble() float64 { + if x != nil { + return x.xxx_hidden_OptionalDouble + } + return 0 +} + +func (x *OpaqueMessage) GetOptionalBool() bool { + if x != nil { + return x.xxx_hidden_OptionalBool + } + return false +} + +func (x *OpaqueMessage) GetOptionalEnum() OpaqueEnum { + if x != nil { + if protoimpl.X.Present(&(x.XXX_presence[0]), 5) { + return x.xxx_hidden_OptionalEnum + } + } + return OpaqueEnum_OPAQUE_ENUM_ZERO +} + +func (x *OpaqueMessage) GetOptionalString() string { + if x != nil { + if x.xxx_hidden_OptionalString != nil { + return *x.xxx_hidden_OptionalString + } + return "" + } + return "" +} + +func (x *OpaqueMessage) GetOptionalBytes() []byte { + if x != nil { + return x.xxx_hidden_OptionalBytes + } + return nil +} + +func (x *OpaqueMessage) GetInner() *Inner { + if x != nil { + return x.xxx_hidden_Inner + } + return nil +} + +func (x *OpaqueMessage) GetRepeatedInt32() []int32 { + if x != nil { + return x.xxx_hidden_RepeatedInt32 + } + return nil +} + +func (x *OpaqueMessage) GetRepeatedInner() []*Inner { + if x != nil { + if x.xxx_hidden_RepeatedInner != nil { + return *x.xxx_hidden_RepeatedInner + } + } + return nil +} + +func (x *OpaqueMessage) GetMapInt32() map[string]int32 { + if x != nil { + return x.xxx_hidden_MapInt32 + } + return nil +} + +func (x *OpaqueMessage) GetOneofInt32() int32 { + if x != nil { + if x, ok := x.xxx_hidden_Selected.(*opaqueMessage_OneofInt32); ok { + return x.OneofInt32 + } + } + return 0 +} + +func (x *OpaqueMessage) GetOneofString() string { + if x != nil { + if x, ok := x.xxx_hidden_Selected.(*opaqueMessage_OneofString); ok { + return x.OneofString + } + } + return "" +} + +func (x *OpaqueMessage) GetOneofInner() *Inner { + if x != nil { + if x, ok := x.xxx_hidden_Selected.(*opaqueMessage_OneofInner); ok { + return x.OneofInner + } + } + return nil +} + +func (x *OpaqueMessage) SetImplicitInt32(v int32) { + x.xxx_hidden_ImplicitInt32 = v +} + +func (x *OpaqueMessage) SetImplicitString(v string) { + x.xxx_hidden_ImplicitString = v +} + +func (x *OpaqueMessage) SetOptionalInt32(v int32) { + x.xxx_hidden_OptionalInt32 = v + protoimpl.X.SetPresent(&(x.XXX_presence[0]), 2, 13) +} + +func (x *OpaqueMessage) SetOptionalDouble(v float64) { + x.xxx_hidden_OptionalDouble = v + protoimpl.X.SetPresent(&(x.XXX_presence[0]), 3, 13) +} + +func (x *OpaqueMessage) SetOptionalBool(v bool) { + x.xxx_hidden_OptionalBool = v + protoimpl.X.SetPresent(&(x.XXX_presence[0]), 4, 13) +} + +func (x *OpaqueMessage) SetOptionalEnum(v OpaqueEnum) { + x.xxx_hidden_OptionalEnum = v + protoimpl.X.SetPresent(&(x.XXX_presence[0]), 5, 13) +} + +func (x *OpaqueMessage) SetOptionalString(v string) { + x.xxx_hidden_OptionalString = &v + protoimpl.X.SetPresent(&(x.XXX_presence[0]), 6, 13) +} + +func (x *OpaqueMessage) SetOptionalBytes(v []byte) { + if v == nil { + v = []byte{} + } + x.xxx_hidden_OptionalBytes = v + protoimpl.X.SetPresent(&(x.XXX_presence[0]), 7, 13) +} + +func (x *OpaqueMessage) SetInner(v *Inner) { + x.xxx_hidden_Inner = v +} + +func (x *OpaqueMessage) SetRepeatedInt32(v []int32) { + x.xxx_hidden_RepeatedInt32 = v +} + +func (x *OpaqueMessage) SetRepeatedInner(v []*Inner) { + x.xxx_hidden_RepeatedInner = &v +} + +func (x *OpaqueMessage) SetMapInt32(v map[string]int32) { + x.xxx_hidden_MapInt32 = v +} + +func (x *OpaqueMessage) SetOneofInt32(v int32) { + x.xxx_hidden_Selected = &opaqueMessage_OneofInt32{v} +} + +func (x *OpaqueMessage) SetOneofString(v string) { + x.xxx_hidden_Selected = &opaqueMessage_OneofString{v} +} + +func (x *OpaqueMessage) SetOneofInner(v *Inner) { + if v == nil { + x.xxx_hidden_Selected = nil + return + } + x.xxx_hidden_Selected = &opaqueMessage_OneofInner{v} +} + +func (x *OpaqueMessage) HasOptionalInt32() bool { + if x == nil { + return false + } + return protoimpl.X.Present(&(x.XXX_presence[0]), 2) +} + +func (x *OpaqueMessage) HasOptionalDouble() bool { + if x == nil { + return false + } + return protoimpl.X.Present(&(x.XXX_presence[0]), 3) +} + +func (x *OpaqueMessage) HasOptionalBool() bool { + if x == nil { + return false + } + return protoimpl.X.Present(&(x.XXX_presence[0]), 4) +} + +func (x *OpaqueMessage) HasOptionalEnum() bool { + if x == nil { + return false + } + return protoimpl.X.Present(&(x.XXX_presence[0]), 5) +} + +func (x *OpaqueMessage) HasOptionalString() bool { + if x == nil { + return false + } + return protoimpl.X.Present(&(x.XXX_presence[0]), 6) +} + +func (x *OpaqueMessage) HasOptionalBytes() bool { + if x == nil { + return false + } + return protoimpl.X.Present(&(x.XXX_presence[0]), 7) +} + +func (x *OpaqueMessage) HasInner() bool { + if x == nil { + return false + } + return x.xxx_hidden_Inner != nil +} + +func (x *OpaqueMessage) HasSelected() bool { + if x == nil { + return false + } + return x.xxx_hidden_Selected != nil +} + +func (x *OpaqueMessage) HasOneofInt32() bool { + if x == nil { + return false + } + _, ok := x.xxx_hidden_Selected.(*opaqueMessage_OneofInt32) + return ok +} + +func (x *OpaqueMessage) HasOneofString() bool { + if x == nil { + return false + } + _, ok := x.xxx_hidden_Selected.(*opaqueMessage_OneofString) + return ok +} + +func (x *OpaqueMessage) HasOneofInner() bool { + if x == nil { + return false + } + _, ok := x.xxx_hidden_Selected.(*opaqueMessage_OneofInner) + return ok +} + +func (x *OpaqueMessage) ClearOptionalInt32() { + protoimpl.X.ClearPresent(&(x.XXX_presence[0]), 2) + x.xxx_hidden_OptionalInt32 = 0 +} + +func (x *OpaqueMessage) ClearOptionalDouble() { + protoimpl.X.ClearPresent(&(x.XXX_presence[0]), 3) + x.xxx_hidden_OptionalDouble = 0 +} + +func (x *OpaqueMessage) ClearOptionalBool() { + protoimpl.X.ClearPresent(&(x.XXX_presence[0]), 4) + x.xxx_hidden_OptionalBool = false +} + +func (x *OpaqueMessage) ClearOptionalEnum() { + protoimpl.X.ClearPresent(&(x.XXX_presence[0]), 5) + x.xxx_hidden_OptionalEnum = OpaqueEnum_OPAQUE_ENUM_ZERO +} + +func (x *OpaqueMessage) ClearOptionalString() { + protoimpl.X.ClearPresent(&(x.XXX_presence[0]), 6) + x.xxx_hidden_OptionalString = nil +} + +func (x *OpaqueMessage) ClearOptionalBytes() { + protoimpl.X.ClearPresent(&(x.XXX_presence[0]), 7) + x.xxx_hidden_OptionalBytes = nil +} + +func (x *OpaqueMessage) ClearInner() { + x.xxx_hidden_Inner = nil +} + +func (x *OpaqueMessage) ClearSelected() { + x.xxx_hidden_Selected = nil +} + +func (x *OpaqueMessage) ClearOneofInt32() { + if _, ok := x.xxx_hidden_Selected.(*opaqueMessage_OneofInt32); ok { + x.xxx_hidden_Selected = nil + } +} + +func (x *OpaqueMessage) ClearOneofString() { + if _, ok := x.xxx_hidden_Selected.(*opaqueMessage_OneofString); ok { + x.xxx_hidden_Selected = nil + } +} + +func (x *OpaqueMessage) ClearOneofInner() { + if _, ok := x.xxx_hidden_Selected.(*opaqueMessage_OneofInner); ok { + x.xxx_hidden_Selected = nil + } +} + +const OpaqueMessage_Selected_not_set_case case_OpaqueMessage_Selected = 0 +const OpaqueMessage_OneofInt32_case case_OpaqueMessage_Selected = 51 +const OpaqueMessage_OneofString_case case_OpaqueMessage_Selected = 52 +const OpaqueMessage_OneofInner_case case_OpaqueMessage_Selected = 53 + +func (x *OpaqueMessage) WhichSelected() case_OpaqueMessage_Selected { + if x == nil { + return OpaqueMessage_Selected_not_set_case + } + switch x.xxx_hidden_Selected.(type) { + case *opaqueMessage_OneofInt32: + return OpaqueMessage_OneofInt32_case + case *opaqueMessage_OneofString: + return OpaqueMessage_OneofString_case + case *opaqueMessage_OneofInner: + return OpaqueMessage_OneofInner_case + default: + return OpaqueMessage_Selected_not_set_case + } +} + +type OpaqueMessage_builder struct { + _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. + + ImplicitInt32 int32 + ImplicitString string + // Explicit presence: scalars, enums and bools lose their pointer and are + // tracked by the presence bitfield, strings keep both. + OptionalInt32 *int32 + OptionalDouble *float64 + OptionalBool *bool + OptionalEnum *OpaqueEnum + OptionalString *string + OptionalBytes []byte + Inner *Inner + RepeatedInt32 []int32 + // Repeated message fields are stored as a pointer to the slice. + RepeatedInner []*Inner + MapInt32 map[string]int32 + // Fields of oneof xxx_hidden_Selected: + OneofInt32 *int32 + OneofString *string + OneofInner *Inner + // -- end of xxx_hidden_Selected +} + +func (b0 OpaqueMessage_builder) Build() *OpaqueMessage { + m0 := &OpaqueMessage{} + b, x := &b0, m0 + _, _ = b, x + x.xxx_hidden_ImplicitInt32 = b.ImplicitInt32 + x.xxx_hidden_ImplicitString = b.ImplicitString + if b.OptionalInt32 != nil { + protoimpl.X.SetPresentNonAtomic(&(x.XXX_presence[0]), 2, 13) + x.xxx_hidden_OptionalInt32 = *b.OptionalInt32 + } + if b.OptionalDouble != nil { + protoimpl.X.SetPresentNonAtomic(&(x.XXX_presence[0]), 3, 13) + x.xxx_hidden_OptionalDouble = *b.OptionalDouble + } + if b.OptionalBool != nil { + protoimpl.X.SetPresentNonAtomic(&(x.XXX_presence[0]), 4, 13) + x.xxx_hidden_OptionalBool = *b.OptionalBool + } + if b.OptionalEnum != nil { + protoimpl.X.SetPresentNonAtomic(&(x.XXX_presence[0]), 5, 13) + x.xxx_hidden_OptionalEnum = *b.OptionalEnum + } + if b.OptionalString != nil { + protoimpl.X.SetPresentNonAtomic(&(x.XXX_presence[0]), 6, 13) + x.xxx_hidden_OptionalString = b.OptionalString + } + if b.OptionalBytes != nil { + protoimpl.X.SetPresentNonAtomic(&(x.XXX_presence[0]), 7, 13) + x.xxx_hidden_OptionalBytes = b.OptionalBytes + } + x.xxx_hidden_Inner = b.Inner + x.xxx_hidden_RepeatedInt32 = b.RepeatedInt32 + x.xxx_hidden_RepeatedInner = &b.RepeatedInner + x.xxx_hidden_MapInt32 = b.MapInt32 + if b.OneofInt32 != nil { + x.xxx_hidden_Selected = &opaqueMessage_OneofInt32{*b.OneofInt32} + } + if b.OneofString != nil { + x.xxx_hidden_Selected = &opaqueMessage_OneofString{*b.OneofString} + } + if b.OneofInner != nil { + x.xxx_hidden_Selected = &opaqueMessage_OneofInner{b.OneofInner} + } + return m0 +} + +type case_OpaqueMessage_Selected protoreflect.FieldNumber + +func (x case_OpaqueMessage_Selected) String() string { + md := file_opaque_opaque_proto_msgTypes[1].Descriptor() + if x == 0 { + return "not set" + } + return protoimpl.X.MessageFieldStringOf(md, protoreflect.FieldNumber(x)) +} + +type isOpaqueMessage_Selected interface { + isOpaqueMessage_Selected() +} + +type opaqueMessage_OneofInt32 struct { + OneofInt32 int32 `protobuf:"varint,51,opt,name=oneof_int32,json=oneofInt32,proto3,oneof"` +} + +type opaqueMessage_OneofString struct { + OneofString string `protobuf:"bytes,52,opt,name=oneof_string,json=oneofString,proto3,oneof"` +} + +type opaqueMessage_OneofInner struct { + OneofInner *Inner `protobuf:"bytes,53,opt,name=oneof_inner,json=oneofInner,proto3,oneof"` +} + +func (*opaqueMessage_OneofInt32) isOpaqueMessage_Selected() {} + +func (*opaqueMessage_OneofString) isOpaqueMessage_Selected() {} + +func (*opaqueMessage_OneofInner) isOpaqueMessage_Selected() {} + +type PooledOpaque struct { + state protoimpl.MessageState `protogen:"opaque.v1"` + xxx_hidden_Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3"` + xxx_hidden_Counter int32 `protobuf:"varint,2,opt,name=counter,proto3,oneof"` + xxx_hidden_RepeatedInner *[]*Inner `protobuf:"bytes,3,rep,name=repeated_inner,json=repeatedInner,proto3"` + XXX_raceDetectHookData protoimpl.RaceDetectHookData + XXX_presence [1]uint32 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *PooledOpaque) Reset() { + *x = PooledOpaque{} + mi := &file_opaque_opaque_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *PooledOpaque) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PooledOpaque) ProtoMessage() {} + +func (x *PooledOpaque) ProtoReflect() protoreflect.Message { + mi := &file_opaque_opaque_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +func (x *PooledOpaque) GetPayload() []byte { + if x != nil { + return x.xxx_hidden_Payload + } + return nil +} + +func (x *PooledOpaque) GetCounter() int32 { + if x != nil { + return x.xxx_hidden_Counter + } + return 0 +} + +func (x *PooledOpaque) GetRepeatedInner() []*Inner { + if x != nil { + if x.xxx_hidden_RepeatedInner != nil { + return *x.xxx_hidden_RepeatedInner + } + } + return nil +} + +func (x *PooledOpaque) SetPayload(v []byte) { + if v == nil { + v = []byte{} + } + x.xxx_hidden_Payload = v +} + +func (x *PooledOpaque) SetCounter(v int32) { + x.xxx_hidden_Counter = v + protoimpl.X.SetPresent(&(x.XXX_presence[0]), 1, 3) +} + +func (x *PooledOpaque) SetRepeatedInner(v []*Inner) { + x.xxx_hidden_RepeatedInner = &v +} + +func (x *PooledOpaque) HasCounter() bool { + if x == nil { + return false + } + return protoimpl.X.Present(&(x.XXX_presence[0]), 1) +} + +func (x *PooledOpaque) ClearCounter() { + protoimpl.X.ClearPresent(&(x.XXX_presence[0]), 1) + x.xxx_hidden_Counter = 0 +} + +type PooledOpaque_builder struct { + _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. + + Payload []byte + Counter *int32 + RepeatedInner []*Inner +} + +func (b0 PooledOpaque_builder) Build() *PooledOpaque { + m0 := &PooledOpaque{} + b, x := &b0, m0 + _, _ = b, x + x.xxx_hidden_Payload = b.Payload + if b.Counter != nil { + protoimpl.X.SetPresentNonAtomic(&(x.XXX_presence[0]), 1, 3) + x.xxx_hidden_Counter = *b.Counter + } + x.xxx_hidden_RepeatedInner = &b.RepeatedInner + return m0 +} + +var File_opaque_opaque_proto protoreflect.FileDescriptor + +const file_opaque_opaque_proto_rawDesc = "" + + "\n" + + "\x13opaque/opaque.proto\x1a3github.com/planetscale/vtprotobuf/vtproto/ext.proto\"\x1d\n" + + "\x05Inner\x12\x14\n" + + "\x05value\x18\x01 \x01(\x05R\x05value\"\xd1\x06\n" + + "\rOpaqueMessage\x12%\n" + + "\x0eimplicit_int32\x18\x01 \x01(\x05R\rimplicitInt32\x12'\n" + + "\x0fimplicit_string\x18\x02 \x01(\tR\x0eimplicitString\x12*\n" + + "\x0eoptional_int32\x18\v \x01(\x05H\x01R\roptionalInt32\x88\x01\x01\x12,\n" + + "\x0foptional_double\x18\f \x01(\x01H\x02R\x0eoptionalDouble\x88\x01\x01\x12(\n" + + "\roptional_bool\x18\r \x01(\bH\x03R\foptionalBool\x88\x01\x01\x125\n" + + "\roptional_enum\x18\x0e \x01(\x0e2\v.OpaqueEnumH\x04R\foptionalEnum\x88\x01\x01\x12,\n" + + "\x0foptional_string\x18\x0f \x01(\tH\x05R\x0eoptionalString\x88\x01\x01\x12*\n" + + "\x0eoptional_bytes\x18\x10 \x01(\fH\x06R\roptionalBytes\x88\x01\x01\x12\x1c\n" + + "\x05inner\x18\x15 \x01(\v2\x06.InnerR\x05inner\x12%\n" + + "\x0erepeated_int32\x18\x1f \x03(\x05R\rrepeatedInt32\x12-\n" + + "\x0erepeated_inner\x18 \x03(\v2\x06.InnerR\rrepeatedInner\x129\n" + + "\tmap_int32\x18) \x03(\v2\x1c.OpaqueMessage.MapInt32EntryR\bmapInt32\x12!\n" + + "\voneof_int32\x183 \x01(\x05H\x00R\n" + + "oneofInt32\x12#\n" + + "\foneof_string\x184 \x01(\tH\x00R\voneofString\x12)\n" + + "\voneof_inner\x185 \x01(\v2\x06.InnerH\x00R\n" + + "oneofInner\x1a;\n" + + "\rMapInt32Entry\x12\x10\n" + + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + + "\x05value\x18\x02 \x01(\x05R\x05value:\x028\x01B\n" + + "\n" + + "\bselectedB\x11\n" + + "\x0f_optional_int32B\x12\n" + + "\x10_optional_doubleB\x10\n" + + "\x0e_optional_boolB\x10\n" + + "\x0e_optional_enumB\x12\n" + + "\x10_optional_stringB\x11\n" + + "\x0f_optional_bytes\"\x88\x01\n" + + "\fPooledOpaque\x12\x18\n" + + "\apayload\x18\x01 \x01(\fR\apayload\x12\x1d\n" + + "\acounter\x18\x02 \x01(\x05H\x00R\acounter\x88\x01\x01\x12-\n" + + "\x0erepeated_inner\x18\x03 \x03(\v2\x06.InnerR\rrepeatedInner:\x04\xa8\xa6\x1f\x01B\n" + + "\n" + + "\b_counter*7\n" + + "\n" + + "OpaqueEnum\x12\x14\n" + + "\x10OPAQUE_ENUM_ZERO\x10\x00\x12\x13\n" + + "\x0fOPAQUE_ENUM_ONE\x10\x01B\x12Z\x10testproto/opaqueb\x06proto3" + +var file_opaque_opaque_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_opaque_opaque_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_opaque_opaque_proto_goTypes = []any{ + (OpaqueEnum)(0), // 0: OpaqueEnum + (*Inner)(nil), // 1: Inner + (*OpaqueMessage)(nil), // 2: OpaqueMessage + (*PooledOpaque)(nil), // 3: PooledOpaque + nil, // 4: OpaqueMessage.MapInt32Entry +} +var file_opaque_opaque_proto_depIdxs = []int32{ + 0, // 0: OpaqueMessage.optional_enum:type_name -> OpaqueEnum + 1, // 1: OpaqueMessage.inner:type_name -> Inner + 1, // 2: OpaqueMessage.repeated_inner:type_name -> Inner + 4, // 3: OpaqueMessage.map_int32:type_name -> OpaqueMessage.MapInt32Entry + 1, // 4: OpaqueMessage.oneof_inner:type_name -> Inner + 1, // 5: PooledOpaque.repeated_inner:type_name -> Inner + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name +} + +func init() { file_opaque_opaque_proto_init() } +func file_opaque_opaque_proto_init() { + if File_opaque_opaque_proto != nil { + return + } + file_opaque_opaque_proto_msgTypes[1].OneofWrappers = []any{ + (*opaqueMessage_OneofInt32)(nil), + (*opaqueMessage_OneofString)(nil), + (*opaqueMessage_OneofInner)(nil), + } + file_opaque_opaque_proto_msgTypes[2].OneofWrappers = []any{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_opaque_opaque_proto_rawDesc), len(file_opaque_opaque_proto_rawDesc)), + NumEnums: 1, + NumMessages: 4, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_opaque_opaque_proto_goTypes, + DependencyIndexes: file_opaque_opaque_proto_depIdxs, + EnumInfos: file_opaque_opaque_proto_enumTypes, + MessageInfos: file_opaque_opaque_proto_msgTypes, + }.Build() + File_opaque_opaque_proto = out.File + file_opaque_opaque_proto_goTypes = nil + file_opaque_opaque_proto_depIdxs = nil +} diff --git a/testproto/opaque/opaque.proto b/testproto/opaque/opaque.proto new file mode 100644 index 00000000..48008854 --- /dev/null +++ b/testproto/opaque/opaque.proto @@ -0,0 +1,49 @@ +syntax = "proto3"; +option go_package = "testproto/opaque"; + +import "github.com/planetscale/vtprotobuf/vtproto/ext.proto"; + +enum OpaqueEnum { + OPAQUE_ENUM_ZERO = 0; + OPAQUE_ENUM_ONE = 1; +} + +message Inner { + int32 value = 1; +} + +message OpaqueMessage { + int32 implicit_int32 = 1; + string implicit_string = 2; + + // Explicit presence: scalars, enums and bools lose their pointer and are + // tracked by the presence bitfield, strings keep both. + optional int32 optional_int32 = 11; + optional double optional_double = 12; + optional bool optional_bool = 13; + optional OpaqueEnum optional_enum = 14; + optional string optional_string = 15; + optional bytes optional_bytes = 16; + + Inner inner = 21; + + repeated int32 repeated_int32 = 31; + // Repeated message fields are stored as a pointer to the slice. + repeated Inner repeated_inner = 32; + + map map_int32 = 41; + + oneof selected { + int32 oneof_int32 = 51; + string oneof_string = 52; + Inner oneof_inner = 53; + } +} + +message PooledOpaque { + option (vtproto.mempool) = true; + + bytes payload = 1; + optional int32 counter = 2; + repeated Inner repeated_inner = 3; +} diff --git a/testproto/opaque/opaque_test.go b/testproto/opaque/opaque_test.go new file mode 100644 index 00000000..4afb6bc7 --- /dev/null +++ b/testproto/opaque/opaque_test.go @@ -0,0 +1,91 @@ +package opaque + +import ( + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" +) + +func messages() []*OpaqueMessage { + return []*OpaqueMessage{ + {}, + OpaqueMessage_builder{ + ImplicitInt32: 1, + ImplicitString: "implicit", + OptionalInt32: proto.Int32(-2), + OptionalDouble: proto.Float64(3.5), + OptionalBool: proto.Bool(true), + OptionalEnum: OpaqueEnum_OPAQUE_ENUM_ONE.Enum(), + OptionalString: proto.String("optional"), + OptionalBytes: []byte("optional bytes"), + Inner: Inner_builder{Value: 4}.Build(), + RepeatedInt32: []int32{5, 6}, + RepeatedInner: []*Inner{ + Inner_builder{Value: 7}.Build(), + Inner_builder{Value: 8}.Build(), + }, + MapInt32: map[string]int32{"k": 9}, + OneofInt32: proto.Int32(10), + }.Build(), + // Only the presence bits distinguish these from an empty message. + OpaqueMessage_builder{ + OptionalInt32: proto.Int32(0), + OptionalBool: proto.Bool(false), + OptionalString: proto.String(""), + OptionalBytes: []byte{}, + }.Build(), + OpaqueMessage_builder{OneofString: proto.String("s")}.Build(), + OpaqueMessage_builder{OneofInner: Inner_builder{Value: 11}.Build()}.Build(), + } +} + +func TestRoundTrip(t *testing.T) { + for _, msg := range messages() { + vt, err := msg.MarshalVT() + require.NoError(t, err) + require.Equal(t, msg.SizeVT(), len(vt)) + + var fromVT OpaqueMessage + require.NoError(t, proto.Unmarshal(vt, &fromVT)) + require.True(t, proto.Equal(msg, &fromVT)) + + enc, err := proto.Marshal(msg) + require.NoError(t, err) + + var toVT OpaqueMessage + require.NoError(t, toVT.UnmarshalVT(enc)) + require.True(t, proto.Equal(msg, &toVT)) + + require.True(t, msg.EqualVT(msg.CloneVT())) + require.True(t, proto.Equal(msg, msg.CloneVT())) + } +} + +func TestPresenceOnlyDiffers(t *testing.T) { + set := OpaqueMessage_builder{OptionalInt32: proto.Int32(0)}.Build() + require.False(t, set.EqualVT(&OpaqueMessage{})) + require.True(t, set.EqualVT(OpaqueMessage_builder{OptionalInt32: proto.Int32(0)}.Build())) +} + +func TestPool(t *testing.T) { + msg := PooledOpaque_builder{ + Payload: []byte("payload"), + Counter: proto.Int32(1), + RepeatedInner: []*Inner{Inner_builder{Value: 2}.Build()}, + }.Build() + enc, err := proto.Marshal(msg) + require.NoError(t, err) + + pooled := PooledOpaqueFromVTPool() + require.NoError(t, pooled.UnmarshalVT(enc)) + require.True(t, proto.Equal(msg, pooled)) + pooled.ReturnToVTPool() + + // A recycled message must not carry over presence bits the next payload omits. + reused := PooledOpaqueFromVTPool() + require.NoError(t, reused.UnmarshalVT(nil)) + require.False(t, reused.HasCounter()) + require.True(t, proto.Equal(&PooledOpaque{}, reused)) + reused.ReturnToVTPool() +} diff --git a/testproto/opaque/opaque_vtproto.pb.go b/testproto/opaque/opaque_vtproto.pb.go new file mode 100644 index 00000000..d9074cc9 --- /dev/null +++ b/testproto/opaque/opaque_vtproto.pb.go @@ -0,0 +1,2896 @@ +// Code generated by protoc-gen-go-vtproto. DO NOT EDIT. +// protoc-gen-go-vtproto version: (devel) +// source: opaque/opaque.proto + +package opaque + +import ( + binary "encoding/binary" + fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" + proto "google.golang.org/protobuf/proto" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + math "math" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +func (m *Inner) CloneVT() *Inner { + if m == nil { + return (*Inner)(nil) + } + r := new(Inner) + r.xxx_hidden_Value = m.xxx_hidden_Value + if len(m.unknownFields) > 0 { + r.unknownFields = make([]byte, len(m.unknownFields)) + copy(r.unknownFields, m.unknownFields) + } + return r +} + +func (m *Inner) CloneMessageVT() proto.Message { + return m.CloneVT() +} + +func (m *OpaqueMessage) CloneVT() *OpaqueMessage { + if m == nil { + return (*OpaqueMessage)(nil) + } + r := new(OpaqueMessage) + r.xxx_hidden_ImplicitInt32 = m.xxx_hidden_ImplicitInt32 + r.xxx_hidden_ImplicitString = m.xxx_hidden_ImplicitString + r.xxx_hidden_OptionalInt32 = m.xxx_hidden_OptionalInt32 + r.xxx_hidden_OptionalDouble = m.xxx_hidden_OptionalDouble + r.xxx_hidden_OptionalBool = m.xxx_hidden_OptionalBool + r.xxx_hidden_OptionalEnum = m.xxx_hidden_OptionalEnum + r.xxx_hidden_Inner = m.xxx_hidden_Inner.CloneVT() + if rhs := m.xxx_hidden_OptionalString; rhs != nil { + tmpVal := *rhs + r.xxx_hidden_OptionalString = &tmpVal + } + if rhs := m.xxx_hidden_OptionalBytes; rhs != nil { + tmpBytes := make([]byte, len(rhs)) + copy(tmpBytes, rhs) + r.xxx_hidden_OptionalBytes = tmpBytes + } + if rhs := m.xxx_hidden_RepeatedInt32; rhs != nil { + tmpContainer := make([]int32, len(rhs)) + copy(tmpContainer, rhs) + r.xxx_hidden_RepeatedInt32 = tmpContainer + } + var vtmRepeatedInner []*Inner + if vtmRepeatedInnerp := m.xxx_hidden_RepeatedInner; vtmRepeatedInnerp != nil { + vtmRepeatedInner = *vtmRepeatedInnerp + } + if rhs := vtmRepeatedInner; rhs != nil { + tmpContainer := make([]*Inner, len(rhs)) + for k, v := range rhs { + tmpContainer[k] = v.CloneVT() + } + r.xxx_hidden_RepeatedInner = &tmpContainer + } + if rhs := m.xxx_hidden_MapInt32; rhs != nil { + tmpContainer := make(map[string]int32, len(rhs)) + for k, v := range rhs { + tmpContainer[k] = v + } + r.xxx_hidden_MapInt32 = tmpContainer + } + if m.xxx_hidden_Selected != nil { + r.xxx_hidden_Selected = m.xxx_hidden_Selected.(interface { + CloneVT() isOpaqueMessage_Selected + }).CloneVT() + } + r.XXX_presence = m.XXX_presence + if len(m.unknownFields) > 0 { + r.unknownFields = make([]byte, len(m.unknownFields)) + copy(r.unknownFields, m.unknownFields) + } + return r +} + +func (m *OpaqueMessage) CloneMessageVT() proto.Message { + return m.CloneVT() +} + +func (m *opaqueMessage_OneofInt32) CloneVT() isOpaqueMessage_Selected { + if m == nil { + return (*opaqueMessage_OneofInt32)(nil) + } + r := new(opaqueMessage_OneofInt32) + r.OneofInt32 = m.OneofInt32 + return r +} + +func (m *opaqueMessage_OneofString) CloneVT() isOpaqueMessage_Selected { + if m == nil { + return (*opaqueMessage_OneofString)(nil) + } + r := new(opaqueMessage_OneofString) + r.OneofString = m.OneofString + return r +} + +func (m *opaqueMessage_OneofInner) CloneVT() isOpaqueMessage_Selected { + if m == nil { + return (*opaqueMessage_OneofInner)(nil) + } + r := new(opaqueMessage_OneofInner) + r.OneofInner = m.OneofInner.CloneVT() + return r +} + +func (m *PooledOpaque) CloneVT() *PooledOpaque { + if m == nil { + return (*PooledOpaque)(nil) + } + r := PooledOpaqueFromVTPool() + r.xxx_hidden_Counter = m.xxx_hidden_Counter + if rhs := m.xxx_hidden_Payload; rhs != nil { + tmpBytes := make([]byte, len(rhs)) + copy(tmpBytes, rhs) + r.xxx_hidden_Payload = tmpBytes + } + var vtmRepeatedInner []*Inner + if vtmRepeatedInnerp := m.xxx_hidden_RepeatedInner; vtmRepeatedInnerp != nil { + vtmRepeatedInner = *vtmRepeatedInnerp + } + if rhs := vtmRepeatedInner; rhs != nil { + tmpContainer := make([]*Inner, len(rhs)) + for k, v := range rhs { + tmpContainer[k] = v.CloneVT() + } + r.xxx_hidden_RepeatedInner = &tmpContainer + } + r.XXX_presence = m.XXX_presence + if len(m.unknownFields) > 0 { + r.unknownFields = make([]byte, len(m.unknownFields)) + copy(r.unknownFields, m.unknownFields) + } + return r +} + +func (m *PooledOpaque) CloneMessageVT() proto.Message { + return m.CloneVT() +} + +func (this *Inner) EqualVT(that *Inner) bool { + if this == that { + return true + } else if this == nil || that == nil { + return false + } + if this.xxx_hidden_Value != that.xxx_hidden_Value { + return false + } + return string(this.unknownFields) == string(that.unknownFields) +} + +func (this *Inner) EqualMessageVT(thatMsg proto.Message) bool { + that, ok := thatMsg.(*Inner) + if !ok { + return false + } + return this.EqualVT(that) +} +func (this *OpaqueMessage) EqualVT(that *OpaqueMessage) bool { + if this == that { + return true + } else if this == nil || that == nil { + return false + } + if this.xxx_hidden_Selected == nil && that.xxx_hidden_Selected != nil { + return false + } else if this.xxx_hidden_Selected != nil { + if that.xxx_hidden_Selected == nil { + return false + } + if !this.xxx_hidden_Selected.(interface { + EqualVT(isOpaqueMessage_Selected) bool + }).EqualVT(that.xxx_hidden_Selected) { + return false + } + } + if this.xxx_hidden_ImplicitInt32 != that.xxx_hidden_ImplicitInt32 { + return false + } + if this.xxx_hidden_ImplicitString != that.xxx_hidden_ImplicitString { + return false + } + if protoimpl.X.Present(&(this.XXX_presence[0]), 2) != protoimpl.X.Present(&(that.XXX_presence[0]), 2) { + return false + } + if this.xxx_hidden_OptionalInt32 != that.xxx_hidden_OptionalInt32 { + return false + } + if protoimpl.X.Present(&(this.XXX_presence[0]), 3) != protoimpl.X.Present(&(that.XXX_presence[0]), 3) { + return false + } + if this.xxx_hidden_OptionalDouble != that.xxx_hidden_OptionalDouble { + return false + } + if protoimpl.X.Present(&(this.XXX_presence[0]), 4) != protoimpl.X.Present(&(that.XXX_presence[0]), 4) { + return false + } + if this.xxx_hidden_OptionalBool != that.xxx_hidden_OptionalBool { + return false + } + if protoimpl.X.Present(&(this.XXX_presence[0]), 5) != protoimpl.X.Present(&(that.XXX_presence[0]), 5) { + return false + } + if this.xxx_hidden_OptionalEnum != that.xxx_hidden_OptionalEnum { + return false + } + if p, q := this.xxx_hidden_OptionalString, that.xxx_hidden_OptionalString; (p == nil && q != nil) || (p != nil && (q == nil || *p != *q)) { + return false + } + if protoimpl.X.Present(&(this.XXX_presence[0]), 7) != protoimpl.X.Present(&(that.XXX_presence[0]), 7) { + return false + } + if string(this.xxx_hidden_OptionalBytes) != string(that.xxx_hidden_OptionalBytes) { + return false + } + if !this.xxx_hidden_Inner.EqualVT(that.xxx_hidden_Inner) { + return false + } + if len(this.xxx_hidden_RepeatedInt32) != len(that.xxx_hidden_RepeatedInt32) { + return false + } + for i, vx := range this.xxx_hidden_RepeatedInt32 { + vy := that.xxx_hidden_RepeatedInt32[i] + if vx != vy { + return false + } + } + var vtthisRepeatedInner []*Inner + if vtthisRepeatedInnerp := this.xxx_hidden_RepeatedInner; vtthisRepeatedInnerp != nil { + vtthisRepeatedInner = *vtthisRepeatedInnerp + } + var vtthatRepeatedInner []*Inner + if vtthatRepeatedInnerp := that.xxx_hidden_RepeatedInner; vtthatRepeatedInnerp != nil { + vtthatRepeatedInner = *vtthatRepeatedInnerp + } + if len(vtthisRepeatedInner) != len(vtthatRepeatedInner) { + return false + } + for i, vx := range vtthisRepeatedInner { + vy := vtthatRepeatedInner[i] + if p, q := vx, vy; p != q { + if p == nil { + p = &Inner{} + } + if q == nil { + q = &Inner{} + } + if !p.EqualVT(q) { + return false + } + } + } + if len(this.xxx_hidden_MapInt32) != len(that.xxx_hidden_MapInt32) { + return false + } + for i, vx := range this.xxx_hidden_MapInt32 { + vy, ok := that.xxx_hidden_MapInt32[i] + if !ok { + return false + } + if vx != vy { + return false + } + } + return string(this.unknownFields) == string(that.unknownFields) +} + +func (this *OpaqueMessage) EqualMessageVT(thatMsg proto.Message) bool { + that, ok := thatMsg.(*OpaqueMessage) + if !ok { + return false + } + return this.EqualVT(that) +} +func (this *opaqueMessage_OneofInt32) EqualVT(thatIface isOpaqueMessage_Selected) bool { + that, ok := thatIface.(*opaqueMessage_OneofInt32) + if !ok { + return false + } + if this == that { + return true + } + if this == nil && that != nil || this != nil && that == nil { + return false + } + if this.OneofInt32 != that.OneofInt32 { + return false + } + return true +} + +func (this *opaqueMessage_OneofString) EqualVT(thatIface isOpaqueMessage_Selected) bool { + that, ok := thatIface.(*opaqueMessage_OneofString) + if !ok { + return false + } + if this == that { + return true + } + if this == nil && that != nil || this != nil && that == nil { + return false + } + if this.OneofString != that.OneofString { + return false + } + return true +} + +func (this *opaqueMessage_OneofInner) EqualVT(thatIface isOpaqueMessage_Selected) bool { + that, ok := thatIface.(*opaqueMessage_OneofInner) + if !ok { + return false + } + if this == that { + return true + } + if this == nil && that != nil || this != nil && that == nil { + return false + } + if p, q := this.OneofInner, that.OneofInner; p != q { + if p == nil { + p = &Inner{} + } + if q == nil { + q = &Inner{} + } + if !p.EqualVT(q) { + return false + } + } + return true +} + +func (this *PooledOpaque) EqualVT(that *PooledOpaque) bool { + if this == that { + return true + } else if this == nil || that == nil { + return false + } + if string(this.xxx_hidden_Payload) != string(that.xxx_hidden_Payload) { + return false + } + if protoimpl.X.Present(&(this.XXX_presence[0]), 1) != protoimpl.X.Present(&(that.XXX_presence[0]), 1) { + return false + } + if this.xxx_hidden_Counter != that.xxx_hidden_Counter { + return false + } + var vtthisRepeatedInner []*Inner + if vtthisRepeatedInnerp := this.xxx_hidden_RepeatedInner; vtthisRepeatedInnerp != nil { + vtthisRepeatedInner = *vtthisRepeatedInnerp + } + var vtthatRepeatedInner []*Inner + if vtthatRepeatedInnerp := that.xxx_hidden_RepeatedInner; vtthatRepeatedInnerp != nil { + vtthatRepeatedInner = *vtthatRepeatedInnerp + } + if len(vtthisRepeatedInner) != len(vtthatRepeatedInner) { + return false + } + for i, vx := range vtthisRepeatedInner { + vy := vtthatRepeatedInner[i] + if p, q := vx, vy; p != q { + if p == nil { + p = &Inner{} + } + if q == nil { + q = &Inner{} + } + if !p.EqualVT(q) { + return false + } + } + } + return string(this.unknownFields) == string(that.unknownFields) +} + +func (this *PooledOpaque) EqualMessageVT(thatMsg proto.Message) bool { + that, ok := thatMsg.(*PooledOpaque) + if !ok { + return false + } + return this.EqualVT(that) +} +func (m *Inner) MarshalVT() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVT(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Inner) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *Inner) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if m.xxx_hidden_Value != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_Value)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *OpaqueMessage) MarshalVT() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVT(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *OpaqueMessage) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *OpaqueMessage) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if vtmsg, ok := m.xxx_hidden_Selected.(interface { + MarshalToSizedBufferVT([]byte) (int, error) + }); ok { + size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + } + if len(m.xxx_hidden_MapInt32) > 0 { + for k := range m.xxx_hidden_MapInt32 { + v := m.xxx_hidden_MapInt32[k] + baseI := i + i = protohelpers.EncodeVarint(dAtA, i, uint64(v)) + i-- + dAtA[i] = 0x10 + i -= len(k) + copy(dAtA[i:], k) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0xca + } + } + var vtmRepeatedInner []*Inner + if vtmRepeatedInnerp := m.xxx_hidden_RepeatedInner; vtmRepeatedInnerp != nil { + vtmRepeatedInner = *vtmRepeatedInnerp + } + if len(vtmRepeatedInner) > 0 { + for iNdEx := len(vtmRepeatedInner) - 1; iNdEx >= 0; iNdEx-- { + size, err := vtmRepeatedInner[iNdEx].MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0x82 + } + } + if len(m.xxx_hidden_RepeatedInt32) > 0 { + var pksize2 int + for _, num := range m.xxx_hidden_RepeatedInt32 { + pksize2 += protohelpers.SizeOfVarint(uint64(num)) + } + i -= pksize2 + j1 := i + for _, num1 := range m.xxx_hidden_RepeatedInt32 { + num := uint64(num1) + for num >= 1<<7 { + dAtA[j1] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j1++ + } + dAtA[j1] = uint8(num) + j1++ + } + i = protohelpers.EncodeVarint(dAtA, i, uint64(pksize2)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xfa + } + if m.xxx_hidden_Inner != nil { + size, err := m.xxx_hidden_Inner.MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xaa + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 7) { + i -= len(m.xxx_hidden_OptionalBytes) + copy(dAtA[i:], m.xxx_hidden_OptionalBytes) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.xxx_hidden_OptionalBytes))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x82 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 6) { + i -= len(*m.xxx_hidden_OptionalString) + copy(dAtA[i:], *m.xxx_hidden_OptionalString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(*m.xxx_hidden_OptionalString))) + i-- + dAtA[i] = 0x7a + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 5) { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_OptionalEnum)) + i-- + dAtA[i] = 0x70 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 4) { + i-- + if m.xxx_hidden_OptionalBool { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x68 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 3) { + i -= 8 + binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.xxx_hidden_OptionalDouble)))) + i-- + dAtA[i] = 0x61 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 2) { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_OptionalInt32)) + i-- + dAtA[i] = 0x58 + } + if len(m.xxx_hidden_ImplicitString) > 0 { + i -= len(m.xxx_hidden_ImplicitString) + copy(dAtA[i:], m.xxx_hidden_ImplicitString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.xxx_hidden_ImplicitString))) + i-- + dAtA[i] = 0x12 + } + if m.xxx_hidden_ImplicitInt32 != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_ImplicitInt32)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *opaqueMessage_OneofInt32) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *opaqueMessage_OneofInt32) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + i := len(dAtA) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.OneofInt32)) + i-- + dAtA[i] = 0x3 + i-- + dAtA[i] = 0x98 + return len(dAtA) - i, nil +} +func (m *opaqueMessage_OneofString) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *opaqueMessage_OneofString) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + i := len(dAtA) + i -= len(m.OneofString) + copy(dAtA[i:], m.OneofString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.OneofString))) + i-- + dAtA[i] = 0x3 + i-- + dAtA[i] = 0xa2 + return len(dAtA) - i, nil +} +func (m *opaqueMessage_OneofInner) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *opaqueMessage_OneofInner) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + i := len(dAtA) + if m.OneofInner != nil { + size, err := m.OneofInner.MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x3 + i-- + dAtA[i] = 0xaa + } else { + i = protohelpers.EncodeVarint(dAtA, i, 0) + i-- + dAtA[i] = 0x3 + i-- + dAtA[i] = 0xaa + } + return len(dAtA) - i, nil +} +func (m *PooledOpaque) MarshalVT() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVT(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PooledOpaque) MarshalToVT(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVT(dAtA[:size]) +} + +func (m *PooledOpaque) MarshalToSizedBufferVT(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + var vtmRepeatedInner []*Inner + if vtmRepeatedInnerp := m.xxx_hidden_RepeatedInner; vtmRepeatedInnerp != nil { + vtmRepeatedInner = *vtmRepeatedInnerp + } + if len(vtmRepeatedInner) > 0 { + for iNdEx := len(vtmRepeatedInner) - 1; iNdEx >= 0; iNdEx-- { + size, err := vtmRepeatedInner[iNdEx].MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x1a + } + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 1) { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_Counter)) + i-- + dAtA[i] = 0x10 + } + if len(m.xxx_hidden_Payload) > 0 { + i -= len(m.xxx_hidden_Payload) + copy(dAtA[i:], m.xxx_hidden_Payload) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.xxx_hidden_Payload))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Inner) MarshalVTStrict() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVTStrict(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Inner) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *Inner) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if m.xxx_hidden_Value != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_Value)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *OpaqueMessage) MarshalVTStrict() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVTStrict(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *OpaqueMessage) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *OpaqueMessage) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + if msg, ok := m.xxx_hidden_Selected.(*opaqueMessage_OneofInner); ok { + size, err := msg.MarshalToSizedBufferVTStrict(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + } + if msg, ok := m.xxx_hidden_Selected.(*opaqueMessage_OneofString); ok { + size, err := msg.MarshalToSizedBufferVTStrict(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + } + if msg, ok := m.xxx_hidden_Selected.(*opaqueMessage_OneofInt32); ok { + size, err := msg.MarshalToSizedBufferVTStrict(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + } + if len(m.xxx_hidden_MapInt32) > 0 { + for k := range m.xxx_hidden_MapInt32 { + v := m.xxx_hidden_MapInt32[k] + baseI := i + i = protohelpers.EncodeVarint(dAtA, i, uint64(v)) + i-- + dAtA[i] = 0x10 + i -= len(k) + copy(dAtA[i:], k) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0xca + } + } + var vtmRepeatedInner []*Inner + if vtmRepeatedInnerp := m.xxx_hidden_RepeatedInner; vtmRepeatedInnerp != nil { + vtmRepeatedInner = *vtmRepeatedInnerp + } + if len(vtmRepeatedInner) > 0 { + for iNdEx := len(vtmRepeatedInner) - 1; iNdEx >= 0; iNdEx-- { + size, err := vtmRepeatedInner[iNdEx].MarshalToSizedBufferVTStrict(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0x82 + } + } + if len(m.xxx_hidden_RepeatedInt32) > 0 { + var pksize2 int + for _, num := range m.xxx_hidden_RepeatedInt32 { + pksize2 += protohelpers.SizeOfVarint(uint64(num)) + } + i -= pksize2 + j1 := i + for _, num1 := range m.xxx_hidden_RepeatedInt32 { + num := uint64(num1) + for num >= 1<<7 { + dAtA[j1] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j1++ + } + dAtA[j1] = uint8(num) + j1++ + } + i = protohelpers.EncodeVarint(dAtA, i, uint64(pksize2)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xfa + } + if m.xxx_hidden_Inner != nil { + size, err := m.xxx_hidden_Inner.MarshalToSizedBufferVTStrict(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xaa + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 7) { + i -= len(m.xxx_hidden_OptionalBytes) + copy(dAtA[i:], m.xxx_hidden_OptionalBytes) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.xxx_hidden_OptionalBytes))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x82 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 6) { + i -= len(*m.xxx_hidden_OptionalString) + copy(dAtA[i:], *m.xxx_hidden_OptionalString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(*m.xxx_hidden_OptionalString))) + i-- + dAtA[i] = 0x7a + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 5) { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_OptionalEnum)) + i-- + dAtA[i] = 0x70 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 4) { + i-- + if m.xxx_hidden_OptionalBool { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x68 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 3) { + i -= 8 + binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.xxx_hidden_OptionalDouble)))) + i-- + dAtA[i] = 0x61 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 2) { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_OptionalInt32)) + i-- + dAtA[i] = 0x58 + } + if len(m.xxx_hidden_ImplicitString) > 0 { + i -= len(m.xxx_hidden_ImplicitString) + copy(dAtA[i:], m.xxx_hidden_ImplicitString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.xxx_hidden_ImplicitString))) + i-- + dAtA[i] = 0x12 + } + if m.xxx_hidden_ImplicitInt32 != 0 { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_ImplicitInt32)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *opaqueMessage_OneofInt32) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *opaqueMessage_OneofInt32) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + i := len(dAtA) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.OneofInt32)) + i-- + dAtA[i] = 0x3 + i-- + dAtA[i] = 0x98 + return len(dAtA) - i, nil +} +func (m *opaqueMessage_OneofString) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *opaqueMessage_OneofString) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + i := len(dAtA) + i -= len(m.OneofString) + copy(dAtA[i:], m.OneofString) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.OneofString))) + i-- + dAtA[i] = 0x3 + i-- + dAtA[i] = 0xa2 + return len(dAtA) - i, nil +} +func (m *opaqueMessage_OneofInner) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *opaqueMessage_OneofInner) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + i := len(dAtA) + if m.OneofInner != nil { + size, err := m.OneofInner.MarshalToSizedBufferVTStrict(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x3 + i-- + dAtA[i] = 0xaa + } else { + i = protohelpers.EncodeVarint(dAtA, i, 0) + i-- + dAtA[i] = 0x3 + i-- + dAtA[i] = 0xaa + } + return len(dAtA) - i, nil +} +func (m *PooledOpaque) MarshalVTStrict() (dAtA []byte, err error) { + if m == nil { + return nil, nil + } + size := m.SizeVT() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBufferVTStrict(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PooledOpaque) MarshalToVTStrict(dAtA []byte) (int, error) { + size := m.SizeVT() + return m.MarshalToSizedBufferVTStrict(dAtA[:size]) +} + +func (m *PooledOpaque) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { + if m == nil { + return 0, nil + } + i := len(dAtA) + _ = i + var l int + _ = l + if m.unknownFields != nil { + i -= len(m.unknownFields) + copy(dAtA[i:], m.unknownFields) + } + var vtmRepeatedInner []*Inner + if vtmRepeatedInnerp := m.xxx_hidden_RepeatedInner; vtmRepeatedInnerp != nil { + vtmRepeatedInner = *vtmRepeatedInnerp + } + if len(vtmRepeatedInner) > 0 { + for iNdEx := len(vtmRepeatedInner) - 1; iNdEx >= 0; iNdEx-- { + size, err := vtmRepeatedInner[iNdEx].MarshalToSizedBufferVTStrict(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x1a + } + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 1) { + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.xxx_hidden_Counter)) + i-- + dAtA[i] = 0x10 + } + if len(m.xxx_hidden_Payload) > 0 { + i -= len(m.xxx_hidden_Payload) + copy(dAtA[i:], m.xxx_hidden_Payload) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.xxx_hidden_Payload))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +var vtprotoPool_PooledOpaque = sync.Pool{ + New: func() interface{} { + return &PooledOpaque{} + }, +} + +func (m *PooledOpaque) ResetVT() { + if m != nil { + f0 := m.xxx_hidden_Payload[:0] + f1 := m.xxx_hidden_RepeatedInner + if f1 != nil { + for _, mm := range *f1 { + mm.Reset() + } + *f1 = (*f1)[:0] + } + m.Reset() + m.xxx_hidden_Payload = f0 + m.xxx_hidden_RepeatedInner = f1 + } +} +func (m *PooledOpaque) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_PooledOpaque.Put(m) + } +} +func PooledOpaqueFromVTPool() *PooledOpaque { + return vtprotoPool_PooledOpaque.Get().(*PooledOpaque) +} +func (m *Inner) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.xxx_hidden_Value != 0 { + n += 1 + protohelpers.SizeOfVarint(uint64(m.xxx_hidden_Value)) + } + n += len(m.unknownFields) + return n +} + +func (m *OpaqueMessage) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.xxx_hidden_ImplicitInt32 != 0 { + n += 1 + protohelpers.SizeOfVarint(uint64(m.xxx_hidden_ImplicitInt32)) + } + l = len(m.xxx_hidden_ImplicitString) + if l > 0 { + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 2) { + n += 1 + protohelpers.SizeOfVarint(uint64(m.xxx_hidden_OptionalInt32)) + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 3) { + n += 9 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 4) { + n += 2 + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 5) { + n += 1 + protohelpers.SizeOfVarint(uint64(m.xxx_hidden_OptionalEnum)) + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 6) { + l = len(*m.xxx_hidden_OptionalString) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 7) { + l = len(m.xxx_hidden_OptionalBytes) + n += 2 + l + protohelpers.SizeOfVarint(uint64(l)) + } + if m.xxx_hidden_Inner != nil { + l = m.xxx_hidden_Inner.SizeVT() + n += 2 + l + protohelpers.SizeOfVarint(uint64(l)) + } + if len(m.xxx_hidden_RepeatedInt32) > 0 { + l = 0 + for _, e := range m.xxx_hidden_RepeatedInt32 { + l += protohelpers.SizeOfVarint(uint64(e)) + } + n += 2 + protohelpers.SizeOfVarint(uint64(l)) + l + } + var vtmRepeatedInner []*Inner + if vtmRepeatedInnerp := m.xxx_hidden_RepeatedInner; vtmRepeatedInnerp != nil { + vtmRepeatedInner = *vtmRepeatedInnerp + } + if len(vtmRepeatedInner) > 0 { + for _, e := range vtmRepeatedInner { + l = e.SizeVT() + n += 2 + l + protohelpers.SizeOfVarint(uint64(l)) + } + } + if len(m.xxx_hidden_MapInt32) > 0 { + for k, v := range m.xxx_hidden_MapInt32 { + _ = k + _ = v + mapEntrySize := 1 + len(k) + protohelpers.SizeOfVarint(uint64(len(k))) + 1 + protohelpers.SizeOfVarint(uint64(v)) + n += mapEntrySize + 2 + protohelpers.SizeOfVarint(uint64(mapEntrySize)) + } + } + if vtmsg, ok := m.xxx_hidden_Selected.(interface{ SizeVT() int }); ok { + n += vtmsg.SizeVT() + } + n += len(m.unknownFields) + return n +} + +func (m *opaqueMessage_OneofInt32) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + n += 2 + protohelpers.SizeOfVarint(uint64(m.OneofInt32)) + return n +} +func (m *opaqueMessage_OneofString) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.OneofString) + n += 2 + l + protohelpers.SizeOfVarint(uint64(l)) + return n +} +func (m *opaqueMessage_OneofInner) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.OneofInner != nil { + l = m.OneofInner.SizeVT() + n += 2 + l + protohelpers.SizeOfVarint(uint64(l)) + } else { + n += 3 + } + return n +} +func (m *PooledOpaque) SizeVT() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.xxx_hidden_Payload) + if l > 0 { + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) + } + if protoimpl.X.Present(&(m.XXX_presence[0]), 1) { + n += 1 + protohelpers.SizeOfVarint(uint64(m.xxx_hidden_Counter)) + } + var vtmRepeatedInner []*Inner + if vtmRepeatedInnerp := m.xxx_hidden_RepeatedInner; vtmRepeatedInnerp != nil { + vtmRepeatedInner = *vtmRepeatedInnerp + } + if len(vtmRepeatedInner) > 0 { + for _, e := range vtmRepeatedInner { + l = e.SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) + } + } + n += len(m.unknownFields) + return n +} + +func (m *Inner) UnmarshalVT(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Inner: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Inner: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } + m.xxx_hidden_Value = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.xxx_hidden_Value |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OpaqueMessage) UnmarshalVT(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: OpaqueMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OpaqueMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitInt32", wireType) + } + m.xxx_hidden_ImplicitInt32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.xxx_hidden_ImplicitInt32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.xxx_hidden_ImplicitString = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalInt32", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_OptionalInt32 = v + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 2, 13) + case 12: + if wireType != 1 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalDouble", wireType) + } + var v uint64 + if (iNdEx + 8) > l { + return io.ErrUnexpectedEOF + } + v = uint64(binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + v2 := float64(math.Float64frombits(v)) + m.xxx_hidden_OptionalDouble = v2 + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 3, 13) + case 13: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalBool", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + b := bool(v != 0) + m.xxx_hidden_OptionalBool = b + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 4, 13) + case 14: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalEnum", wireType) + } + var v OpaqueEnum + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= OpaqueEnum(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_OptionalEnum = v + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 5, 13) + case 15: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + s := string(dAtA[iNdEx:postIndex]) + m.xxx_hidden_OptionalString = &s + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 6, 13) + iNdEx = postIndex + case 16: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalBytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.xxx_hidden_OptionalBytes = append(m.xxx_hidden_OptionalBytes[:0], dAtA[iNdEx:postIndex]...) + if m.xxx_hidden_OptionalBytes == nil { + m.xxx_hidden_OptionalBytes = []byte{} + } + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 7, 13) + iNdEx = postIndex + case 21: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Inner", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.xxx_hidden_Inner == nil { + m.xxx_hidden_Inner = &Inner{} + } + if err := m.xxx_hidden_Inner.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 31: + if wireType == 0 { + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_RepeatedInt32 = append(m.xxx_hidden_RepeatedInt32, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.xxx_hidden_RepeatedInt32) == 0 { + m.xxx_hidden_RepeatedInt32 = make([]int32, 0, elementCount) + } + for iNdEx < postIndex { + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_RepeatedInt32 = append(m.xxx_hidden_RepeatedInt32, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field RepeatedInt32", wireType) + } + case 32: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RepeatedInner", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.xxx_hidden_RepeatedInner == nil { + m.xxx_hidden_RepeatedInner = &[]*Inner{} + } + (*m.xxx_hidden_RepeatedInner) = append((*m.xxx_hidden_RepeatedInner), &Inner{}) + if err := (*m.xxx_hidden_RepeatedInner)[len((*m.xxx_hidden_RepeatedInner))-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 41: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MapInt32", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.xxx_hidden_MapInt32 == nil { + m.xxx_hidden_MapInt32 = make(map[string]int32) + } + var mapkey string + var mapvalue int32 + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return protohelpers.ErrInvalidLength + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return protohelpers.ErrInvalidLength + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapvalue |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + } else { + iNdEx = entryPreIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.xxx_hidden_MapInt32[mapkey] = mapvalue + iNdEx = postIndex + case 51: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field OneofInt32", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_Selected = &opaqueMessage_OneofInt32{OneofInt32: v} + case 52: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OneofString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.xxx_hidden_Selected = &opaqueMessage_OneofString{OneofString: string(dAtA[iNdEx:postIndex])} + iNdEx = postIndex + case 53: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OneofInner", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if oneof, ok := m.xxx_hidden_Selected.(*opaqueMessage_OneofInner); ok { + if err := oneof.OneofInner.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err + } + } else { + v := &Inner{} + if err := v.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.xxx_hidden_Selected = &opaqueMessage_OneofInner{OneofInner: v} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PooledOpaque) UnmarshalVT(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PooledOpaque: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PooledOpaque: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.xxx_hidden_Payload = append(m.xxx_hidden_Payload[:0], dAtA[iNdEx:postIndex]...) + if m.xxx_hidden_Payload == nil { + m.xxx_hidden_Payload = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Counter", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_Counter = v + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 1, 3) + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RepeatedInner", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.xxx_hidden_RepeatedInner == nil { + m.xxx_hidden_RepeatedInner = &[]*Inner{} + } + if len((*m.xxx_hidden_RepeatedInner)) == cap((*m.xxx_hidden_RepeatedInner)) { + (*m.xxx_hidden_RepeatedInner) = append((*m.xxx_hidden_RepeatedInner), &Inner{}) + } else { + (*m.xxx_hidden_RepeatedInner) = (*m.xxx_hidden_RepeatedInner)[:len((*m.xxx_hidden_RepeatedInner))+1] + if (*m.xxx_hidden_RepeatedInner)[len((*m.xxx_hidden_RepeatedInner))-1] == nil { + (*m.xxx_hidden_RepeatedInner)[len((*m.xxx_hidden_RepeatedInner))-1] = &Inner{} + } + } + if err := (*m.xxx_hidden_RepeatedInner)[len((*m.xxx_hidden_RepeatedInner))-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Inner) UnmarshalVTUnsafe(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Inner: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Inner: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } + m.xxx_hidden_Value = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.xxx_hidden_Value |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OpaqueMessage) UnmarshalVTUnsafe(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: OpaqueMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OpaqueMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitInt32", wireType) + } + m.xxx_hidden_ImplicitInt32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.xxx_hidden_ImplicitInt32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ImplicitString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var stringValue string + if intStringLen > 0 { + stringValue = unsafe.String(&dAtA[iNdEx], intStringLen) + } + m.xxx_hidden_ImplicitString = stringValue + iNdEx = postIndex + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalInt32", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_OptionalInt32 = v + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 2, 13) + case 12: + if wireType != 1 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalDouble", wireType) + } + var v uint64 + if (iNdEx + 8) > l { + return io.ErrUnexpectedEOF + } + v = uint64(binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + v2 := float64(math.Float64frombits(v)) + m.xxx_hidden_OptionalDouble = v2 + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 3, 13) + case 13: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalBool", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + b := bool(v != 0) + m.xxx_hidden_OptionalBool = b + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 4, 13) + case 14: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalEnum", wireType) + } + var v OpaqueEnum + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= OpaqueEnum(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_OptionalEnum = v + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 5, 13) + case 15: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var stringValue string + if intStringLen > 0 { + stringValue = unsafe.String(&dAtA[iNdEx], intStringLen) + } + s := stringValue + m.xxx_hidden_OptionalString = &s + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 6, 13) + iNdEx = postIndex + case 16: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OptionalBytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.xxx_hidden_OptionalBytes = dAtA[iNdEx:postIndex] + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 7, 13) + iNdEx = postIndex + case 21: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Inner", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.xxx_hidden_Inner == nil { + m.xxx_hidden_Inner = &Inner{} + } + if err := m.xxx_hidden_Inner.UnmarshalVTUnsafe(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 31: + if wireType == 0 { + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_RepeatedInt32 = append(m.xxx_hidden_RepeatedInt32, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.xxx_hidden_RepeatedInt32) == 0 { + m.xxx_hidden_RepeatedInt32 = make([]int32, 0, elementCount) + } + for iNdEx < postIndex { + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_RepeatedInt32 = append(m.xxx_hidden_RepeatedInt32, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field RepeatedInt32", wireType) + } + case 32: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RepeatedInner", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.xxx_hidden_RepeatedInner == nil { + m.xxx_hidden_RepeatedInner = &[]*Inner{} + } + (*m.xxx_hidden_RepeatedInner) = append((*m.xxx_hidden_RepeatedInner), &Inner{}) + if err := (*m.xxx_hidden_RepeatedInner)[len((*m.xxx_hidden_RepeatedInner))-1].UnmarshalVTUnsafe(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 41: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MapInt32", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.xxx_hidden_MapInt32 == nil { + m.xxx_hidden_MapInt32 = make(map[string]int32) + } + var mapkey string + var mapvalue int32 + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return protohelpers.ErrInvalidLength + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return protohelpers.ErrInvalidLength + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + if intStringLenmapkey == 0 { + mapkey = "" + } else { + mapkey = unsafe.String(&dAtA[iNdEx], intStringLenmapkey) + } + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapvalue |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + } else { + iNdEx = entryPreIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.xxx_hidden_MapInt32[mapkey] = mapvalue + iNdEx = postIndex + case 51: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field OneofInt32", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_Selected = &opaqueMessage_OneofInt32{OneofInt32: v} + case 52: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OneofString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var stringValue string + if intStringLen > 0 { + stringValue = unsafe.String(&dAtA[iNdEx], intStringLen) + } + m.xxx_hidden_Selected = &opaqueMessage_OneofString{OneofString: stringValue} + iNdEx = postIndex + case 53: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OneofInner", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if oneof, ok := m.xxx_hidden_Selected.(*opaqueMessage_OneofInner); ok { + if err := oneof.OneofInner.UnmarshalVTUnsafe(dAtA[iNdEx:postIndex]); err != nil { + return err + } + } else { + v := &Inner{} + if err := v.UnmarshalVTUnsafe(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.xxx_hidden_Selected = &opaqueMessage_OneofInner{OneofInner: v} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PooledOpaque) UnmarshalVTUnsafe(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PooledOpaque: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PooledOpaque: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.xxx_hidden_Payload = dAtA[iNdEx:postIndex] + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Counter", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.xxx_hidden_Counter = v + protoimpl.X.SetPresent(&(m.XXX_presence[0]), 1, 3) + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RepeatedInner", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.xxx_hidden_RepeatedInner == nil { + m.xxx_hidden_RepeatedInner = &[]*Inner{} + } + if len((*m.xxx_hidden_RepeatedInner)) == cap((*m.xxx_hidden_RepeatedInner)) { + (*m.xxx_hidden_RepeatedInner) = append((*m.xxx_hidden_RepeatedInner), &Inner{}) + } else { + (*m.xxx_hidden_RepeatedInner) = (*m.xxx_hidden_RepeatedInner)[:len((*m.xxx_hidden_RepeatedInner))+1] + if (*m.xxx_hidden_RepeatedInner)[len((*m.xxx_hidden_RepeatedInner))-1] == nil { + (*m.xxx_hidden_RepeatedInner)[len((*m.xxx_hidden_RepeatedInner))-1] = &Inner{} + } + } + if err := (*m.xxx_hidden_RepeatedInner)[len((*m.xxx_hidden_RepeatedInner))-1].UnmarshalVTUnsafe(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.unknownFields = append(m.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +}