From 745457b3954ca00db7544403d5816047b4579751 Mon Sep 17 00:00:00 2001 From: Arthur Rodrigues Date: Sat, 11 Jul 2026 11:48:26 -0300 Subject: [PATCH 1/2] deps: updates vtprotobuf to 0.6.0 --- gen/main.go | 4 ++-- gen/vtproto.go | 44 ++++++++++++++++++++++++++++++-------------- go.mod | 4 ++-- go.sum | 16 +++++----------- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/gen/main.go b/gen/main.go index 05f1430..f783c40 100644 --- a/gen/main.go +++ b/gen/main.go @@ -94,10 +94,10 @@ type Options struct { } func NewGenerator(plugin *protogen.Plugin) (*Generator, error) { - ext := &vtgenerator.Extensions{} + cfg := &vtgenerator.Config{} featureNames := []string{"marshal", "unmarshal", "size"} - vtgen, err := vtgenerator.NewGenerator(plugin.Files, featureNames, ext) + vtgen, err := vtgenerator.NewGenerator(plugin, featureNames, cfg) if err != nil { return nil, err } diff --git a/gen/vtproto.go b/gen/vtproto.go index 888ca16..82ded4b 100644 --- a/gen/vtproto.go +++ b/gen/vtproto.go @@ -2,32 +2,48 @@ package gen import ( "bytes" + "google.golang.org/protobuf/compiler/protogen" + vtgenerator "github.com/planetscale/vtprotobuf/generator" // Confirme o import/alias utilizado no seu projeto ) func (gg *Generator) generateVTFile(f *fileInfo) { // It is a bit tricky, but necessary for workaround. - // Generates a vtprotobuf file as a dummy file, modifies and writes that to the real file. - filename := f.GeneratedFilenamePrefix + "_vt_dummy.pb.go" - g := gg.plugin.NewGeneratedFile(filename, f.GoImportPath) - gg.vtgen.GenerateFile(g, f.File) + // We create a dummyPlugin in memory. + // Create the VTfile with it and then update its header + dummyPlugin, err := protogen.Options{}.New(gg.plugin.Request) + if err != nil { + gg.plugin.Error(err) + return + } - b, err := g.Content() + cfg := &vtgenerator.Config{} + featureNames := []string{"marshal", "unmarshal", "size"} + localVtGen, err := vtgenerator.NewGenerator(dummyPlugin, featureNames, cfg) if err != nil { gg.plugin.Error(err) return } - // Skip the generated header - if idx := bytes.Index(b, []byte("import ")); idx != -1 { - b = b[idx:] + localVtGen.Generate() + + targetFilename := f.GeneratedFilenamePrefix + "_vtproto.pb.go" + var vtContent []byte + for _, rf := range dummyPlugin.Response().File { + if rf.GetName() == targetFilename { + vtContent = []byte(rf.GetContent()) + break + } } - // Do not generate the dummy file - g.Skip() + if len(vtContent) == 0 { + return + } + + if idx := bytes.Index(vtContent, []byte("import ")); idx != -1 { + vtContent = vtContent[idx:] + } - // Write the replaced content - filename = f.GeneratedFilenamePrefix + "_vtproto.pb.go" - g = gg.plugin.NewGeneratedFile(filename, f.GoImportPath) + g := gg.plugin.NewGeneratedFile(targetFilename, f.GoImportPath) gg.generateHeader(g, f) - g.Write(b) + g.Write(vtContent) } diff --git a/go.mod b/go.mod index 18fcc74..70d7fdb 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/knqyf263/go-plugin go 1.24.0 require ( - github.com/planetscale/vtprotobuf v0.4.0 + github.com/planetscale/vtprotobuf v0.6.0 github.com/stretchr/testify v1.8.4 github.com/tetratelabs/wazero v1.9.0 - google.golang.org/protobuf v1.30.0 + google.golang.org/protobuf v1.31.0 ) require ( diff --git a/go.sum b/go.sum index d0360f6..0072eef 100644 --- a/go.sum +++ b/go.sum @@ -1,28 +1,22 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/planetscale/vtprotobuf v0.4.0 h1:NEI+g4woRaAZgeZ3sAvbtyvMBRjIv5kE7EWYQ8m4JwY= -github.com/planetscale/vtprotobuf v0.4.0/go.mod h1:wm1N3qk9G/4+VM1WhpkLbvY/d8+0PbwYYpP5P5VhTks= +github.com/planetscale/vtprotobuf v0.6.0 h1:nBeETjudeJ5ZgBHUz1fVHvbqUKnYOXNhsIEabROxmNA= +github.com/planetscale/vtprotobuf v0.6.0/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I= github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From a377c6eaa55da6d704bd67c4b552a8db10269551 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 20 Aug 2026 14:00:04 +0200 Subject: [PATCH 2/2] fixup! deps: updates vtprotobuf to 0.6.0 Work around vtprotobuf's well-known type locality handling. go-plugin replaces the standard protobuf well-known types with its own implementations under github.com/knqyf263/go-plugin/types/known. These types retain their original protobuf package names (google.protobuf), but live in separate Go packages such as anypb, structpb, typepb, etc. vtprotobuf determines whether a message is local using its protobuf package name: message.Desc.ParentFile().Package() and records generated packages in LocalPackages using the same key. That assumption breaks for go-plugin's replacement well-known types. For example, google.protobuf.Type and google.protobuf.Any are considered local to each other even though their Go types live in separate typepb and anypb packages. This can cause vtprotobuf to emit unqualified types such as: (*Any)(m.Value) instead of: (*anypb.Any)(m.Value) It also affects vtprotobuf's special handling of well-known types, where a type considered local has its Go import path cleared. With go-plugin's layout this can result in invalid imports such as: __ "" or incorrect references to vtprotobuf's own well-known type packages. The proper fix belongs in vtprotobuf: locality should be determined by the generated Go package/import path rather than only by the protobuf package name. Testing this locally by comparing message.GoIdent.GoImportPath with the import path of the file being generated fixes the failures and allows the full go-plugin test suite to pass. Until that can be fixed upstream, keep the workaround local to go-plugin. Reapply go-plugin's well-known type import remapping to the temporary protogen.Plugin used for vtprotobuf generation, preserve local well-known type generation, rewrite vtprotobuf's hard-coded well-known type package paths, qualify cross-package well-known type references, and normalize duplicate imports introduced by those rewrites. This is intentionally a stop-gap to allow go-plugin to build with vtprotobuf v0.6.x without carrying a fork of vtprotobuf. Signed-off-by: Sebastiaan van Stijn --- .../helloworld/greeting/greet_vtproto.pb.go | 136 +- .../json-parser/export/library_vtproto.pb.go | 158 +- .../proto/greet_vtproto.pb.go | 168 +-- .../greeting/greet_vtproto.pb.go | 184 +-- .../known-types/known/known_vtproto.pb.go | 318 +--- examples/wasi/cat/cat_vtproto.pb.go | 136 +- gen/main.go | 163 +- gen/vtproto.go | 304 +++- tests/fields/proto/fields_vtproto.pb.go | 424 ++---- tests/host-functions/proto/host_vtproto.pb.go | 190 +-- tests/import/proto/bar/bar_vtproto.pb.go | 136 +- tests/import/proto/foo/foo_vtproto.pb.go | 120 +- tests/well-known/proto/known_vtproto.pb.go | 1318 ++++------------- types/known/anypb/any_vtproto.pb.go | 130 +- types/known/durationpb/duration_vtproto.pb.go | 122 +- types/known/emptypb/empty_vtproto.pb.go | 110 +- .../source_context_vtproto.pb.go | 120 +- types/known/structpb/struct_vtproto.pb.go | 286 ++-- .../known/timestamppb/timestamp_vtproto.pb.go | 122 +- types/known/typepb/type_vtproto.pb.go | 364 ++--- types/known/wrapperspb/wrappers_vtproto.pb.go | 204 +-- 21 files changed, 1508 insertions(+), 3705 deletions(-) diff --git a/examples/helloworld/greeting/greet_vtproto.pb.go b/examples/helloworld/greeting/greet_vtproto.pb.go index 860e42c..b8e0510 100644 --- a/examples/helloworld/greeting/greet_vtproto.pb.go +++ b/examples/helloworld/greeting/greet_vtproto.pb.go @@ -8,9 +8,9 @@ package greeting import ( fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -53,7 +53,7 @@ func (m *GreetRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Name) > 0 { i -= len(m.Name) copy(dAtA[i:], m.Name) - i = encodeVarint(dAtA, i, uint64(len(m.Name))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Name))) i-- dAtA[i] = 0xa } @@ -93,24 +93,13 @@ func (m *GreetReply) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Message) > 0 { i -= len(m.Message) copy(dAtA[i:], m.Message) - i = encodeVarint(dAtA, i, uint64(len(m.Message))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Message))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *GreetRequest) SizeVT() (n int) { if m == nil { return 0 @@ -119,7 +108,7 @@ func (m *GreetRequest) SizeVT() (n int) { _ = l l = len(m.Name) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -133,18 +122,12 @@ func (m *GreetReply) SizeVT() (n int) { _ = l l = len(m.Message) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -153,7 +136,7 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -181,7 +164,7 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -195,11 +178,11 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -208,12 +191,12 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -236,7 +219,7 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -264,7 +247,7 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -278,11 +261,11 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -291,12 +274,12 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -311,88 +294,3 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/examples/host-function-library/library/json-parser/export/library_vtproto.pb.go b/examples/host-function-library/library/json-parser/export/library_vtproto.pb.go index 738cf4e..97c4e84 100644 --- a/examples/host-function-library/library/json-parser/export/library_vtproto.pb.go +++ b/examples/host-function-library/library/json-parser/export/library_vtproto.pb.go @@ -8,9 +8,9 @@ package export import ( fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -53,7 +53,7 @@ func (m *ParseJsonRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Content) > 0 { i -= len(m.Content) copy(dAtA[i:], m.Content) - i = encodeVarint(dAtA, i, uint64(len(m.Content))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Content))) i-- dAtA[i] = 0xa } @@ -96,7 +96,7 @@ func (m *ParseJsonResponse) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0xa } @@ -134,31 +134,20 @@ func (m *Person) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.Age != 0 { - i = encodeVarint(dAtA, i, uint64(m.Age)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Age)) i-- dAtA[i] = 0x10 } if len(m.Name) > 0 { i -= len(m.Name) copy(dAtA[i:], m.Name) - i = encodeVarint(dAtA, i, uint64(len(m.Name))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Name))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *ParseJsonRequest) SizeVT() (n int) { if m == nil { return 0 @@ -167,7 +156,7 @@ func (m *ParseJsonRequest) SizeVT() (n int) { _ = l l = len(m.Content) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -181,7 +170,7 @@ func (m *ParseJsonResponse) SizeVT() (n int) { _ = l if m.Response != nil { l = m.Response.SizeVT() - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -195,21 +184,15 @@ func (m *Person) SizeVT() (n int) { _ = l l = len(m.Name) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.Age != 0 { - n += 1 + sov(uint64(m.Age)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Age)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *ParseJsonRequest) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -218,7 +201,7 @@ func (m *ParseJsonRequest) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -246,7 +229,7 @@ func (m *ParseJsonRequest) UnmarshalVT(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -259,11 +242,11 @@ func (m *ParseJsonRequest) UnmarshalVT(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -275,12 +258,12 @@ func (m *ParseJsonRequest) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -303,7 +286,7 @@ func (m *ParseJsonResponse) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -331,7 +314,7 @@ func (m *ParseJsonResponse) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -344,11 +327,11 @@ func (m *ParseJsonResponse) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -362,12 +345,12 @@ func (m *ParseJsonResponse) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -390,7 +373,7 @@ func (m *Person) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -418,7 +401,7 @@ func (m *Person) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -432,11 +415,11 @@ func (m *Person) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -450,7 +433,7 @@ func (m *Person) UnmarshalVT(dAtA []byte) error { m.Age = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -464,12 +447,12 @@ func (m *Person) UnmarshalVT(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -484,88 +467,3 @@ func (m *Person) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/examples/host-function-library/proto/greet_vtproto.pb.go b/examples/host-function-library/proto/greet_vtproto.pb.go index c1333e7..1557d2b 100644 --- a/examples/host-function-library/proto/greet_vtproto.pb.go +++ b/examples/host-function-library/proto/greet_vtproto.pb.go @@ -8,9 +8,9 @@ package proto import ( fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -53,7 +53,7 @@ func (m *GreetRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Name) > 0 { i -= len(m.Name) copy(dAtA[i:], m.Name) - i = encodeVarint(dAtA, i, uint64(len(m.Name))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Name))) i-- dAtA[i] = 0xa } @@ -93,7 +93,7 @@ func (m *GreetReply) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Message) > 0 { i -= len(m.Message) copy(dAtA[i:], m.Message) - i = encodeVarint(dAtA, i, uint64(len(m.Message))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Message))) i-- dAtA[i] = 0xa } @@ -133,7 +133,7 @@ func (m *SanRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Message) > 0 { i -= len(m.Message) copy(dAtA[i:], m.Message) - i = encodeVarint(dAtA, i, uint64(len(m.Message))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Message))) i-- dAtA[i] = 0xa } @@ -173,24 +173,13 @@ func (m *SanResponse) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Message) > 0 { i -= len(m.Message) copy(dAtA[i:], m.Message) - i = encodeVarint(dAtA, i, uint64(len(m.Message))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Message))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *GreetRequest) SizeVT() (n int) { if m == nil { return 0 @@ -199,7 +188,7 @@ func (m *GreetRequest) SizeVT() (n int) { _ = l l = len(m.Name) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -213,7 +202,7 @@ func (m *GreetReply) SizeVT() (n int) { _ = l l = len(m.Message) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -227,7 +216,7 @@ func (m *SanRequest) SizeVT() (n int) { _ = l l = len(m.Message) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -241,18 +230,12 @@ func (m *SanResponse) SizeVT() (n int) { _ = l l = len(m.Message) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -261,7 +244,7 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -289,7 +272,7 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -303,11 +286,11 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -316,12 +299,12 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -344,7 +327,7 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -372,7 +355,7 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -386,11 +369,11 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -399,12 +382,12 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -427,7 +410,7 @@ func (m *SanRequest) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -455,7 +438,7 @@ func (m *SanRequest) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -469,11 +452,11 @@ func (m *SanRequest) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -482,12 +465,12 @@ func (m *SanRequest) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -510,7 +493,7 @@ func (m *SanResponse) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -538,7 +521,7 @@ func (m *SanResponse) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -552,11 +535,11 @@ func (m *SanResponse) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -565,12 +548,12 @@ func (m *SanResponse) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -585,88 +568,3 @@ func (m *SanResponse) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/examples/host-functions/greeting/greet_vtproto.pb.go b/examples/host-functions/greeting/greet_vtproto.pb.go index 62f9855..b949475 100644 --- a/examples/host-functions/greeting/greet_vtproto.pb.go +++ b/examples/host-functions/greeting/greet_vtproto.pb.go @@ -8,9 +8,9 @@ package greeting import ( fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -53,7 +53,7 @@ func (m *GreetRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Name) > 0 { i -= len(m.Name) copy(dAtA[i:], m.Name) - i = encodeVarint(dAtA, i, uint64(len(m.Name))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Name))) i-- dAtA[i] = 0xa } @@ -93,7 +93,7 @@ func (m *GreetReply) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Message) > 0 { i -= len(m.Message) copy(dAtA[i:], m.Message) - i = encodeVarint(dAtA, i, uint64(len(m.Message))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Message))) i-- dAtA[i] = 0xa } @@ -133,7 +133,7 @@ func (m *HttpGetRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Url) > 0 { i -= len(m.Url) copy(dAtA[i:], m.Url) - i = encodeVarint(dAtA, i, uint64(len(m.Url))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Url))) i-- dAtA[i] = 0xa } @@ -173,7 +173,7 @@ func (m *HttpGetResponse) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Response) > 0 { i -= len(m.Response) copy(dAtA[i:], m.Response) - i = encodeVarint(dAtA, i, uint64(len(m.Response))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Response))) i-- dAtA[i] = 0xa } @@ -213,24 +213,13 @@ func (m *LogRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Message) > 0 { i -= len(m.Message) copy(dAtA[i:], m.Message) - i = encodeVarint(dAtA, i, uint64(len(m.Message))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Message))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *GreetRequest) SizeVT() (n int) { if m == nil { return 0 @@ -239,7 +228,7 @@ func (m *GreetRequest) SizeVT() (n int) { _ = l l = len(m.Name) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -253,7 +242,7 @@ func (m *GreetReply) SizeVT() (n int) { _ = l l = len(m.Message) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -267,7 +256,7 @@ func (m *HttpGetRequest) SizeVT() (n int) { _ = l l = len(m.Url) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -281,7 +270,7 @@ func (m *HttpGetResponse) SizeVT() (n int) { _ = l l = len(m.Response) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -295,18 +284,12 @@ func (m *LogRequest) SizeVT() (n int) { _ = l l = len(m.Message) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -315,7 +298,7 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -343,7 +326,7 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -357,11 +340,11 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -370,12 +353,12 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -398,7 +381,7 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -426,7 +409,7 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -440,11 +423,11 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -453,12 +436,12 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -481,7 +464,7 @@ func (m *HttpGetRequest) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -509,7 +492,7 @@ func (m *HttpGetRequest) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -523,11 +506,11 @@ func (m *HttpGetRequest) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -536,12 +519,12 @@ func (m *HttpGetRequest) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -564,7 +547,7 @@ func (m *HttpGetResponse) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -592,7 +575,7 @@ func (m *HttpGetResponse) UnmarshalVT(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -605,11 +588,11 @@ func (m *HttpGetResponse) UnmarshalVT(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -621,12 +604,12 @@ func (m *HttpGetResponse) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -649,7 +632,7 @@ func (m *LogRequest) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -677,7 +660,7 @@ func (m *LogRequest) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -691,11 +674,11 @@ func (m *LogRequest) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -704,12 +687,12 @@ func (m *LogRequest) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -724,88 +707,3 @@ func (m *LogRequest) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/examples/known-types/known/known_vtproto.pb.go b/examples/known-types/known/known_vtproto.pb.go index 01fa15b..463f587 100644 --- a/examples/known-types/known/known_vtproto.pb.go +++ b/examples/known-types/known/known_vtproto.pb.go @@ -8,13 +8,13 @@ package known import ( fmt "fmt" + durationpb "github.com/knqyf263/go-plugin/types/known/durationpb" structpb "github.com/knqyf263/go-plugin/types/known/structpb" timestamppb "github.com/knqyf263/go-plugin/types/known/timestamppb" - proto "google.golang.org/protobuf/proto" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -55,68 +55,32 @@ func (m *DiffRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.End != nil { - if vtmsg, ok := interface{}(m.End).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.End) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*timestamppb.Timestamp)(m.End).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x1a } if m.Start != nil { - if vtmsg, ok := interface{}(m.Start).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.Start) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*timestamppb.Timestamp)(m.Start).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x12 } if m.Value != nil { - if vtmsg, ok := interface{}(m.Value).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.Value) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*structpb.Value)(m.Value).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0xa } @@ -154,41 +118,18 @@ func (m *DiffReply) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.Duration != nil { - if vtmsg, ok := interface{}(m.Duration).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.Duration) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*durationpb.Duration)(m.Duration).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *DiffRequest) SizeVT() (n int) { if m == nil { return 0 @@ -196,34 +137,16 @@ func (m *DiffRequest) SizeVT() (n int) { var l int _ = l if m.Value != nil { - if size, ok := interface{}(m.Value).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.Value) - } - n += 1 + l + sov(uint64(l)) + l = (*structpb.Value)(m.Value).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.Start != nil { - if size, ok := interface{}(m.Start).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.Start) - } - n += 1 + l + sov(uint64(l)) + l = (*timestamppb.Timestamp)(m.Start).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.End != nil { - if size, ok := interface{}(m.End).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.End) - } - n += 1 + l + sov(uint64(l)) + l = (*timestamppb.Timestamp)(m.End).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -236,25 +159,13 @@ func (m *DiffReply) SizeVT() (n int) { var l int _ = l if m.Duration != nil { - if size, ok := interface{}(m.Duration).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.Duration) - } - n += 1 + l + sov(uint64(l)) + l = (*durationpb.Duration)(m.Duration).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *DiffRequest) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -263,7 +174,7 @@ func (m *DiffRequest) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -291,7 +202,7 @@ func (m *DiffRequest) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -304,11 +215,11 @@ func (m *DiffRequest) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -316,16 +227,8 @@ func (m *DiffRequest) UnmarshalVT(dAtA []byte) error { if m.Value == nil { m.Value = &structpb.Value{} } - if unmarshal, ok := interface{}(m.Value).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.Value); err != nil { - return err - } + if err := (*structpb.Value)(m.Value).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 2: @@ -335,7 +238,7 @@ func (m *DiffRequest) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -348,11 +251,11 @@ func (m *DiffRequest) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -360,16 +263,8 @@ func (m *DiffRequest) UnmarshalVT(dAtA []byte) error { if m.Start == nil { m.Start = ×tamppb.Timestamp{} } - if unmarshal, ok := interface{}(m.Start).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.Start); err != nil { - return err - } + if err := (*timestamppb.Timestamp)(m.Start).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 3: @@ -379,7 +274,7 @@ func (m *DiffRequest) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -392,11 +287,11 @@ func (m *DiffRequest) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -404,26 +299,18 @@ func (m *DiffRequest) UnmarshalVT(dAtA []byte) error { if m.End == nil { m.End = ×tamppb.Timestamp{} } - if unmarshal, ok := interface{}(m.End).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.End); err != nil { - return err - } + if err := (*timestamppb.Timestamp)(m.End).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -446,7 +333,7 @@ func (m *DiffReply) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -474,7 +361,7 @@ func (m *DiffReply) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -487,11 +374,11 @@ func (m *DiffReply) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -499,26 +386,18 @@ func (m *DiffReply) UnmarshalVT(dAtA []byte) error { if m.Duration == nil { m.Duration = &durationpb.Duration{} } - if unmarshal, ok := interface{}(m.Duration).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.Duration); err != nil { - return err - } + if err := (*durationpb.Duration)(m.Duration).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -533,88 +412,3 @@ func (m *DiffReply) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/examples/wasi/cat/cat_vtproto.pb.go b/examples/wasi/cat/cat_vtproto.pb.go index 1256c98..63d189d 100644 --- a/examples/wasi/cat/cat_vtproto.pb.go +++ b/examples/wasi/cat/cat_vtproto.pb.go @@ -8,9 +8,9 @@ package cat import ( fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -53,7 +53,7 @@ func (m *FileCatRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.FilePath) > 0 { i -= len(m.FilePath) copy(dAtA[i:], m.FilePath) - i = encodeVarint(dAtA, i, uint64(len(m.FilePath))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.FilePath))) i-- dAtA[i] = 0xa } @@ -93,24 +93,13 @@ func (m *FileCatReply) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Content) > 0 { i -= len(m.Content) copy(dAtA[i:], m.Content) - i = encodeVarint(dAtA, i, uint64(len(m.Content))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Content))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *FileCatRequest) SizeVT() (n int) { if m == nil { return 0 @@ -119,7 +108,7 @@ func (m *FileCatRequest) SizeVT() (n int) { _ = l l = len(m.FilePath) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -133,18 +122,12 @@ func (m *FileCatReply) SizeVT() (n int) { _ = l l = len(m.Content) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *FileCatRequest) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -153,7 +136,7 @@ func (m *FileCatRequest) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -181,7 +164,7 @@ func (m *FileCatRequest) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -195,11 +178,11 @@ func (m *FileCatRequest) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -208,12 +191,12 @@ func (m *FileCatRequest) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -236,7 +219,7 @@ func (m *FileCatReply) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -264,7 +247,7 @@ func (m *FileCatReply) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -278,11 +261,11 @@ func (m *FileCatReply) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -291,12 +274,12 @@ func (m *FileCatReply) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -311,88 +294,3 @@ func (m *FileCatReply) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/gen/main.go b/gen/main.go index f783c40..096cadb 100644 --- a/gen/main.go +++ b/gen/main.go @@ -4,11 +4,14 @@ package gen import ( + "bytes" "fmt" "go/ast" + "go/format" "go/parser" "go/token" "math" + "path" "strconv" "strings" "unicode" @@ -102,25 +105,12 @@ func NewGenerator(plugin *protogen.Plugin) (*Generator, error) { return nil, err } - for _, f := range plugin.Files { - if !f.Generate { + // Replace google known types with custom types so that they can be used in Wasm. + for _, file := range plugin.Files { + if !file.Generate { continue } - - // Replace google known types with custom types so that they can be used in Wasm. - walkMessages(f.Messages, func(message *protogen.Message) { - for _, field := range message.Fields { - replaceImport(field.Message) - } - replaceImport(message) - }) - for _, svc := range f.Services { - for _, method := range svc.Methods { - walkMessages([]*protogen.Message{method.Input, method.Output}, func(message *protogen.Message) { - replaceImport(message) - }) - } - } + replaceImports(file) } return &Generator{ @@ -141,6 +131,23 @@ func replaceImport(m *protogen.Message) { } } +func replaceImports(file *protogen.File) { + walkMessages(file.Messages, func(message *protogen.Message) { + for _, field := range message.Fields { + replaceImport(field.Message) + } + replaceImport(message) + }) + + for _, svc := range file.Services { + for _, method := range svc.Methods { + walkMessages([]*protogen.Message{method.Input, method.Output}, func(message *protogen.Message) { + replaceImport(message) + }) + } + } +} + // GenerateFiles generates the contents of a .pb.go file. func (gg *Generator) GenerateFiles(file *protogen.File, opts Options) *protogen.GeneratedFile { f := gg.newFileInfo(file) @@ -195,7 +202,7 @@ func (gg *Generator) generateHeader(g *protogen.GeneratedFile, f *fileInfo) { genStandaloneComments(g, f, int32(genid.FileDescriptorProto_Package_field_number)) // TODO - //packageDoc := genPackageKnownComment(f) + // packageDoc := genPackageKnownComment(f) g.P("package ", f.GoPackageName) g.P() } @@ -905,3 +912,123 @@ func parseParam(comment string) (Parameter, error) { } return param, nil } + +func dedupeImports(src []byte) ([]byte, error) { + fset := token.NewFileSet() + file, err := parser.ParseFile(fset, "", src, parser.ParseComments) + if err != nil { + return nil, err + } + + type importInfo struct { + spec *ast.ImportSpec + name string + path string + } + + imports := make(map[string][]importInfo) + + for _, spec := range file.Imports { + importPath, err := strconv.Unquote(spec.Path.Value) + if err != nil { + return nil, err + } + + name := path.Base(importPath) + if spec.Name != nil { + name = spec.Name.Name + } + + imports[importPath] = append(imports[importPath], importInfo{ + spec: spec, + name: name, + path: importPath, + }) + } + + renames := make(map[string]string) + remove := make(map[*ast.ImportSpec]bool) + + for importPath, specs := range imports { + if len(specs) < 2 { + continue + } + + // Prefer the natural package name over aliases generated to + // disambiguate imports that used to have different paths. + preferred := path.Base(importPath) + canonical := specs[0] + + for _, spec := range specs { + if spec.name == preferred { + canonical = spec + break + } + } + + for _, spec := range specs { + if spec.spec == canonical.spec { + continue + } + + if spec.name != canonical.name { + renames[spec.name] = canonical.name + } + remove[spec.spec] = true + } + } + + if len(remove) == 0 { + return src, nil + } + + ast.Inspect(file, func(node ast.Node) bool { + selector, ok := node.(*ast.SelectorExpr) + if !ok { + return true + } + + ident, ok := selector.X.(*ast.Ident) + if !ok { + return true + } + + if name, ok := renames[ident.Name]; ok { + ident.Name = name + } + + return true + }) + + for _, decl := range file.Decls { + gen, ok := decl.(*ast.GenDecl) + if !ok || gen.Tok != token.IMPORT { + continue + } + + specs := gen.Specs[:0] + for _, spec := range gen.Specs { + importSpec, ok := spec.(*ast.ImportSpec) + if ok && remove[importSpec] { + continue + } + specs = append(specs, spec) + } + gen.Specs = specs + } + + importSpecs := file.Imports[:0] + for _, spec := range file.Imports { + if !remove[spec] { + importSpecs = append(importSpecs, spec) + } + } + file.Imports = importSpecs + + var buf bytes.Buffer + if err := format.Node(&buf, fset, file); err != nil { + return nil, err + } + + return buf.Bytes(), nil +} diff --git a/gen/vtproto.go b/gen/vtproto.go index 82ded4b..b455ae9 100644 --- a/gen/vtproto.go +++ b/gen/vtproto.go @@ -2,10 +2,20 @@ package gen import ( "bytes" + "go/ast" + "go/parser" + "go/token" + "path" + "sort" + "strconv" + "strings" + + vtgenerator "github.com/planetscale/vtprotobuf/generator" "google.golang.org/protobuf/compiler/protogen" - vtgenerator "github.com/planetscale/vtprotobuf/generator" // Confirme o import/alias utilizado no seu projeto ) +const knownTypesImportPrefix = "github.com/knqyf263/go-plugin/types/known/" + func (gg *Generator) generateVTFile(f *fileInfo) { // It is a bit tricky, but necessary for workaround. // We create a dummyPlugin in memory. @@ -16,6 +26,15 @@ func (gg *Generator) generateVTFile(f *fileInfo) { return } + for _, file := range dummyPlugin.Files { + replaceImports(file) + + if file.Desc.Path() == f.Desc.Path() && + file.Desc.Package() == "google.protobuf" { + makeLocal(file) + } + } + cfg := &vtgenerator.Config{} featureNames := []string{"marshal", "unmarshal", "size"} localVtGen, err := vtgenerator.NewGenerator(dummyPlugin, featureNames, cfg) @@ -39,6 +58,24 @@ func (gg *Generator) generateVTFile(f *fileInfo) { return } + vtContent = bytes.ReplaceAll( + vtContent, + []byte("github.com/planetscale/vtprotobuf/types/known/"), + []byte(knownTypesImportPrefix), + ) + + vtContent, err = rewriteKnownTypes(vtContent, dummyPlugin, f.GoImportPath) + if err != nil { + gg.plugin.Error(err) + return + } + + vtContent, err = dedupeImports(vtContent) + if err != nil { + gg.plugin.Error(err) + return + } + if idx := bytes.Index(vtContent, []byte("import ")); idx != -1 { vtContent = vtContent[idx:] } @@ -47,3 +84,268 @@ func (gg *Generator) generateVTFile(f *fileInfo) { gg.generateHeader(g, f) g.Write(vtContent) } + +func makeLocal(file *protogen.File) { + file.GoImportPath = "" + + var walk func([]*protogen.Message) + walk = func(messages []*protogen.Message) { + for _, message := range messages { + message.GoIdent.GoImportPath = "" + + for _, enum := range message.Enums { + enum.GoIdent.GoImportPath = "" + } + + for _, oneof := range message.Oneofs { + for _, field := range oneof.Fields { + field.GoIdent.GoImportPath = "" + } + } + + walk(message.Messages) + } + } + + for _, enum := range file.Enums { + enum.GoIdent.GoImportPath = "" + } + walk(file.Messages) +} + +func rewriteKnownTypes(src []byte, plugin *protogen.Plugin, localImportPath protogen.GoImportPath) ([]byte, error) { + known := collectKnownTypes(plugin) + if len(known) == 0 { + return src, nil + } + + fset := token.NewFileSet() + file, err := parser.ParseFile(fset, "", src, parser.ParseComments) + if err != nil { + return nil, err + } + + type replacement struct { + offset int + old string + new string + } + + replacements := make(map[token.Pos]replacement) + imports := make(map[string]string) + + add := func(ident *ast.Ident) { + goIdent, ok := known[ident.Name] + if !ok || + goIdent.GoImportPath == "" || + goIdent.GoImportPath == localImportPath { + return + } + + importPath := string(goIdent.GoImportPath) + importName := importNameForPath(file, importPath) + if importName == "" { + importName = path.Base(importPath) + imports[importName] = importPath + } + + replacements[ident.Pos()] = replacement{ + offset: fset.Position(ident.Pos()).Offset, + old: ident.Name, + new: importName + "." + ident.Name, + } + } + + var walkType func(ast.Expr) + walkType = func(expr ast.Expr) { + switch expr := expr.(type) { + case nil: + return + + case *ast.Ident: + add(expr) + + case *ast.ArrayType: + walkType(expr.Elt) + + case *ast.ChanType: + walkType(expr.Value) + + case *ast.Ellipsis: + walkType(expr.Elt) + + case *ast.FuncType: + walkFields(expr.TypeParams, walkType) + walkFields(expr.Params, walkType) + walkFields(expr.Results, walkType) + + case *ast.IndexExpr: + walkType(expr.X) + walkType(expr.Index) + + case *ast.IndexListExpr: + walkType(expr.X) + for _, index := range expr.Indices { + walkType(index) + } + + case *ast.InterfaceType: + walkFields(expr.Methods, walkType) + + case *ast.MapType: + walkType(expr.Key) + walkType(expr.Value) + + case *ast.ParenExpr: + walkType(expr.X) + + case *ast.SelectorExpr: + // Already qualified. + + case *ast.StarExpr: + walkType(expr.X) + + case *ast.StructType: + walkFields(expr.Fields, walkType) + } + } + + ast.Inspect(file, func(node ast.Node) bool { + switch node := node.(type) { + case *ast.Field: + walkType(node.Type) + + case *ast.TypeSpec: + walkType(node.Type) + + case *ast.ValueSpec: + walkType(node.Type) + + case *ast.CompositeLit: + walkType(node.Type) + + case *ast.TypeAssertExpr: + walkType(node.Type) + + case *ast.CallExpr: + // Type conversions generated by vtprotobuf, for example: + // + // (*Any)(m.Value) + // + walkType(node.Fun) + + // Allocations such as new(Any). + if ident, ok := node.Fun.(*ast.Ident); ok && + (ident.Name == "new" || ident.Name == "make") && + len(node.Args) != 0 { + walkType(node.Args[0]) + } + } + + return true + }) + + ordered := make([]replacement, 0, len(replacements)) + for _, replacement := range replacements { + ordered = append(ordered, replacement) + } + + // Work backwards so earlier offsets remain valid. + sort.Slice(ordered, func(i, j int) bool { + return ordered[i].offset > ordered[j].offset + }) + + for _, replacement := range ordered { + src = append( + src[:replacement.offset], + append( + []byte(replacement.new), + src[replacement.offset+len(replacement.old):]..., + )..., + ) + } + + for name, importPath := range imports { + src = addImport(src, name, importPath) + } + + return src, nil +} + +func walkFields(fields *ast.FieldList, walk func(ast.Expr)) { + if fields == nil { + return + } + + for _, field := range fields.List { + walk(field.Type) + } +} + +func collectKnownTypes(plugin *protogen.Plugin) map[string]protogen.GoIdent { + known := make(map[string]protogen.GoIdent) + + for _, file := range plugin.Files { + walkMessages(file.Messages, func(message *protogen.Message) { + addKnownType(known, message.GoIdent) + + for _, enum := range message.Enums { + addKnownType(known, enum.GoIdent) + } + + for _, oneof := range message.Oneofs { + for _, field := range oneof.Fields { + addKnownType(known, field.GoIdent) + } + } + }) + + for _, enum := range file.Enums { + addKnownType(known, enum.GoIdent) + } + } + + return known +} + +func addKnownType(known map[string]protogen.GoIdent, ident protogen.GoIdent) { + if !strings.HasPrefix(string(ident.GoImportPath), knownTypesImportPrefix) { + return + } + + known[ident.GoName] = ident +} + +func importNameForPath(file *ast.File, importPath string) string { + for _, spec := range file.Imports { + p, err := strconv.Unquote(spec.Path.Value) + if err != nil || p != importPath { + continue + } + + if spec.Name != nil { + if spec.Name.Name == "_" || spec.Name.Name == "." { + return "" + } + return spec.Name.Name + } + + return path.Base(importPath) + } + + return "" +} + +func addImport(src []byte, name, importPath string) []byte { + needle := []byte("import (\n") + index := bytes.Index(src, needle) + if index == -1 { + return src + } + + index += len(needle) + + line := []byte("\t" + name + " " + strconv.Quote(importPath) + "\n") + + return append(src[:index], append(line, src[index:]...)...) +} diff --git a/tests/fields/proto/fields_vtproto.pb.go b/tests/fields/proto/fields_vtproto.pb.go index d65af2a..5f1434e 100644 --- a/tests/fields/proto/fields_vtproto.pb.go +++ b/tests/fields/proto/fields_vtproto.pb.go @@ -9,10 +9,10 @@ package proto import ( binary "encoding/binary" fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" math "math" - bits "math/bits" ) const ( @@ -98,7 +98,7 @@ func (m *Request_Nested) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.A) > 0 { i -= len(m.A) copy(dAtA[i:], m.A) - i = encodeVarint(dAtA, i, uint64(len(m.A))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.A))) i-- dAtA[i] = 0xa } @@ -136,7 +136,7 @@ func (m *Request) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.S != 0 { - i = encodeVarint(dAtA, i, uint64(m.S)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.S)) i-- dAtA[i] = 0x1 i-- @@ -148,7 +148,7 @@ func (m *Request) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x1 i-- @@ -163,15 +163,15 @@ func (m *Request) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x12 i -= len(k) copy(dAtA[i:], k) - i = encodeVarint(dAtA, i, uint64(len(k))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(k))) i-- dAtA[i] = 0xa - i = encodeVarint(dAtA, i, uint64(baseI-i)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) i-- dAtA[i] = 0x1 i-- @@ -182,7 +182,7 @@ func (m *Request) MarshalToSizedBufferVT(dAtA []byte) (int, error) { for iNdEx := len(m.P) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.P[iNdEx]) copy(dAtA[i:], m.P[iNdEx]) - i = encodeVarint(dAtA, i, uint64(len(m.P[iNdEx]))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.P[iNdEx]))) i-- dAtA[i] = 0x1 i-- @@ -192,14 +192,14 @@ func (m *Request) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.O) > 0 { i -= len(m.O) copy(dAtA[i:], m.O) - i = encodeVarint(dAtA, i, uint64(len(m.O))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.O))) i-- dAtA[i] = 0x7a } if len(m.N) > 0 { i -= len(m.N) copy(dAtA[i:], m.N) - i = encodeVarint(dAtA, i, uint64(len(m.N))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.N))) i-- dAtA[i] = 0x72 } @@ -238,32 +238,32 @@ func (m *Request) MarshalToSizedBufferVT(dAtA []byte) (int, error) { dAtA[i] = 0x4d } if m.H != 0 { - i = encodeVarint(dAtA, i, uint64((uint64(m.H)<<1)^uint64((m.H>>63)))) + i = protohelpers.EncodeVarint(dAtA, i, uint64((uint64(m.H)<<1)^uint64((m.H>>63)))) i-- dAtA[i] = 0x40 } if m.G != 0 { - i = encodeVarint(dAtA, i, uint64((uint32(m.G)<<1)^uint32((m.G>>31)))) + i = protohelpers.EncodeVarint(dAtA, i, uint64((uint32(m.G)<<1)^uint32((m.G>>31)))) i-- dAtA[i] = 0x38 } if m.F != 0 { - i = encodeVarint(dAtA, i, uint64(m.F)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.F)) i-- dAtA[i] = 0x30 } if m.E != 0 { - i = encodeVarint(dAtA, i, uint64(m.E)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.E)) i-- dAtA[i] = 0x28 } if m.D != 0 { - i = encodeVarint(dAtA, i, uint64(m.D)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.D)) i-- dAtA[i] = 0x20 } if m.C != 0 { - i = encodeVarint(dAtA, i, uint64(m.C)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.C)) i-- dAtA[i] = 0x18 } @@ -313,7 +313,7 @@ func (m *IntValue) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.A != 0 { - i = encodeVarint(dAtA, i, uint64(m.A)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.A)) i-- dAtA[i] = 0x8 } @@ -353,7 +353,7 @@ func (m *Response_Nested) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.A) > 0 { i -= len(m.A) copy(dAtA[i:], m.A) - i = encodeVarint(dAtA, i, uint64(len(m.A))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.A))) i-- dAtA[i] = 0xa } @@ -391,7 +391,7 @@ func (m *Response) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.S != 0 { - i = encodeVarint(dAtA, i, uint64(m.S)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.S)) i-- dAtA[i] = 0x1 i-- @@ -403,7 +403,7 @@ func (m *Response) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x1 i-- @@ -418,15 +418,15 @@ func (m *Response) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x12 i -= len(k) copy(dAtA[i:], k) - i = encodeVarint(dAtA, i, uint64(len(k))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(k))) i-- dAtA[i] = 0xa - i = encodeVarint(dAtA, i, uint64(baseI-i)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) i-- dAtA[i] = 0x1 i-- @@ -437,7 +437,7 @@ func (m *Response) MarshalToSizedBufferVT(dAtA []byte) (int, error) { for iNdEx := len(m.P) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.P[iNdEx]) copy(dAtA[i:], m.P[iNdEx]) - i = encodeVarint(dAtA, i, uint64(len(m.P[iNdEx]))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.P[iNdEx]))) i-- dAtA[i] = 0x1 i-- @@ -447,14 +447,14 @@ func (m *Response) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.O) > 0 { i -= len(m.O) copy(dAtA[i:], m.O) - i = encodeVarint(dAtA, i, uint64(len(m.O))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.O))) i-- dAtA[i] = 0x7a } if len(m.N) > 0 { i -= len(m.N) copy(dAtA[i:], m.N) - i = encodeVarint(dAtA, i, uint64(len(m.N))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.N))) i-- dAtA[i] = 0x72 } @@ -493,32 +493,32 @@ func (m *Response) MarshalToSizedBufferVT(dAtA []byte) (int, error) { dAtA[i] = 0x4d } if m.H != 0 { - i = encodeVarint(dAtA, i, uint64((uint64(m.H)<<1)^uint64((m.H>>63)))) + i = protohelpers.EncodeVarint(dAtA, i, uint64((uint64(m.H)<<1)^uint64((m.H>>63)))) i-- dAtA[i] = 0x40 } if m.G != 0 { - i = encodeVarint(dAtA, i, uint64((uint32(m.G)<<1)^uint32((m.G>>31)))) + i = protohelpers.EncodeVarint(dAtA, i, uint64((uint32(m.G)<<1)^uint32((m.G>>31)))) i-- dAtA[i] = 0x38 } if m.F != 0 { - i = encodeVarint(dAtA, i, uint64(m.F)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.F)) i-- dAtA[i] = 0x30 } if m.E != 0 { - i = encodeVarint(dAtA, i, uint64(m.E)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.E)) i-- dAtA[i] = 0x28 } if m.D != 0 { - i = encodeVarint(dAtA, i, uint64(m.D)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.D)) i-- dAtA[i] = 0x20 } if m.C != 0 { - i = encodeVarint(dAtA, i, uint64(m.C)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.C)) i-- dAtA[i] = 0x18 } @@ -570,24 +570,13 @@ func (m *ErrorRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.ErrText) > 0 { i -= len(m.ErrText) copy(dAtA[i:], m.ErrText) - i = encodeVarint(dAtA, i, uint64(len(m.ErrText))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.ErrText))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *TestEmptyInputResponse) SizeVT() (n int) { if m == nil { return 0 @@ -609,7 +598,7 @@ func (m *Request_Nested) SizeVT() (n int) { _ = l l = len(m.A) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -628,22 +617,22 @@ func (m *Request) SizeVT() (n int) { n += 5 } if m.C != 0 { - n += 1 + sov(uint64(m.C)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.C)) } if m.D != 0 { - n += 1 + sov(uint64(m.D)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.D)) } if m.E != 0 { - n += 1 + sov(uint64(m.E)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.E)) } if m.F != 0 { - n += 1 + sov(uint64(m.F)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.F)) } if m.G != 0 { - n += 1 + soz(uint64(m.G)) + n += 1 + protohelpers.SizeOfZigzag(uint64(m.G)) } if m.H != 0 { - n += 1 + soz(uint64(m.H)) + n += 1 + protohelpers.SizeOfZigzag(uint64(m.H)) } if m.I != 0 { n += 5 @@ -662,16 +651,16 @@ func (m *Request) SizeVT() (n int) { } l = len(m.N) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } l = len(m.O) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if len(m.P) > 0 { for _, s := range m.P { l = len(s) - n += 2 + l + sov(uint64(l)) + n += 2 + l + protohelpers.SizeOfVarint(uint64(l)) } } if len(m.Q) > 0 { @@ -682,17 +671,17 @@ func (m *Request) SizeVT() (n int) { if v != nil { l = v.SizeVT() } - l += 1 + sov(uint64(l)) - mapEntrySize := 1 + len(k) + sov(uint64(len(k))) + l - n += mapEntrySize + 2 + sov(uint64(mapEntrySize)) + l += 1 + protohelpers.SizeOfVarint(uint64(l)) + mapEntrySize := 1 + len(k) + protohelpers.SizeOfVarint(uint64(len(k))) + l + n += mapEntrySize + 2 + protohelpers.SizeOfVarint(uint64(mapEntrySize)) } } if m.R != nil { l = m.R.SizeVT() - n += 2 + l + sov(uint64(l)) + n += 2 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.S != 0 { - n += 2 + sov(uint64(m.S)) + n += 2 + protohelpers.SizeOfVarint(uint64(m.S)) } n += len(m.unknownFields) return n @@ -705,7 +694,7 @@ func (m *IntValue) SizeVT() (n int) { var l int _ = l if m.A != 0 { - n += 1 + sov(uint64(m.A)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.A)) } n += len(m.unknownFields) return n @@ -719,7 +708,7 @@ func (m *Response_Nested) SizeVT() (n int) { _ = l l = len(m.A) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -738,22 +727,22 @@ func (m *Response) SizeVT() (n int) { n += 5 } if m.C != 0 { - n += 1 + sov(uint64(m.C)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.C)) } if m.D != 0 { - n += 1 + sov(uint64(m.D)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.D)) } if m.E != 0 { - n += 1 + sov(uint64(m.E)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.E)) } if m.F != 0 { - n += 1 + sov(uint64(m.F)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.F)) } if m.G != 0 { - n += 1 + soz(uint64(m.G)) + n += 1 + protohelpers.SizeOfZigzag(uint64(m.G)) } if m.H != 0 { - n += 1 + soz(uint64(m.H)) + n += 1 + protohelpers.SizeOfZigzag(uint64(m.H)) } if m.I != 0 { n += 5 @@ -772,16 +761,16 @@ func (m *Response) SizeVT() (n int) { } l = len(m.N) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } l = len(m.O) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if len(m.P) > 0 { for _, s := range m.P { l = len(s) - n += 2 + l + sov(uint64(l)) + n += 2 + l + protohelpers.SizeOfVarint(uint64(l)) } } if len(m.Q) > 0 { @@ -792,17 +781,17 @@ func (m *Response) SizeVT() (n int) { if v != nil { l = v.SizeVT() } - l += 1 + sov(uint64(l)) - mapEntrySize := 1 + len(k) + sov(uint64(len(k))) + l - n += mapEntrySize + 2 + sov(uint64(mapEntrySize)) + l += 1 + protohelpers.SizeOfVarint(uint64(l)) + mapEntrySize := 1 + len(k) + protohelpers.SizeOfVarint(uint64(len(k))) + l + n += mapEntrySize + 2 + protohelpers.SizeOfVarint(uint64(mapEntrySize)) } } if m.R != nil { l = m.R.SizeVT() - n += 2 + l + sov(uint64(l)) + n += 2 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.S != 0 { - n += 2 + sov(uint64(m.S)) + n += 2 + protohelpers.SizeOfVarint(uint64(m.S)) } n += len(m.unknownFields) return n @@ -816,18 +805,12 @@ func (m *ErrorRequest) SizeVT() (n int) { _ = l l = len(m.ErrText) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *TestEmptyInputResponse) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -836,7 +819,7 @@ func (m *TestEmptyInputResponse) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -864,7 +847,7 @@ func (m *TestEmptyInputResponse) UnmarshalVT(dAtA []byte) error { var v int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -879,12 +862,12 @@ func (m *TestEmptyInputResponse) UnmarshalVT(dAtA []byte) error { m.Ok = bool(v != 0) default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -907,7 +890,7 @@ func (m *Request_Nested) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -935,7 +918,7 @@ func (m *Request_Nested) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -949,11 +932,11 @@ func (m *Request_Nested) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -962,12 +945,12 @@ func (m *Request_Nested) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -990,7 +973,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1040,7 +1023,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { m.C = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1059,7 +1042,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { m.D = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1078,7 +1061,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { m.E = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1097,7 +1080,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { m.F = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1116,7 +1099,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var v int32 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1137,7 +1120,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var v uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1198,7 +1181,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var v int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1218,7 +1201,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1232,11 +1215,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1250,7 +1233,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1263,11 +1246,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1284,7 +1267,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1298,11 +1281,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1316,7 +1299,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1329,11 +1312,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1348,7 +1331,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1365,7 +1348,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var stringLenmapkey uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1379,11 +1362,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } intStringLenmapkey := int(stringLenmapkey) if intStringLenmapkey < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postStringIndexmapkey := iNdEx + intStringLenmapkey if postStringIndexmapkey < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postStringIndexmapkey > l { return io.ErrUnexpectedEOF @@ -1394,7 +1377,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var mapmsglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1407,11 +1390,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if mapmsglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postmsgIndex := iNdEx + mapmsglen if postmsgIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postmsgIndex > l { return io.ErrUnexpectedEOF @@ -1423,12 +1406,12 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { iNdEx = postmsgIndex } else { iNdEx = entryPreIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > postIndex { return io.ErrUnexpectedEOF @@ -1445,7 +1428,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1458,11 +1441,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1481,7 +1464,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { m.S = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1495,12 +1478,12 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1523,7 +1506,7 @@ func (m *IntValue) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1551,7 +1534,7 @@ func (m *IntValue) UnmarshalVT(dAtA []byte) error { m.A = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1565,12 +1548,12 @@ func (m *IntValue) UnmarshalVT(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1593,7 +1576,7 @@ func (m *Response_Nested) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1621,7 +1604,7 @@ func (m *Response_Nested) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1635,11 +1618,11 @@ func (m *Response_Nested) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1648,12 +1631,12 @@ func (m *Response_Nested) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1676,7 +1659,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1726,7 +1709,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { m.C = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1745,7 +1728,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { m.D = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1764,7 +1747,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { m.E = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1783,7 +1766,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { m.F = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1802,7 +1785,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var v int32 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1823,7 +1806,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var v uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1884,7 +1867,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var v int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1904,7 +1887,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1918,11 +1901,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1936,7 +1919,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1949,11 +1932,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1970,7 +1953,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1984,11 +1967,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -2002,7 +1985,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -2015,11 +1998,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -2034,7 +2017,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -2051,7 +2034,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var stringLenmapkey uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -2065,11 +2048,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } intStringLenmapkey := int(stringLenmapkey) if intStringLenmapkey < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postStringIndexmapkey := iNdEx + intStringLenmapkey if postStringIndexmapkey < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postStringIndexmapkey > l { return io.ErrUnexpectedEOF @@ -2080,7 +2063,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var mapmsglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -2093,11 +2076,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if mapmsglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postmsgIndex := iNdEx + mapmsglen if postmsgIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postmsgIndex > l { return io.ErrUnexpectedEOF @@ -2109,12 +2092,12 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { iNdEx = postmsgIndex } else { iNdEx = entryPreIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > postIndex { return io.ErrUnexpectedEOF @@ -2131,7 +2114,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -2144,11 +2127,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -2167,7 +2150,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { m.S = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -2181,12 +2164,12 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -2209,7 +2192,7 @@ func (m *ErrorRequest) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -2237,7 +2220,7 @@ func (m *ErrorRequest) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -2251,11 +2234,11 @@ func (m *ErrorRequest) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -2264,12 +2247,12 @@ func (m *ErrorRequest) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -2284,88 +2267,3 @@ func (m *ErrorRequest) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/tests/host-functions/proto/host_vtproto.pb.go b/tests/host-functions/proto/host_vtproto.pb.go index 9d00d10..7c57e8b 100644 --- a/tests/host-functions/proto/host_vtproto.pb.go +++ b/tests/host-functions/proto/host_vtproto.pb.go @@ -8,9 +8,9 @@ package proto import ( fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -53,7 +53,7 @@ func (m *GreetRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Name) > 0 { i -= len(m.Name) copy(dAtA[i:], m.Name) - i = encodeVarint(dAtA, i, uint64(len(m.Name))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Name))) i-- dAtA[i] = 0xa } @@ -93,7 +93,7 @@ func (m *GreetReply) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Message) > 0 { i -= len(m.Message) copy(dAtA[i:], m.Message) - i = encodeVarint(dAtA, i, uint64(len(m.Message))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Message))) i-- dAtA[i] = 0xa } @@ -133,7 +133,7 @@ func (m *ParseJsonRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Content) > 0 { i -= len(m.Content) copy(dAtA[i:], m.Content) - i = encodeVarint(dAtA, i, uint64(len(m.Content))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Content))) i-- dAtA[i] = 0xa } @@ -176,7 +176,7 @@ func (m *ParseJsonResponse) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0xa } @@ -214,31 +214,20 @@ func (m *Person) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.Age != 0 { - i = encodeVarint(dAtA, i, uint64(m.Age)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Age)) i-- dAtA[i] = 0x10 } if len(m.Name) > 0 { i -= len(m.Name) copy(dAtA[i:], m.Name) - i = encodeVarint(dAtA, i, uint64(len(m.Name))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Name))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *GreetRequest) SizeVT() (n int) { if m == nil { return 0 @@ -247,7 +236,7 @@ func (m *GreetRequest) SizeVT() (n int) { _ = l l = len(m.Name) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -261,7 +250,7 @@ func (m *GreetReply) SizeVT() (n int) { _ = l l = len(m.Message) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -275,7 +264,7 @@ func (m *ParseJsonRequest) SizeVT() (n int) { _ = l l = len(m.Content) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -289,7 +278,7 @@ func (m *ParseJsonResponse) SizeVT() (n int) { _ = l if m.Response != nil { l = m.Response.SizeVT() - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -303,21 +292,15 @@ func (m *Person) SizeVT() (n int) { _ = l l = len(m.Name) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.Age != 0 { - n += 1 + sov(uint64(m.Age)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Age)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -326,7 +309,7 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -354,7 +337,7 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -368,11 +351,11 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -381,12 +364,12 @@ func (m *GreetRequest) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -409,7 +392,7 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -437,7 +420,7 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -451,11 +434,11 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -464,12 +447,12 @@ func (m *GreetReply) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -492,7 +475,7 @@ func (m *ParseJsonRequest) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -520,7 +503,7 @@ func (m *ParseJsonRequest) UnmarshalVT(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -533,11 +516,11 @@ func (m *ParseJsonRequest) UnmarshalVT(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -549,12 +532,12 @@ func (m *ParseJsonRequest) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -577,7 +560,7 @@ func (m *ParseJsonResponse) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -605,7 +588,7 @@ func (m *ParseJsonResponse) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -618,11 +601,11 @@ func (m *ParseJsonResponse) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -636,12 +619,12 @@ func (m *ParseJsonResponse) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -664,7 +647,7 @@ func (m *Person) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -692,7 +675,7 @@ func (m *Person) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -706,11 +689,11 @@ func (m *Person) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -724,7 +707,7 @@ func (m *Person) UnmarshalVT(dAtA []byte) error { m.Age = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -738,12 +721,12 @@ func (m *Person) UnmarshalVT(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -758,88 +741,3 @@ func (m *Person) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/tests/import/proto/bar/bar_vtproto.pb.go b/tests/import/proto/bar/bar_vtproto.pb.go index 1fd0829..2d73f6f 100644 --- a/tests/import/proto/bar/bar_vtproto.pb.go +++ b/tests/import/proto/bar/bar_vtproto.pb.go @@ -8,9 +8,9 @@ package bar import ( fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -53,7 +53,7 @@ func (m *Request) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.A) > 0 { i -= len(m.A) copy(dAtA[i:], m.A) - i = encodeVarint(dAtA, i, uint64(len(m.A))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.A))) i-- dAtA[i] = 0xa } @@ -93,24 +93,13 @@ func (m *Reply) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.A) > 0 { i -= len(m.A) copy(dAtA[i:], m.A) - i = encodeVarint(dAtA, i, uint64(len(m.A))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.A))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *Request) SizeVT() (n int) { if m == nil { return 0 @@ -119,7 +108,7 @@ func (m *Request) SizeVT() (n int) { _ = l l = len(m.A) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -133,18 +122,12 @@ func (m *Reply) SizeVT() (n int) { _ = l l = len(m.A) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *Request) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -153,7 +136,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -181,7 +164,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -195,11 +178,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -208,12 +191,12 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -236,7 +219,7 @@ func (m *Reply) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -264,7 +247,7 @@ func (m *Reply) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -278,11 +261,11 @@ func (m *Reply) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -291,12 +274,12 @@ func (m *Reply) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -311,88 +294,3 @@ func (m *Reply) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/tests/import/proto/foo/foo_vtproto.pb.go b/tests/import/proto/foo/foo_vtproto.pb.go index dedbb24..f065032 100644 --- a/tests/import/proto/foo/foo_vtproto.pb.go +++ b/tests/import/proto/foo/foo_vtproto.pb.go @@ -8,9 +8,9 @@ package foo import ( fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -53,24 +53,13 @@ func (m *Request) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.A) > 0 { i -= len(m.A) copy(dAtA[i:], m.A) - i = encodeVarint(dAtA, i, uint64(len(m.A))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.A))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *Request) SizeVT() (n int) { if m == nil { return 0 @@ -79,18 +68,12 @@ func (m *Request) SizeVT() (n int) { _ = l l = len(m.A) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *Request) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -99,7 +82,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -127,7 +110,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -141,11 +124,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -154,12 +137,12 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -174,88 +157,3 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/tests/well-known/proto/known_vtproto.pb.go b/tests/well-known/proto/known_vtproto.pb.go index cb26fb8..4b1ff89 100644 --- a/tests/well-known/proto/known_vtproto.pb.go +++ b/tests/well-known/proto/known_vtproto.pb.go @@ -8,14 +8,14 @@ package proto import ( fmt "fmt" + durationpb "github.com/knqyf263/go-plugin/types/known/durationpb" structpb "github.com/knqyf263/go-plugin/types/known/structpb" timestamppb "github.com/knqyf263/go-plugin/types/known/timestamppb" wrapperspb "github.com/knqyf263/go-plugin/types/known/wrapperspb" - proto "google.golang.org/protobuf/proto" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -56,266 +56,122 @@ func (m *Request) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.L != nil { - if vtmsg, ok := interface{}(m.L).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.L) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.UInt64Value)(m.L).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x62 } if m.K != nil { - if vtmsg, ok := interface{}(m.K).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.K) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.UInt32Value)(m.K).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x5a } if m.J != nil { - if vtmsg, ok := interface{}(m.J).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.J) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.StringValue)(m.J).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x52 } if m.I != nil { - if vtmsg, ok := interface{}(m.I).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.I) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.Int64Value)(m.I).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x4a } if m.H != nil { - if vtmsg, ok := interface{}(m.H).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.H) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.Int32Value)(m.H).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x42 } if m.G != nil { - if vtmsg, ok := interface{}(m.G).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.G) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.FloatValue)(m.G).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x3a } if m.F != nil { - if vtmsg, ok := interface{}(m.F).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.F) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.DoubleValue)(m.F).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x32 } if m.E != nil { - if vtmsg, ok := interface{}(m.E).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.E) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.BytesValue)(m.E).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x2a } if m.D != nil { - if vtmsg, ok := interface{}(m.D).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.D) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.BoolValue)(m.D).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x22 } if m.C != nil { - if vtmsg, ok := interface{}(m.C).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.C) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*structpb.Value)(m.C).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x1a } if m.B != nil { - if vtmsg, ok := interface{}(m.B).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.B) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*timestamppb.Timestamp)(m.B).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x12 } if m.A != nil { - if vtmsg, ok := interface{}(m.A).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.A) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*durationpb.Duration)(m.A).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0xa } @@ -353,283 +209,128 @@ func (m *Response) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.L != nil { - if vtmsg, ok := interface{}(m.L).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.L) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.UInt64Value)(m.L).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x62 } if m.K != nil { - if vtmsg, ok := interface{}(m.K).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.K) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.UInt32Value)(m.K).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x5a } if m.J != nil { - if vtmsg, ok := interface{}(m.J).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.J) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.StringValue)(m.J).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x52 } if m.I != nil { - if vtmsg, ok := interface{}(m.I).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.I) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.Int64Value)(m.I).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x4a } if m.H != nil { - if vtmsg, ok := interface{}(m.H).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.H) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.Int32Value)(m.H).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x42 } if m.G != nil { - if vtmsg, ok := interface{}(m.G).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.G) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.FloatValue)(m.G).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x3a } if m.F != nil { - if vtmsg, ok := interface{}(m.F).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.F) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.DoubleValue)(m.F).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x32 } if m.E != nil { - if vtmsg, ok := interface{}(m.E).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.E) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.BytesValue)(m.E).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x2a } if m.D != nil { - if vtmsg, ok := interface{}(m.D).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.D) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*wrapperspb.BoolValue)(m.D).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x22 } if m.C != nil { - if vtmsg, ok := interface{}(m.C).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.C) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*structpb.Value)(m.C).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x1a } if m.B != nil { - if vtmsg, ok := interface{}(m.B).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.B) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*timestamppb.Timestamp)(m.B).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x12 } if m.A != nil { - if vtmsg, ok := interface{}(m.A).(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarint(dAtA, i, uint64(size)) - } else { - encoded, err := proto.Marshal(m.A) - if err != nil { - return 0, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = encodeVarint(dAtA, i, uint64(len(encoded))) + size, err := (*durationpb.Duration)(m.A).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *Request) SizeVT() (n int) { if m == nil { return 0 @@ -637,124 +338,52 @@ func (m *Request) SizeVT() (n int) { var l int _ = l if m.A != nil { - if size, ok := interface{}(m.A).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.A) - } - n += 1 + l + sov(uint64(l)) + l = (*durationpb.Duration)(m.A).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.B != nil { - if size, ok := interface{}(m.B).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.B) - } - n += 1 + l + sov(uint64(l)) + l = (*timestamppb.Timestamp)(m.B).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.C != nil { - if size, ok := interface{}(m.C).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.C) - } - n += 1 + l + sov(uint64(l)) + l = (*structpb.Value)(m.C).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.D != nil { - if size, ok := interface{}(m.D).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.D) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.BoolValue)(m.D).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.E != nil { - if size, ok := interface{}(m.E).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.E) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.BytesValue)(m.E).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.F != nil { - if size, ok := interface{}(m.F).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.F) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.DoubleValue)(m.F).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.G != nil { - if size, ok := interface{}(m.G).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.G) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.FloatValue)(m.G).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.H != nil { - if size, ok := interface{}(m.H).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.H) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.Int32Value)(m.H).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.I != nil { - if size, ok := interface{}(m.I).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.I) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.Int64Value)(m.I).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.J != nil { - if size, ok := interface{}(m.J).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.J) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.StringValue)(m.J).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.K != nil { - if size, ok := interface{}(m.K).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.K) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.UInt32Value)(m.K).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.L != nil { - if size, ok := interface{}(m.L).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.L) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.UInt64Value)(m.L).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -767,135 +396,57 @@ func (m *Response) SizeVT() (n int) { var l int _ = l if m.A != nil { - if size, ok := interface{}(m.A).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.A) - } - n += 1 + l + sov(uint64(l)) + l = (*durationpb.Duration)(m.A).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.B != nil { - if size, ok := interface{}(m.B).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.B) - } - n += 1 + l + sov(uint64(l)) + l = (*timestamppb.Timestamp)(m.B).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.C != nil { - if size, ok := interface{}(m.C).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.C) - } - n += 1 + l + sov(uint64(l)) + l = (*structpb.Value)(m.C).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.D != nil { - if size, ok := interface{}(m.D).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.D) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.BoolValue)(m.D).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.E != nil { - if size, ok := interface{}(m.E).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.E) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.BytesValue)(m.E).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.F != nil { - if size, ok := interface{}(m.F).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.F) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.DoubleValue)(m.F).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.G != nil { - if size, ok := interface{}(m.G).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.G) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.FloatValue)(m.G).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.H != nil { - if size, ok := interface{}(m.H).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.H) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.Int32Value)(m.H).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.I != nil { - if size, ok := interface{}(m.I).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.I) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.Int64Value)(m.I).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.J != nil { - if size, ok := interface{}(m.J).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.J) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.StringValue)(m.J).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.K != nil { - if size, ok := interface{}(m.K).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.K) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.UInt32Value)(m.K).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.L != nil { - if size, ok := interface{}(m.L).(interface { - SizeVT() int - }); ok { - l = size.SizeVT() - } else { - l = proto.Size(m.L) - } - n += 1 + l + sov(uint64(l)) + l = (*wrapperspb.UInt64Value)(m.L).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *Request) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -904,7 +455,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -932,7 +483,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -945,11 +496,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -957,16 +508,8 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { if m.A == nil { m.A = &durationpb.Duration{} } - if unmarshal, ok := interface{}(m.A).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.A); err != nil { - return err - } + if err := (*durationpb.Duration)(m.A).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 2: @@ -976,7 +519,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -989,11 +532,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1001,16 +544,8 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { if m.B == nil { m.B = ×tamppb.Timestamp{} } - if unmarshal, ok := interface{}(m.B).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.B); err != nil { - return err - } + if err := (*timestamppb.Timestamp)(m.B).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 3: @@ -1020,7 +555,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1033,11 +568,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1045,16 +580,8 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { if m.C == nil { m.C = &structpb.Value{} } - if unmarshal, ok := interface{}(m.C).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.C); err != nil { - return err - } + if err := (*structpb.Value)(m.C).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 4: @@ -1064,7 +591,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1077,11 +604,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1089,16 +616,8 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { if m.D == nil { m.D = &wrapperspb.BoolValue{} } - if unmarshal, ok := interface{}(m.D).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.D); err != nil { - return err - } + if err := (*wrapperspb.BoolValue)(m.D).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 5: @@ -1108,7 +627,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1121,11 +640,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1133,16 +652,8 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { if m.E == nil { m.E = &wrapperspb.BytesValue{} } - if unmarshal, ok := interface{}(m.E).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.E); err != nil { - return err - } + if err := (*wrapperspb.BytesValue)(m.E).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 6: @@ -1152,7 +663,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1165,11 +676,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1177,16 +688,8 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { if m.F == nil { m.F = &wrapperspb.DoubleValue{} } - if unmarshal, ok := interface{}(m.F).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.F); err != nil { - return err - } + if err := (*wrapperspb.DoubleValue)(m.F).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 7: @@ -1196,7 +699,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1209,11 +712,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1221,16 +724,8 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { if m.G == nil { m.G = &wrapperspb.FloatValue{} } - if unmarshal, ok := interface{}(m.G).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.G); err != nil { - return err - } + if err := (*wrapperspb.FloatValue)(m.G).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 8: @@ -1240,7 +735,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1253,11 +748,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1265,16 +760,8 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { if m.H == nil { m.H = &wrapperspb.Int32Value{} } - if unmarshal, ok := interface{}(m.H).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.H); err != nil { - return err - } + if err := (*wrapperspb.Int32Value)(m.H).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 9: @@ -1284,7 +771,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1297,11 +784,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1309,16 +796,8 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { if m.I == nil { m.I = &wrapperspb.Int64Value{} } - if unmarshal, ok := interface{}(m.I).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.I); err != nil { - return err - } + if err := (*wrapperspb.Int64Value)(m.I).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 10: @@ -1328,7 +807,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1341,11 +820,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1353,16 +832,8 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { if m.J == nil { m.J = &wrapperspb.StringValue{} } - if unmarshal, ok := interface{}(m.J).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.J); err != nil { - return err - } + if err := (*wrapperspb.StringValue)(m.J).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 11: @@ -1372,7 +843,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1385,11 +856,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1397,16 +868,8 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { if m.K == nil { m.K = &wrapperspb.UInt32Value{} } - if unmarshal, ok := interface{}(m.K).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.K); err != nil { - return err - } + if err := (*wrapperspb.UInt32Value)(m.K).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 12: @@ -1416,7 +879,7 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1429,11 +892,11 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1441,26 +904,18 @@ func (m *Request) UnmarshalVT(dAtA []byte) error { if m.L == nil { m.L = &wrapperspb.UInt64Value{} } - if unmarshal, ok := interface{}(m.L).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.L); err != nil { - return err - } + if err := (*wrapperspb.UInt64Value)(m.L).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1483,7 +938,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1511,7 +966,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1524,11 +979,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1536,16 +991,8 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { if m.A == nil { m.A = &durationpb.Duration{} } - if unmarshal, ok := interface{}(m.A).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.A); err != nil { - return err - } + if err := (*durationpb.Duration)(m.A).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 2: @@ -1555,7 +1002,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1568,11 +1015,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1580,16 +1027,8 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { if m.B == nil { m.B = ×tamppb.Timestamp{} } - if unmarshal, ok := interface{}(m.B).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.B); err != nil { - return err - } + if err := (*timestamppb.Timestamp)(m.B).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 3: @@ -1599,7 +1038,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1612,11 +1051,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1624,16 +1063,8 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { if m.C == nil { m.C = &structpb.Value{} } - if unmarshal, ok := interface{}(m.C).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.C); err != nil { - return err - } + if err := (*structpb.Value)(m.C).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 4: @@ -1643,7 +1074,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1656,11 +1087,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1668,16 +1099,8 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { if m.D == nil { m.D = &wrapperspb.BoolValue{} } - if unmarshal, ok := interface{}(m.D).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.D); err != nil { - return err - } + if err := (*wrapperspb.BoolValue)(m.D).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 5: @@ -1687,7 +1110,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1700,11 +1123,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1712,16 +1135,8 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { if m.E == nil { m.E = &wrapperspb.BytesValue{} } - if unmarshal, ok := interface{}(m.E).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.E); err != nil { - return err - } + if err := (*wrapperspb.BytesValue)(m.E).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 6: @@ -1731,7 +1146,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1744,11 +1159,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1756,16 +1171,8 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { if m.F == nil { m.F = &wrapperspb.DoubleValue{} } - if unmarshal, ok := interface{}(m.F).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.F); err != nil { - return err - } + if err := (*wrapperspb.DoubleValue)(m.F).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 7: @@ -1775,7 +1182,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1788,11 +1195,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1800,16 +1207,8 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { if m.G == nil { m.G = &wrapperspb.FloatValue{} } - if unmarshal, ok := interface{}(m.G).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.G); err != nil { - return err - } + if err := (*wrapperspb.FloatValue)(m.G).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 8: @@ -1819,7 +1218,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1832,11 +1231,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1844,16 +1243,8 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { if m.H == nil { m.H = &wrapperspb.Int32Value{} } - if unmarshal, ok := interface{}(m.H).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.H); err != nil { - return err - } + if err := (*wrapperspb.Int32Value)(m.H).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 9: @@ -1863,7 +1254,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1876,11 +1267,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1888,16 +1279,8 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { if m.I == nil { m.I = &wrapperspb.Int64Value{} } - if unmarshal, ok := interface{}(m.I).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.I); err != nil { - return err - } + if err := (*wrapperspb.Int64Value)(m.I).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 10: @@ -1907,7 +1290,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1920,11 +1303,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1932,16 +1315,8 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { if m.J == nil { m.J = &wrapperspb.StringValue{} } - if unmarshal, ok := interface{}(m.J).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.J); err != nil { - return err - } + if err := (*wrapperspb.StringValue)(m.J).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 11: @@ -1951,7 +1326,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1964,11 +1339,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1976,16 +1351,8 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { if m.K == nil { m.K = &wrapperspb.UInt32Value{} } - if unmarshal, ok := interface{}(m.K).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.K); err != nil { - return err - } + if err := (*wrapperspb.UInt32Value)(m.K).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 12: @@ -1995,7 +1362,7 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -2008,11 +1375,11 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -2020,26 +1387,18 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { if m.L == nil { m.L = &wrapperspb.UInt64Value{} } - if unmarshal, ok := interface{}(m.L).(interface { - UnmarshalVT([]byte) error - }); ok { - if err := unmarshal.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { - return err - } - } else { - if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.L); err != nil { - return err - } + if err := (*wrapperspb.UInt64Value)(m.L).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -2054,88 +1413,3 @@ func (m *Response) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/types/known/anypb/any_vtproto.pb.go b/types/known/anypb/any_vtproto.pb.go index 7bacc33..6d57e5d 100644 --- a/types/known/anypb/any_vtproto.pb.go +++ b/types/known/anypb/any_vtproto.pb.go @@ -13,9 +13,9 @@ package anypb import ( fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -58,31 +58,20 @@ func (m *Any) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Value) > 0 { i -= len(m.Value) copy(dAtA[i:], m.Value) - i = encodeVarint(dAtA, i, uint64(len(m.Value))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Value))) i-- dAtA[i] = 0x12 } if len(m.TypeUrl) > 0 { i -= len(m.TypeUrl) copy(dAtA[i:], m.TypeUrl) - i = encodeVarint(dAtA, i, uint64(len(m.TypeUrl))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.TypeUrl))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *Any) SizeVT() (n int) { if m == nil { return 0 @@ -91,22 +80,16 @@ func (m *Any) SizeVT() (n int) { _ = l l = len(m.TypeUrl) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } l = len(m.Value) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *Any) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -115,7 +98,7 @@ func (m *Any) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -143,7 +126,7 @@ func (m *Any) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -157,11 +140,11 @@ func (m *Any) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -175,7 +158,7 @@ func (m *Any) UnmarshalVT(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -188,11 +171,11 @@ func (m *Any) UnmarshalVT(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -204,12 +187,12 @@ func (m *Any) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -224,88 +207,3 @@ func (m *Any) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/types/known/durationpb/duration_vtproto.pb.go b/types/known/durationpb/duration_vtproto.pb.go index f8719c2..bfe05d1 100644 --- a/types/known/durationpb/duration_vtproto.pb.go +++ b/types/known/durationpb/duration_vtproto.pb.go @@ -13,9 +13,9 @@ package durationpb import ( fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -56,29 +56,18 @@ func (m *Duration) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.Nanos != 0 { - i = encodeVarint(dAtA, i, uint64(m.Nanos)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Nanos)) i-- dAtA[i] = 0x10 } if m.Seconds != 0 { - i = encodeVarint(dAtA, i, uint64(m.Seconds)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Seconds)) i-- dAtA[i] = 0x8 } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *Duration) SizeVT() (n int) { if m == nil { return 0 @@ -86,21 +75,15 @@ func (m *Duration) SizeVT() (n int) { var l int _ = l if m.Seconds != 0 { - n += 1 + sov(uint64(m.Seconds)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Seconds)) } if m.Nanos != 0 { - n += 1 + sov(uint64(m.Nanos)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Nanos)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *Duration) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -109,7 +92,7 @@ func (m *Duration) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -137,7 +120,7 @@ func (m *Duration) UnmarshalVT(dAtA []byte) error { m.Seconds = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -156,7 +139,7 @@ func (m *Duration) UnmarshalVT(dAtA []byte) error { m.Nanos = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -170,12 +153,12 @@ func (m *Duration) UnmarshalVT(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -190,88 +173,3 @@ func (m *Duration) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/types/known/emptypb/empty_vtproto.pb.go b/types/known/emptypb/empty_vtproto.pb.go index 5dd032a..a755ff4 100644 --- a/types/known/emptypb/empty_vtproto.pb.go +++ b/types/known/emptypb/empty_vtproto.pb.go @@ -13,9 +13,9 @@ package emptypb import ( fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -58,17 +58,6 @@ func (m *Empty) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *Empty) SizeVT() (n int) { if m == nil { return 0 @@ -79,12 +68,6 @@ func (m *Empty) SizeVT() (n int) { return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *Empty) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -93,7 +76,7 @@ func (m *Empty) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -116,12 +99,12 @@ func (m *Empty) UnmarshalVT(dAtA []byte) error { switch fieldNum { default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -136,88 +119,3 @@ func (m *Empty) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/types/known/sourcecontextpb/source_context_vtproto.pb.go b/types/known/sourcecontextpb/source_context_vtproto.pb.go index 5bc7bc3..14e09f9 100644 --- a/types/known/sourcecontextpb/source_context_vtproto.pb.go +++ b/types/known/sourcecontextpb/source_context_vtproto.pb.go @@ -13,9 +13,9 @@ package sourcecontextpb import ( fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -58,24 +58,13 @@ func (m *SourceContext) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.FileName) > 0 { i -= len(m.FileName) copy(dAtA[i:], m.FileName) - i = encodeVarint(dAtA, i, uint64(len(m.FileName))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.FileName))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *SourceContext) SizeVT() (n int) { if m == nil { return 0 @@ -84,18 +73,12 @@ func (m *SourceContext) SizeVT() (n int) { _ = l l = len(m.FileName) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *SourceContext) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -104,7 +87,7 @@ func (m *SourceContext) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -132,7 +115,7 @@ func (m *SourceContext) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -146,11 +129,11 @@ func (m *SourceContext) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -159,12 +142,12 @@ func (m *SourceContext) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -179,88 +162,3 @@ func (m *SourceContext) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/types/known/structpb/struct_vtproto.pb.go b/types/known/structpb/struct_vtproto.pb.go index eaa5d13..c7d1c8f 100644 --- a/types/known/structpb/struct_vtproto.pb.go +++ b/types/known/structpb/struct_vtproto.pb.go @@ -14,10 +14,10 @@ package structpb import ( binary "encoding/binary" fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" math "math" - bits "math/bits" ) const ( @@ -61,20 +61,20 @@ func (m *Struct) MarshalToSizedBufferVT(dAtA []byte) (int, error) { for k := range m.Fields { v := m.Fields[k] baseI := i - size, err := v.MarshalToSizedBufferVT(dAtA[:i]) + size, err := (*Value)(v).MarshalToSizedBufferVT(dAtA[:i]) if err != nil { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x12 i -= len(k) copy(dAtA[i:], k) - i = encodeVarint(dAtA, i, uint64(len(k))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(k))) i-- dAtA[i] = 0xa - i = encodeVarint(dAtA, i, uint64(baseI-i)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) i-- dAtA[i] = 0xa } @@ -112,10 +112,39 @@ func (m *Value) MarshalToSizedBufferVT(dAtA []byte) (int, error) { i -= len(m.unknownFields) copy(dAtA[i:], m.unknownFields) } - if vtmsg, ok := m.Kind.(interface { - MarshalToSizedBufferVT([]byte) (int, error) - }); ok { - size, err := vtmsg.MarshalToSizedBufferVT(dAtA[:i]) + switch c := m.Kind.(type) { + case *Value_NullValue: + size, err := (*Value_NullValue)(c).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + case *Value_NumberValue: + size, err := (*Value_NumberValue)(c).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + case *Value_StringValue: + size, err := (*Value_StringValue)(c).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + case *Value_BoolValue: + size, err := (*Value_BoolValue)(c).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + case *Value_StructValue: + size, err := (*Value_StructValue)(c).MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + case *Value_ListValue: + size, err := (*Value_ListValue)(c).MarshalToSizedBufferVT(dAtA[:i]) if err != nil { return 0, err } @@ -131,7 +160,7 @@ func (m *Value_NullValue) MarshalToVT(dAtA []byte) (int, error) { func (m *Value_NullValue) MarshalToSizedBufferVT(dAtA []byte) (int, error) { i := len(dAtA) - i = encodeVarint(dAtA, i, uint64(m.NullValue)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.NullValue)) i-- dAtA[i] = 0x8 return len(dAtA) - i, nil @@ -158,7 +187,7 @@ func (m *Value_StringValue) MarshalToSizedBufferVT(dAtA []byte) (int, error) { i := len(dAtA) i -= len(m.StringValue) copy(dAtA[i:], m.StringValue) - i = encodeVarint(dAtA, i, uint64(len(m.StringValue))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.StringValue))) i-- dAtA[i] = 0x1a return len(dAtA) - i, nil @@ -188,12 +217,12 @@ func (m *Value_StructValue) MarshalToVT(dAtA []byte) (int, error) { func (m *Value_StructValue) MarshalToSizedBufferVT(dAtA []byte) (int, error) { i := len(dAtA) if m.StructValue != nil { - size, err := m.StructValue.MarshalToSizedBufferVT(dAtA[:i]) + size, err := (*Struct)(m.StructValue).MarshalToSizedBufferVT(dAtA[:i]) if err != nil { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x2a } @@ -207,12 +236,12 @@ func (m *Value_ListValue) MarshalToVT(dAtA []byte) (int, error) { func (m *Value_ListValue) MarshalToSizedBufferVT(dAtA []byte) (int, error) { i := len(dAtA) if m.ListValue != nil { - size, err := m.ListValue.MarshalToSizedBufferVT(dAtA[:i]) + size, err := (*ListValue)(m.ListValue).MarshalToSizedBufferVT(dAtA[:i]) if err != nil { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x32 } @@ -250,12 +279,12 @@ func (m *ListValue) MarshalToSizedBufferVT(dAtA []byte) (int, error) { } if len(m.Values) > 0 { for iNdEx := len(m.Values) - 1; iNdEx >= 0; iNdEx-- { - size, err := m.Values[iNdEx].MarshalToSizedBufferVT(dAtA[:i]) + size, err := (*Value)(m.Values[iNdEx]).MarshalToSizedBufferVT(dAtA[:i]) if err != nil { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0xa } @@ -263,17 +292,6 @@ func (m *ListValue) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *Struct) SizeVT() (n int) { if m == nil { return 0 @@ -286,11 +304,11 @@ func (m *Struct) SizeVT() (n int) { _ = v l = 0 if v != nil { - l = v.SizeVT() + l = (*Value)(v).SizeVT() } - l += 1 + sov(uint64(l)) - mapEntrySize := 1 + len(k) + sov(uint64(len(k))) + l - n += mapEntrySize + 1 + sov(uint64(mapEntrySize)) + l += 1 + protohelpers.SizeOfVarint(uint64(l)) + mapEntrySize := 1 + len(k) + protohelpers.SizeOfVarint(uint64(len(k))) + l + n += mapEntrySize + 1 + protohelpers.SizeOfVarint(uint64(mapEntrySize)) } } n += len(m.unknownFields) @@ -303,8 +321,19 @@ func (m *Value) SizeVT() (n int) { } var l int _ = l - if vtmsg, ok := m.Kind.(interface{ SizeVT() int }); ok { - n += vtmsg.SizeVT() + switch c := m.Kind.(type) { + case *Value_NullValue: + n += (*Value_NullValue)(c).SizeVT() + case *Value_NumberValue: + n += (*Value_NumberValue)(c).SizeVT() + case *Value_StringValue: + n += (*Value_StringValue)(c).SizeVT() + case *Value_BoolValue: + n += (*Value_BoolValue)(c).SizeVT() + case *Value_StructValue: + n += (*Value_StructValue)(c).SizeVT() + case *Value_ListValue: + n += (*Value_ListValue)(c).SizeVT() } n += len(m.unknownFields) return n @@ -316,7 +345,7 @@ func (m *Value_NullValue) SizeVT() (n int) { } var l int _ = l - n += 1 + sov(uint64(m.NullValue)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.NullValue)) return n } func (m *Value_NumberValue) SizeVT() (n int) { @@ -335,7 +364,7 @@ func (m *Value_StringValue) SizeVT() (n int) { var l int _ = l l = len(m.StringValue) - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) return n } func (m *Value_BoolValue) SizeVT() (n int) { @@ -354,8 +383,8 @@ func (m *Value_StructValue) SizeVT() (n int) { var l int _ = l if m.StructValue != nil { - l = m.StructValue.SizeVT() - n += 1 + l + sov(uint64(l)) + l = (*Struct)(m.StructValue).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } return n } @@ -366,8 +395,8 @@ func (m *Value_ListValue) SizeVT() (n int) { var l int _ = l if m.ListValue != nil { - l = m.ListValue.SizeVT() - n += 1 + l + sov(uint64(l)) + l = (*ListValue)(m.ListValue).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } return n } @@ -379,20 +408,14 @@ func (m *ListValue) SizeVT() (n int) { _ = l if len(m.Values) > 0 { for _, e := range m.Values { - l = e.SizeVT() - n += 1 + l + sov(uint64(l)) + l = (*Value)(e).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *Struct) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -401,7 +424,7 @@ func (m *Struct) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -429,7 +452,7 @@ func (m *Struct) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -442,11 +465,11 @@ func (m *Struct) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -461,7 +484,7 @@ func (m *Struct) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -478,7 +501,7 @@ func (m *Struct) UnmarshalVT(dAtA []byte) error { var stringLenmapkey uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -492,11 +515,11 @@ func (m *Struct) UnmarshalVT(dAtA []byte) error { } intStringLenmapkey := int(stringLenmapkey) if intStringLenmapkey < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postStringIndexmapkey := iNdEx + intStringLenmapkey if postStringIndexmapkey < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postStringIndexmapkey > l { return io.ErrUnexpectedEOF @@ -507,7 +530,7 @@ func (m *Struct) UnmarshalVT(dAtA []byte) error { var mapmsglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -520,28 +543,28 @@ func (m *Struct) UnmarshalVT(dAtA []byte) error { } } if mapmsglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postmsgIndex := iNdEx + mapmsglen if postmsgIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postmsgIndex > l { return io.ErrUnexpectedEOF } mapvalue = &Value{} - if err := mapvalue.UnmarshalVT(dAtA[iNdEx:postmsgIndex]); err != nil { + if err := (*Value)(mapvalue).UnmarshalVT(dAtA[iNdEx:postmsgIndex]); err != nil { return err } iNdEx = postmsgIndex } else { iNdEx = entryPreIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > postIndex { return io.ErrUnexpectedEOF @@ -553,12 +576,12 @@ func (m *Struct) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -581,7 +604,7 @@ func (m *Value) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -609,7 +632,7 @@ func (m *Value) UnmarshalVT(dAtA []byte) error { var v NullValue for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -640,7 +663,7 @@ func (m *Value) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -654,11 +677,11 @@ func (m *Value) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -672,7 +695,7 @@ func (m *Value) UnmarshalVT(dAtA []byte) error { var v int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -693,7 +716,7 @@ func (m *Value) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -706,22 +729,22 @@ func (m *Value) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF } if oneof, ok := m.Kind.(*Value_StructValue); ok { - if err := oneof.StructValue.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + if err := (*Struct)(oneof.StructValue).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } } else { v := &Struct{} - if err := v.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + if err := (*Struct)(v).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } m.Kind = &Value_StructValue{StructValue: v} @@ -734,7 +757,7 @@ func (m *Value) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -747,22 +770,22 @@ func (m *Value) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF } if oneof, ok := m.Kind.(*Value_ListValue); ok { - if err := oneof.ListValue.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + if err := (*ListValue)(oneof.ListValue).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } } else { v := &ListValue{} - if err := v.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + if err := (*ListValue)(v).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } m.Kind = &Value_ListValue{ListValue: v} @@ -770,12 +793,12 @@ func (m *Value) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -798,7 +821,7 @@ func (m *ListValue) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -826,7 +849,7 @@ func (m *ListValue) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -839,28 +862,28 @@ func (m *ListValue) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF } m.Values = append(m.Values, &Value{}) - if err := m.Values[len(m.Values)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + if err := (*Value)(m.Values[len(m.Values)-1]).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -875,88 +898,3 @@ func (m *ListValue) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/types/known/timestamppb/timestamp_vtproto.pb.go b/types/known/timestamppb/timestamp_vtproto.pb.go index ee50941..573d90e 100644 --- a/types/known/timestamppb/timestamp_vtproto.pb.go +++ b/types/known/timestamppb/timestamp_vtproto.pb.go @@ -13,9 +13,9 @@ package timestamppb import ( fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -56,29 +56,18 @@ func (m *Timestamp) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.Nanos != 0 { - i = encodeVarint(dAtA, i, uint64(m.Nanos)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Nanos)) i-- dAtA[i] = 0x10 } if m.Seconds != 0 { - i = encodeVarint(dAtA, i, uint64(m.Seconds)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Seconds)) i-- dAtA[i] = 0x8 } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *Timestamp) SizeVT() (n int) { if m == nil { return 0 @@ -86,21 +75,15 @@ func (m *Timestamp) SizeVT() (n int) { var l int _ = l if m.Seconds != 0 { - n += 1 + sov(uint64(m.Seconds)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Seconds)) } if m.Nanos != 0 { - n += 1 + sov(uint64(m.Nanos)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Nanos)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *Timestamp) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -109,7 +92,7 @@ func (m *Timestamp) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -137,7 +120,7 @@ func (m *Timestamp) UnmarshalVT(dAtA []byte) error { m.Seconds = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -156,7 +139,7 @@ func (m *Timestamp) UnmarshalVT(dAtA []byte) error { m.Nanos = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -170,12 +153,12 @@ func (m *Timestamp) UnmarshalVT(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -190,88 +173,3 @@ func (m *Timestamp) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/types/known/typepb/type_vtproto.pb.go b/types/known/typepb/type_vtproto.pb.go index f56a519..8bcf7dd 100644 --- a/types/known/typepb/type_vtproto.pb.go +++ b/types/known/typepb/type_vtproto.pb.go @@ -15,9 +15,9 @@ import ( fmt "fmt" anypb "github.com/knqyf263/go-plugin/types/known/anypb" sourcecontextpb "github.com/knqyf263/go-plugin/types/known/sourcecontextpb" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" - bits "math/bits" ) const ( @@ -58,7 +58,7 @@ func (m *Type) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.Syntax != 0 { - i = encodeVarint(dAtA, i, uint64(m.Syntax)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Syntax)) i-- dAtA[i] = 0x30 } @@ -68,7 +68,7 @@ func (m *Type) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x2a } @@ -79,7 +79,7 @@ func (m *Type) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x22 } @@ -88,7 +88,7 @@ func (m *Type) MarshalToSizedBufferVT(dAtA []byte) (int, error) { for iNdEx := len(m.Oneofs) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.Oneofs[iNdEx]) copy(dAtA[i:], m.Oneofs[iNdEx]) - i = encodeVarint(dAtA, i, uint64(len(m.Oneofs[iNdEx]))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Oneofs[iNdEx]))) i-- dAtA[i] = 0x1a } @@ -100,7 +100,7 @@ func (m *Type) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x12 } @@ -108,7 +108,7 @@ func (m *Type) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Name) > 0 { i -= len(m.Name) copy(dAtA[i:], m.Name) - i = encodeVarint(dAtA, i, uint64(len(m.Name))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Name))) i-- dAtA[i] = 0xa } @@ -148,14 +148,14 @@ func (m *Field) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.DefaultValue) > 0 { i -= len(m.DefaultValue) copy(dAtA[i:], m.DefaultValue) - i = encodeVarint(dAtA, i, uint64(len(m.DefaultValue))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.DefaultValue))) i-- dAtA[i] = 0x5a } if len(m.JsonName) > 0 { i -= len(m.JsonName) copy(dAtA[i:], m.JsonName) - i = encodeVarint(dAtA, i, uint64(len(m.JsonName))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.JsonName))) i-- dAtA[i] = 0x52 } @@ -166,7 +166,7 @@ func (m *Field) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x4a } @@ -182,36 +182,36 @@ func (m *Field) MarshalToSizedBufferVT(dAtA []byte) (int, error) { dAtA[i] = 0x40 } if m.OneofIndex != 0 { - i = encodeVarint(dAtA, i, uint64(m.OneofIndex)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.OneofIndex)) i-- dAtA[i] = 0x38 } if len(m.TypeUrl) > 0 { i -= len(m.TypeUrl) copy(dAtA[i:], m.TypeUrl) - i = encodeVarint(dAtA, i, uint64(len(m.TypeUrl))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.TypeUrl))) i-- dAtA[i] = 0x32 } if len(m.Name) > 0 { i -= len(m.Name) copy(dAtA[i:], m.Name) - i = encodeVarint(dAtA, i, uint64(len(m.Name))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Name))) i-- dAtA[i] = 0x22 } if m.Number != 0 { - i = encodeVarint(dAtA, i, uint64(m.Number)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Number)) i-- dAtA[i] = 0x18 } if m.Cardinality != 0 { - i = encodeVarint(dAtA, i, uint64(m.Cardinality)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Cardinality)) i-- dAtA[i] = 0x10 } if m.Kind != 0 { - i = encodeVarint(dAtA, i, uint64(m.Kind)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Kind)) i-- dAtA[i] = 0x8 } @@ -249,7 +249,7 @@ func (m *Enum) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.Syntax != 0 { - i = encodeVarint(dAtA, i, uint64(m.Syntax)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Syntax)) i-- dAtA[i] = 0x28 } @@ -259,7 +259,7 @@ func (m *Enum) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x22 } @@ -270,7 +270,7 @@ func (m *Enum) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x1a } @@ -282,7 +282,7 @@ func (m *Enum) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x12 } @@ -290,7 +290,7 @@ func (m *Enum) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Name) > 0 { i -= len(m.Name) copy(dAtA[i:], m.Name) - i = encodeVarint(dAtA, i, uint64(len(m.Name))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Name))) i-- dAtA[i] = 0xa } @@ -334,20 +334,20 @@ func (m *EnumValue) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x1a } } if m.Number != 0 { - i = encodeVarint(dAtA, i, uint64(m.Number)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Number)) i-- dAtA[i] = 0x10 } if len(m.Name) > 0 { i -= len(m.Name) copy(dAtA[i:], m.Name) - i = encodeVarint(dAtA, i, uint64(len(m.Name))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Name))) i-- dAtA[i] = 0xa } @@ -385,36 +385,25 @@ func (m *Option) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.Value != nil { - size, err := m.Value.MarshalToSizedBufferVT(dAtA[:i]) + size, err := (*anypb.Any)(m.Value).MarshalToSizedBufferVT(dAtA[:i]) if err != nil { return 0, err } i -= size - i = encodeVarint(dAtA, i, uint64(size)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) i-- dAtA[i] = 0x12 } if len(m.Name) > 0 { i -= len(m.Name) copy(dAtA[i:], m.Name) - i = encodeVarint(dAtA, i, uint64(len(m.Name))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Name))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *Type) SizeVT() (n int) { if m == nil { return 0 @@ -423,32 +412,32 @@ func (m *Type) SizeVT() (n int) { _ = l l = len(m.Name) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if len(m.Fields) > 0 { for _, e := range m.Fields { l = e.SizeVT() - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } } if len(m.Oneofs) > 0 { for _, s := range m.Oneofs { l = len(s) - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } } if len(m.Options) > 0 { for _, e := range m.Options { l = e.SizeVT() - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } } if m.SourceContext != nil { l = m.SourceContext.SizeVT() - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.Syntax != 0 { - n += 1 + sov(uint64(m.Syntax)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Syntax)) } n += len(m.unknownFields) return n @@ -461,24 +450,24 @@ func (m *Field) SizeVT() (n int) { var l int _ = l if m.Kind != 0 { - n += 1 + sov(uint64(m.Kind)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Kind)) } if m.Cardinality != 0 { - n += 1 + sov(uint64(m.Cardinality)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Cardinality)) } if m.Number != 0 { - n += 1 + sov(uint64(m.Number)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Number)) } l = len(m.Name) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } l = len(m.TypeUrl) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.OneofIndex != 0 { - n += 1 + sov(uint64(m.OneofIndex)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.OneofIndex)) } if m.Packed { n += 2 @@ -486,16 +475,16 @@ func (m *Field) SizeVT() (n int) { if len(m.Options) > 0 { for _, e := range m.Options { l = e.SizeVT() - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } } l = len(m.JsonName) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } l = len(m.DefaultValue) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -509,26 +498,26 @@ func (m *Enum) SizeVT() (n int) { _ = l l = len(m.Name) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if len(m.Enumvalue) > 0 { for _, e := range m.Enumvalue { l = e.SizeVT() - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } } if len(m.Options) > 0 { for _, e := range m.Options { l = e.SizeVT() - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } } if m.SourceContext != nil { l = m.SourceContext.SizeVT() - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.Syntax != 0 { - n += 1 + sov(uint64(m.Syntax)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Syntax)) } n += len(m.unknownFields) return n @@ -542,15 +531,15 @@ func (m *EnumValue) SizeVT() (n int) { _ = l l = len(m.Name) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.Number != 0 { - n += 1 + sov(uint64(m.Number)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Number)) } if len(m.Options) > 0 { for _, e := range m.Options { l = e.SizeVT() - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } } n += len(m.unknownFields) @@ -565,22 +554,16 @@ func (m *Option) SizeVT() (n int) { _ = l l = len(m.Name) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } if m.Value != nil { - l = m.Value.SizeVT() - n += 1 + l + sov(uint64(l)) + l = (*anypb.Any)(m.Value).SizeVT() + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *Type) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -589,7 +572,7 @@ func (m *Type) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -617,7 +600,7 @@ func (m *Type) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -631,11 +614,11 @@ func (m *Type) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -649,7 +632,7 @@ func (m *Type) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -662,11 +645,11 @@ func (m *Type) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -683,7 +666,7 @@ func (m *Type) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -697,11 +680,11 @@ func (m *Type) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -715,7 +698,7 @@ func (m *Type) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -728,11 +711,11 @@ func (m *Type) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -749,7 +732,7 @@ func (m *Type) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -762,11 +745,11 @@ func (m *Type) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -785,7 +768,7 @@ func (m *Type) UnmarshalVT(dAtA []byte) error { m.Syntax = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -799,12 +782,12 @@ func (m *Type) UnmarshalVT(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -827,7 +810,7 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -855,7 +838,7 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { m.Kind = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -874,7 +857,7 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { m.Cardinality = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -893,7 +876,7 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { m.Number = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -912,7 +895,7 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -926,11 +909,11 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -944,7 +927,7 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -958,11 +941,11 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -976,7 +959,7 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { m.OneofIndex = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -995,7 +978,7 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { var v int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1015,7 +998,7 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1028,11 +1011,11 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1049,7 +1032,7 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1063,11 +1046,11 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1081,7 +1064,7 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1095,11 +1078,11 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1108,12 +1091,12 @@ func (m *Field) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1136,7 +1119,7 @@ func (m *Enum) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1164,7 +1147,7 @@ func (m *Enum) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1178,11 +1161,11 @@ func (m *Enum) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1196,7 +1179,7 @@ func (m *Enum) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1209,11 +1192,11 @@ func (m *Enum) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1230,7 +1213,7 @@ func (m *Enum) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1243,11 +1226,11 @@ func (m *Enum) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1264,7 +1247,7 @@ func (m *Enum) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1277,11 +1260,11 @@ func (m *Enum) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1300,7 +1283,7 @@ func (m *Enum) UnmarshalVT(dAtA []byte) error { m.Syntax = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1314,12 +1297,12 @@ func (m *Enum) UnmarshalVT(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1342,7 +1325,7 @@ func (m *EnumValue) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1370,7 +1353,7 @@ func (m *EnumValue) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1384,11 +1367,11 @@ func (m *EnumValue) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1402,7 +1385,7 @@ func (m *EnumValue) UnmarshalVT(dAtA []byte) error { m.Number = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1421,7 +1404,7 @@ func (m *EnumValue) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1434,11 +1417,11 @@ func (m *EnumValue) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1450,12 +1433,12 @@ func (m *EnumValue) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1478,7 +1461,7 @@ func (m *Option) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1506,7 +1489,7 @@ func (m *Option) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1520,11 +1503,11 @@ func (m *Option) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1538,7 +1521,7 @@ func (m *Option) UnmarshalVT(dAtA []byte) error { var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1551,11 +1534,11 @@ func (m *Option) UnmarshalVT(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1563,18 +1546,18 @@ func (m *Option) UnmarshalVT(dAtA []byte) error { if m.Value == nil { m.Value = &anypb.Any{} } - if err := m.Value.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + if err := (*anypb.Any)(m.Value).UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1589,88 +1572,3 @@ func (m *Option) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -) diff --git a/types/known/wrapperspb/wrappers_vtproto.pb.go b/types/known/wrapperspb/wrappers_vtproto.pb.go index 7802cab..6caae8d 100644 --- a/types/known/wrapperspb/wrappers_vtproto.pb.go +++ b/types/known/wrapperspb/wrappers_vtproto.pb.go @@ -14,10 +14,10 @@ package wrapperspb import ( binary "encoding/binary" fmt "fmt" + protohelpers "github.com/planetscale/vtprotobuf/protohelpers" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" math "math" - bits "math/bits" ) const ( @@ -136,7 +136,7 @@ func (m *Int64Value) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.Value != 0 { - i = encodeVarint(dAtA, i, uint64(m.Value)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Value)) i-- dAtA[i] = 0x8 } @@ -174,7 +174,7 @@ func (m *UInt64Value) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.Value != 0 { - i = encodeVarint(dAtA, i, uint64(m.Value)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Value)) i-- dAtA[i] = 0x8 } @@ -212,7 +212,7 @@ func (m *Int32Value) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.Value != 0 { - i = encodeVarint(dAtA, i, uint64(m.Value)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Value)) i-- dAtA[i] = 0x8 } @@ -250,7 +250,7 @@ func (m *UInt32Value) MarshalToSizedBufferVT(dAtA []byte) (int, error) { copy(dAtA[i:], m.unknownFields) } if m.Value != 0 { - i = encodeVarint(dAtA, i, uint64(m.Value)) + i = protohelpers.EncodeVarint(dAtA, i, uint64(m.Value)) i-- dAtA[i] = 0x8 } @@ -333,7 +333,7 @@ func (m *StringValue) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Value) > 0 { i -= len(m.Value) copy(dAtA[i:], m.Value) - i = encodeVarint(dAtA, i, uint64(len(m.Value))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Value))) i-- dAtA[i] = 0xa } @@ -373,24 +373,13 @@ func (m *BytesValue) MarshalToSizedBufferVT(dAtA []byte) (int, error) { if len(m.Value) > 0 { i -= len(m.Value) copy(dAtA[i:], m.Value) - i = encodeVarint(dAtA, i, uint64(len(m.Value))) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Value))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarint(dAtA []byte, offset int, v uint64) int { - offset -= sov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} func (m *DoubleValue) SizeVT() (n int) { if m == nil { return 0 @@ -424,7 +413,7 @@ func (m *Int64Value) SizeVT() (n int) { var l int _ = l if m.Value != 0 { - n += 1 + sov(uint64(m.Value)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Value)) } n += len(m.unknownFields) return n @@ -437,7 +426,7 @@ func (m *UInt64Value) SizeVT() (n int) { var l int _ = l if m.Value != 0 { - n += 1 + sov(uint64(m.Value)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Value)) } n += len(m.unknownFields) return n @@ -450,7 +439,7 @@ func (m *Int32Value) SizeVT() (n int) { var l int _ = l if m.Value != 0 { - n += 1 + sov(uint64(m.Value)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Value)) } n += len(m.unknownFields) return n @@ -463,7 +452,7 @@ func (m *UInt32Value) SizeVT() (n int) { var l int _ = l if m.Value != 0 { - n += 1 + sov(uint64(m.Value)) + n += 1 + protohelpers.SizeOfVarint(uint64(m.Value)) } n += len(m.unknownFields) return n @@ -490,7 +479,7 @@ func (m *StringValue) SizeVT() (n int) { _ = l l = len(m.Value) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n @@ -504,18 +493,12 @@ func (m *BytesValue) SizeVT() (n int) { _ = l l = len(m.Value) if l > 0 { - n += 1 + l + sov(uint64(l)) + n += 1 + l + protohelpers.SizeOfVarint(uint64(l)) } n += len(m.unknownFields) return n } -func sov(x uint64) (n int) { - return (bits.Len64(x|1) + 6) / 7 -} -func soz(x uint64) (n int) { - return sov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} func (m *DoubleValue) UnmarshalVT(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -524,7 +507,7 @@ func (m *DoubleValue) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -558,12 +541,12 @@ func (m *DoubleValue) UnmarshalVT(dAtA []byte) error { m.Value = float64(math.Float64frombits(v)) default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -586,7 +569,7 @@ func (m *FloatValue) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -620,12 +603,12 @@ func (m *FloatValue) UnmarshalVT(dAtA []byte) error { m.Value = float32(math.Float32frombits(v)) default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -648,7 +631,7 @@ func (m *Int64Value) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -676,7 +659,7 @@ func (m *Int64Value) UnmarshalVT(dAtA []byte) error { m.Value = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -690,12 +673,12 @@ func (m *Int64Value) UnmarshalVT(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -718,7 +701,7 @@ func (m *UInt64Value) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -746,7 +729,7 @@ func (m *UInt64Value) UnmarshalVT(dAtA []byte) error { m.Value = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -760,12 +743,12 @@ func (m *UInt64Value) UnmarshalVT(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -788,7 +771,7 @@ func (m *Int32Value) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -816,7 +799,7 @@ func (m *Int32Value) UnmarshalVT(dAtA []byte) error { m.Value = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -830,12 +813,12 @@ func (m *Int32Value) UnmarshalVT(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -858,7 +841,7 @@ func (m *UInt32Value) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -886,7 +869,7 @@ func (m *UInt32Value) UnmarshalVT(dAtA []byte) error { m.Value = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -900,12 +883,12 @@ func (m *UInt32Value) UnmarshalVT(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -928,7 +911,7 @@ func (m *BoolValue) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -956,7 +939,7 @@ func (m *BoolValue) UnmarshalVT(dAtA []byte) error { var v int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -971,12 +954,12 @@ func (m *BoolValue) UnmarshalVT(dAtA []byte) error { m.Value = bool(v != 0) default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -999,7 +982,7 @@ func (m *StringValue) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1027,7 +1010,7 @@ func (m *StringValue) UnmarshalVT(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1041,11 +1024,11 @@ func (m *StringValue) UnmarshalVT(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1054,12 +1037,12 @@ func (m *StringValue) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1082,7 +1065,7 @@ func (m *BytesValue) UnmarshalVT(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1110,7 +1093,7 @@ func (m *BytesValue) UnmarshalVT(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflow + return protohelpers.ErrIntOverflow } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1123,11 +1106,11 @@ func (m *BytesValue) UnmarshalVT(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if postIndex > l { return io.ErrUnexpectedEOF @@ -1139,12 +1122,12 @@ func (m *BytesValue) UnmarshalVT(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skip(dAtA[iNdEx:]) + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLength + return protohelpers.ErrInvalidLength } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1159,88 +1142,3 @@ func (m *BytesValue) UnmarshalVT(dAtA []byte) error { } return nil } - -func skip(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflow - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLength - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroup - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLength - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflow = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") -)