From f0831e87e2b78faccf88fb0c491d37a3ef7467f1 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 21 Jan 2020 14:25:12 -0800 Subject: [PATCH] internal/impl: change unmarshal func return to unmarshalOptions The fast-path unmarshal funcs return the number of bytes consumed. Change these functions to return an unmarshalOutput struct instead, to make it easier to add to the results. This is groundwork for allowing the fast-path unmarshaler to indicate when the unmarshaled message is known to be initialized. Change-Id: Ia8c44731a88f5be969a55cd98ea26282f412c7ae Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/215720 Reviewed-by: Joe Tsai --- internal/cmd/generate-types/impl.go | 116 ++-- internal/impl/codec_field.go | 140 ++-- internal/impl/codec_gen.go | 1002 +++++++++++++++------------ internal/impl/codec_map.go | 50 +- internal/impl/codec_messageset.go | 9 +- internal/impl/codec_reflect.go | 31 +- internal/impl/codec_tables.go | 4 +- internal/impl/decode.go | 46 +- 8 files changed, 775 insertions(+), 623 deletions(-) diff --git a/internal/cmd/generate-types/impl.go b/internal/cmd/generate-types/impl.go index bca586c1..a72b43f4 100644 --- a/internal/cmd/generate-types/impl.go +++ b/internal/cmd/generate-types/impl.go @@ -96,16 +96,17 @@ func append{{.Name}}(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]b } // consume{{.Name}} wire decodes a {{.GoType}} pointer as a {{.Name}}. -func consume{{.Name}}(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consume{{.Name}}(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != {{.WireType.Expr}} { - return 0, errUnknown + return out, errUnknown } v, n := {{template "Consume" .}} if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.{{.GoType.PointerMethod}}() = {{.ToGoType}} - return n, nil + out.n = n + return out, nil } var coder{{.Name}} = pointerCoderFuncs{ @@ -127,19 +128,20 @@ func append{{.Name}}ValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalO } // consume{{.Name}}ValidateUTF8 wire decodes a {{.GoType}} pointer as a {{.Name}}. -func consume{{.Name}}ValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consume{{.Name}}ValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != {{.WireType.Expr}} { - return 0, errUnknown + return out, errUnknown } v, n := {{template "Consume" .}} if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if !utf8.Valid{{if eq .Name "String"}}String{{end}}(v) { - return 0, errInvalidUTF8{} + return out, errInvalidUTF8{} } *p.{{.GoType.PointerMethod}}() = {{.ToGoType}} - return n, nil + out.n = n + return out, nil } var coder{{.Name}}ValidateUTF8 = pointerCoderFuncs{ @@ -174,16 +176,17 @@ func append{{.Name}}NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions {{if .ToGoTypeNoZero}} // consume{{.Name}}NoZero wire decodes a {{.GoType}} pointer as a {{.Name}}. // The zero value is not decoded. -func consume{{.Name}}NoZero(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consume{{.Name}}NoZero(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != {{.WireType.Expr}} { - return 0, errUnknown + return out, errUnknown } v, n := {{template "Consume" .}} if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.{{.GoType.PointerMethod}}() = {{.ToGoTypeNoZero}} - return n, nil + out.n = n + return out, nil } {{end}} @@ -211,19 +214,20 @@ func append{{.Name}}NoZeroValidateUTF8(b []byte, p pointer, wiretag uint64, _ ma {{if .ToGoTypeNoZero}} // consume{{.Name}}NoZeroValidateUTF8 wire decodes a {{.GoType}} pointer as a {{.Name}}. -func consume{{.Name}}NoZeroValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consume{{.Name}}NoZeroValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != {{.WireType.Expr}} { - return 0, errUnknown + return out, errUnknown } v, n := {{template "Consume" .}} if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if !utf8.Valid{{if eq .Name "String"}}String{{end}}(v) { - return 0, errInvalidUTF8{} + return out, errInvalidUTF8{} } *p.{{.GoType.PointerMethod}}() = {{.ToGoTypeNoZero}} - return n, nil + out.n = n + return out, nil } {{end}} @@ -254,20 +258,21 @@ func append{{.Name}}Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ( } // consume{{.Name}}Ptr wire decodes a *{{.GoType}} pointer as a {{.Name}}. -func consume{{.Name}}Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consume{{.Name}}Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != {{.WireType.Expr}} { - return 0, errUnknown + return out, errUnknown } v, n := {{template "Consume" .}} if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.{{.GoType.PointerMethod}}Ptr() if *vp == nil { *vp = new({{.GoType}}) } **vp = {{.ToGoType}} - return n, nil + out.n = n + return out, nil } var coder{{.Name}}Ptr = pointerCoderFuncs{ @@ -301,36 +306,38 @@ func append{{.Name}}Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) } // consume{{.Name}}Slice wire decodes a []{{.GoType}} pointer as a repeated {{.Name}}. -func consume{{.Name}}Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consume{{.Name}}Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.{{.GoType.PointerMethod}}Slice() {{- if .WireType.Packable}} if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := {{template "Consume" .}} if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, {{.ToGoType}}) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } {{- end}} if wtyp != {{.WireType.Expr}} { - return 0, errUnknown + return out, errUnknown } v, n := {{template "Consume" .}} if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, {{.ToGoType}}) - return n, nil + out.n = n + return out, nil } var coder{{.Name}}Slice = pointerCoderFuncs{ @@ -354,20 +361,21 @@ func append{{.Name}}SliceValidateUTF8(b []byte, p pointer, wiretag uint64, _ mar } // consume{{.Name}}SliceValidateUTF8 wire decodes a []{{.GoType}} pointer as a repeated {{.Name}}. -func consume{{.Name}}SliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consume{{.Name}}SliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.{{.GoType.PointerMethod}}Slice() if wtyp != {{.WireType.Expr}} { - return 0, errUnknown + return out, errUnknown } v, n := {{template "Consume" .}} if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if !utf8.Valid{{if eq .Name "String"}}String{{end}}(v) { - return 0, errInvalidUTF8{} + return out, errInvalidUTF8{} } *sp = append(*sp, {{.ToGoType}}) - return n, nil + out.n = n + return out, nil } var coder{{.Name}}SliceValidateUTF8 = pointerCoderFuncs{ @@ -440,15 +448,16 @@ func append{{.Name}}Value(b []byte, v protoreflect.Value, wiretag uint64, _ mars } // consume{{.Name}}Value decodes a {{.GoType}} value as a {{.Name}}. -func consume{{.Name}}Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consume{{.Name}}Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != {{.WireType.Expr}} { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := {{template "Consume" .}} if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return {{.ToValue}}, n, nil + out.n = n + return {{.ToValue}}, out, nil } var coder{{.Name}}Value = valueCoderFuncs{ @@ -469,18 +478,19 @@ func append{{.Name}}ValueValidateUTF8(b []byte, v protoreflect.Value, wiretag ui } // consume{{.Name}}ValueValidateUTF8 decodes a {{.GoType}} value as a {{.Name}}. -func consume{{.Name}}ValueValidateUTF8(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consume{{.Name}}ValueValidateUTF8(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != {{.WireType.Expr}} { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := {{template "Consume" .}} if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } if !utf8.ValidString(v) { - return protoreflect.Value{}, 0, errInvalidUTF8{} + return protoreflect.Value{}, out, errInvalidUTF8{} } - return {{.ToValue}}, n, nil + out.n = n + return {{.ToValue}}, out, nil } var coder{{.Name}}ValueValidateUTF8 = valueCoderFuncs{ @@ -516,34 +526,36 @@ func append{{.Name}}SliceValue(b []byte, listv protoreflect.Value, wiretag uint6 } // consume{{.Name}}SliceValue wire decodes a []{{.GoType}} value as a repeated {{.Name}}. -func consume{{.Name}}SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consume{{.Name}}SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() {{- if .WireType.Packable}} if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := {{template "Consume" .}} if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append({{.ToValue}}) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } {{- end}} if wtyp != {{.WireType.Expr}} { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := {{template "Consume" .}} if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append({{.ToValue}}) - return listv, n, nil + out.n = n + return listv, out, nil } var coder{{.Name}}SliceValue = valueCoderFuncs{ diff --git a/internal/impl/codec_field.go b/internal/impl/codec_field.go index 3f3957ce..f1f0671c 100644 --- a/internal/impl/codec_field.go +++ b/internal/impl/codec_field.go @@ -52,7 +52,7 @@ func (mi *MessageInfo) initOneofFieldCoders(od pref.OneofDescriptor, si structIn if funcs.isInit != nil { needIsInit = true } - cf.funcs.unmarshal = func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (int, error) { + cf.funcs.unmarshal = func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (unmarshalOutput, error) { var vw reflect.Value // pointer to wrapper type vi := p.AsValueOf(ft).Elem() // oneof field value of interface kind if !vi.IsNil() && !vi.Elem().IsNil() && vi.Elem().Elem().Type() == ot { @@ -60,12 +60,12 @@ func (mi *MessageInfo) initOneofFieldCoders(od pref.OneofDescriptor, si structIn } else { vw = reflect.New(ot) } - n, err := funcs.unmarshal(b, pointerOfValue(vw).Apply(zeroOffset), wtyp, opts) + out, err := funcs.unmarshal(b, pointerOfValue(vw).Apply(zeroOffset), wtyp, opts) if err != nil { - return 0, err + return out, err } vi.Set(vw) - return n, nil + return out, nil } } getInfo := func(p pointer) (pointer, *oneofFieldInfo) { @@ -139,13 +139,13 @@ func makeWeakMessageFieldCoder(fd pref.FieldDescriptor) pointerCoderFuncs { } return appendMessage(b, m, wiretag, opts) }, - unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (int, error) { + unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (unmarshalOutput, error) { fs := p.WeakFields() m, ok := fs.get(num) if !ok { lazyInit() if messageType == nil { - return 0, errUnknown + return unmarshalOutput{}, errUnknown } m = messageType.New().Interface() fs.set(num, m) @@ -171,7 +171,7 @@ func makeMessageFieldCoder(fd pref.FieldDescriptor, ft reflect.Type) pointerCode marshal: func(b []byte, p pointer, wiretag uint64, opts marshalOptions) ([]byte, error) { return appendMessageInfo(b, p, wiretag, mi, opts) }, - unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (int, error) { + unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (unmarshalOutput, error) { return consumeMessageInfo(b, p, mi, wtyp, opts) }, } @@ -191,7 +191,7 @@ func makeMessageFieldCoder(fd pref.FieldDescriptor, ft reflect.Type) pointerCode m := asMessage(p.AsValueOf(ft).Elem()) return appendMessage(b, m, wiretag, opts) }, - unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (int, error) { + unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (unmarshalOutput, error) { mp := p.AsValueOf(ft).Elem() if mp.IsNil() { mp.Set(reflect.New(ft.Elem())) @@ -216,21 +216,22 @@ func appendMessageInfo(b []byte, p pointer, wiretag uint64, mi *MessageInfo, opt return mi.marshalAppendPointer(b, p.Elem(), opts) } -func consumeMessageInfo(b []byte, p pointer, mi *MessageInfo, wtyp wire.Type, opts unmarshalOptions) (int, error) { +func consumeMessageInfo(b []byte, p pointer, mi *MessageInfo, wtyp wire.Type, opts unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if p.Elem().IsNil() { p.SetPointer(pointerOfValue(reflect.New(mi.GoReflectType.Elem()))) } if _, err := mi.unmarshalPointer(v, p.Elem(), 0, opts); err != nil { - return 0, err + return out, err } - return n, nil + out.n = n + return out, nil } func sizeMessage(m proto.Message, tagsize int, _ marshalOptions) int { @@ -243,18 +244,19 @@ func appendMessage(b []byte, m proto.Message, wiretag uint64, opts marshalOption return opts.Options().MarshalAppend(b, m) } -func consumeMessage(b []byte, m proto.Message, wtyp wire.Type, opts unmarshalOptions) (int, error) { +func consumeMessage(b []byte, m proto.Message, wtyp wire.Type, opts unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if err := opts.Options().Unmarshal(v, m); err != nil { - return 0, err + return out, err } - return n, nil + out.n = n + return out, nil } func sizeMessageValue(v pref.Value, tagsize int, opts marshalOptions) int { @@ -267,10 +269,10 @@ func appendMessageValue(b []byte, v pref.Value, wiretag uint64, opts marshalOpti return appendMessage(b, m, wiretag, opts) } -func consumeMessageValue(b []byte, v pref.Value, _ wire.Number, wtyp wire.Type, opts unmarshalOptions) (pref.Value, int, error) { +func consumeMessageValue(b []byte, v pref.Value, _ wire.Number, wtyp wire.Type, opts unmarshalOptions) (pref.Value, unmarshalOutput, error) { m := v.Message().Interface() - n, err := consumeMessage(b, m, wtyp, opts) - return v, n, err + out, err := consumeMessage(b, m, wtyp, opts) + return v, out, err } func isInitMessageValue(v pref.Value) error { @@ -295,10 +297,10 @@ func appendGroupValue(b []byte, v pref.Value, wiretag uint64, opts marshalOption return appendGroup(b, m, wiretag, opts) } -func consumeGroupValue(b []byte, v pref.Value, num wire.Number, wtyp wire.Type, opts unmarshalOptions) (pref.Value, int, error) { +func consumeGroupValue(b []byte, v pref.Value, num wire.Number, wtyp wire.Type, opts unmarshalOptions) (pref.Value, unmarshalOutput, error) { m := v.Message().Interface() - n, err := consumeGroup(b, m, num, wtyp, opts) - return v, n, err + out, err := consumeGroup(b, m, num, wtyp, opts) + return v, out, err } var coderGroupValue = valueCoderFuncs{ @@ -318,7 +320,7 @@ func makeGroupFieldCoder(fd pref.FieldDescriptor, ft reflect.Type) pointerCoderF marshal: func(b []byte, p pointer, wiretag uint64, opts marshalOptions) ([]byte, error) { return appendGroupType(b, p, wiretag, mi, opts) }, - unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (int, error) { + unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (unmarshalOutput, error) { return consumeGroupType(b, p, mi, num, wtyp, opts) }, } @@ -338,7 +340,7 @@ func makeGroupFieldCoder(fd pref.FieldDescriptor, ft reflect.Type) pointerCoderF m := asMessage(p.AsValueOf(ft).Elem()) return appendGroup(b, m, wiretag, opts) }, - unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (int, error) { + unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (unmarshalOutput, error) { mp := p.AsValueOf(ft).Elem() if mp.IsNil() { mp.Set(reflect.New(ft.Elem())) @@ -364,9 +366,9 @@ func appendGroupType(b []byte, p pointer, wiretag uint64, mi *MessageInfo, opts return b, err } -func consumeGroupType(b []byte, p pointer, mi *MessageInfo, num wire.Number, wtyp wire.Type, opts unmarshalOptions) (int, error) { +func consumeGroupType(b []byte, p pointer, mi *MessageInfo, num wire.Number, wtyp wire.Type, opts unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.StartGroupType { - return 0, errUnknown + return out, errUnknown } if p.Elem().IsNil() { p.SetPointer(pointerOfValue(reflect.New(mi.GoReflectType.Elem()))) @@ -385,15 +387,16 @@ func appendGroup(b []byte, m proto.Message, wiretag uint64, opts marshalOptions) return b, err } -func consumeGroup(b []byte, m proto.Message, num wire.Number, wtyp wire.Type, opts unmarshalOptions) (int, error) { +func consumeGroup(b []byte, m proto.Message, num wire.Number, wtyp wire.Type, opts unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.StartGroupType { - return 0, errUnknown + return out, errUnknown } b, n := wire.ConsumeGroup(num, b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } - return n, opts.Options().Unmarshal(b, m) + out.n = n + return out, opts.Options().Unmarshal(b, m) } func makeMessageSliceFieldCoder(fd pref.FieldDescriptor, ft reflect.Type) pointerCoderFuncs { @@ -405,7 +408,7 @@ func makeMessageSliceFieldCoder(fd pref.FieldDescriptor, ft reflect.Type) pointe marshal: func(b []byte, p pointer, wiretag uint64, opts marshalOptions) ([]byte, error) { return appendMessageSliceInfo(b, p, wiretag, mi, opts) }, - unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (int, error) { + unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (unmarshalOutput, error) { return consumeMessageSliceInfo(b, p, mi, wtyp, opts) }, } @@ -423,7 +426,7 @@ func makeMessageSliceFieldCoder(fd pref.FieldDescriptor, ft reflect.Type) pointe marshal: func(b []byte, p pointer, wiretag uint64, opts marshalOptions) ([]byte, error) { return appendMessageSlice(b, p, wiretag, ft, opts) }, - unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (int, error) { + unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (unmarshalOutput, error) { return consumeMessageSlice(b, p, ft, wtyp, opts) }, isInit: func(p pointer) error { @@ -456,21 +459,22 @@ func appendMessageSliceInfo(b []byte, p pointer, wiretag uint64, mi *MessageInfo return b, nil } -func consumeMessageSliceInfo(b []byte, p pointer, mi *MessageInfo, wtyp wire.Type, opts unmarshalOptions) (int, error) { +func consumeMessageSliceInfo(b []byte, p pointer, mi *MessageInfo, wtyp wire.Type, opts unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } m := reflect.New(mi.GoReflectType.Elem()).Interface() mp := pointerOfIface(m) if _, err := mi.unmarshalPointer(v, mp, 0, opts); err != nil { - return 0, err + return out, err } p.AppendPointerSlice(mp) - return n, nil + out.n = n + return out, nil } func isInitMessageSliceInfo(p pointer, mi *MessageInfo) error { @@ -509,20 +513,21 @@ func appendMessageSlice(b []byte, p pointer, wiretag uint64, goType reflect.Type return b, nil } -func consumeMessageSlice(b []byte, p pointer, goType reflect.Type, wtyp wire.Type, opts unmarshalOptions) (int, error) { +func consumeMessageSlice(b []byte, p pointer, goType reflect.Type, wtyp wire.Type, opts unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } mp := reflect.New(goType.Elem()) if err := opts.Options().Unmarshal(v, asMessage(mp)); err != nil { - return 0, err + return out, err } p.AppendPointerSlice(pointerOfValue(mp)) - return n, nil + out.n = n + return out, nil } func isInitMessageSlice(p pointer, goType reflect.Type) error { @@ -565,21 +570,22 @@ func appendMessageSliceValue(b []byte, listv pref.Value, wiretag uint64, opts ma return b, nil } -func consumeMessageSliceValue(b []byte, listv pref.Value, _ wire.Number, wtyp wire.Type, opts unmarshalOptions) (pref.Value, int, error) { +func consumeMessageSliceValue(b []byte, listv pref.Value, _ wire.Number, wtyp wire.Type, opts unmarshalOptions) (_ pref.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp != wire.BytesType { - return pref.Value{}, 0, errUnknown + return pref.Value{}, out, errUnknown } v, n := wire.ConsumeBytes(b) if n < 0 { - return pref.Value{}, 0, wire.ParseError(n) + return pref.Value{}, out, wire.ParseError(n) } m := list.NewElement() if err := opts.Options().Unmarshal(v, m.Message().Interface()); err != nil { - return pref.Value{}, 0, err + return pref.Value{}, out, err } list.Append(m) - return listv, n, nil + out.n = n + return listv, out, nil } func isInitMessageSliceValue(listv pref.Value) error { @@ -626,21 +632,22 @@ func appendGroupSliceValue(b []byte, listv pref.Value, wiretag uint64, opts mars return b, nil } -func consumeGroupSliceValue(b []byte, listv pref.Value, num wire.Number, wtyp wire.Type, opts unmarshalOptions) (pref.Value, int, error) { +func consumeGroupSliceValue(b []byte, listv pref.Value, num wire.Number, wtyp wire.Type, opts unmarshalOptions) (_ pref.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp != wire.StartGroupType { - return pref.Value{}, 0, errUnknown + return pref.Value{}, out, errUnknown } b, n := wire.ConsumeGroup(num, b) if n < 0 { - return pref.Value{}, 0, wire.ParseError(n) + return pref.Value{}, out, wire.ParseError(n) } m := list.NewElement() if err := opts.Options().Unmarshal(b, m.Message().Interface()); err != nil { - return pref.Value{}, 0, err + return pref.Value{}, out, err } list.Append(m) - return listv, n, nil + out.n = n + return listv, out, nil } var coderGroupSliceValue = valueCoderFuncs{ @@ -660,7 +667,7 @@ func makeGroupSliceFieldCoder(fd pref.FieldDescriptor, ft reflect.Type) pointerC marshal: func(b []byte, p pointer, wiretag uint64, opts marshalOptions) ([]byte, error) { return appendGroupSliceInfo(b, p, wiretag, mi, opts) }, - unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (int, error) { + unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (unmarshalOutput, error) { return consumeGroupSliceInfo(b, p, num, wtyp, mi, opts) }, } @@ -678,7 +685,7 @@ func makeGroupSliceFieldCoder(fd pref.FieldDescriptor, ft reflect.Type) pointerC marshal: func(b []byte, p pointer, wiretag uint64, opts marshalOptions) ([]byte, error) { return appendGroupSlice(b, p, wiretag, ft, opts) }, - unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (int, error) { + unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (unmarshalOutput, error) { return consumeGroupSlice(b, p, num, wtyp, ft, opts) }, isInit: func(p pointer) error { @@ -712,20 +719,21 @@ func appendGroupSlice(b []byte, p pointer, wiretag uint64, messageType reflect.T return b, nil } -func consumeGroupSlice(b []byte, p pointer, num wire.Number, wtyp wire.Type, goType reflect.Type, opts unmarshalOptions) (int, error) { +func consumeGroupSlice(b []byte, p pointer, num wire.Number, wtyp wire.Type, goType reflect.Type, opts unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.StartGroupType { - return 0, errUnknown + return out, errUnknown } b, n := wire.ConsumeGroup(num, b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } mp := reflect.New(goType.Elem()) if err := opts.Options().Unmarshal(b, asMessage(mp)); err != nil { - return 0, err + return out, err } p.AppendPointerSlice(pointerOfValue(mp)) - return n, nil + out.n = n + return out, nil } func sizeGroupSliceInfo(p pointer, mi *MessageInfo, tagsize int, opts marshalOptions) int { @@ -751,18 +759,18 @@ func appendGroupSliceInfo(b []byte, p pointer, wiretag uint64, mi *MessageInfo, return b, nil } -func consumeGroupSliceInfo(b []byte, p pointer, num wire.Number, wtyp wire.Type, mi *MessageInfo, opts unmarshalOptions) (int, error) { +func consumeGroupSliceInfo(b []byte, p pointer, num wire.Number, wtyp wire.Type, mi *MessageInfo, opts unmarshalOptions) (unmarshalOutput, error) { if wtyp != wire.StartGroupType { - return 0, errUnknown + return unmarshalOutput{}, errUnknown } m := reflect.New(mi.GoReflectType.Elem()).Interface() mp := pointerOfIface(m) - n, err := mi.unmarshalPointer(b, mp, num, opts) + out, err := mi.unmarshalPointer(b, mp, num, opts) if err != nil { - return 0, err + return out, err } p.AppendPointerSlice(mp) - return n, nil + return out, nil } func asMessage(v reflect.Value) pref.ProtoMessage { diff --git a/internal/impl/codec_gen.go b/internal/impl/codec_gen.go index 060d5bd8..41cdb7b8 100644 --- a/internal/impl/codec_gen.go +++ b/internal/impl/codec_gen.go @@ -29,16 +29,17 @@ func appendBool(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, } // consumeBool wire decodes a bool pointer as a Bool. -func consumeBool(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeBool(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Bool() = wire.DecodeBool(v) - return n, nil + out.n = n + return out, nil } var coderBool = pointerCoderFuncs{ @@ -92,20 +93,21 @@ func appendBoolPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byt } // consumeBoolPtr wire decodes a *bool pointer as a Bool. -func consumeBoolPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeBoolPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.BoolPtr() if *vp == nil { *vp = new(bool) } **vp = wire.DecodeBool(v) - return n, nil + out.n = n + return out, nil } var coderBoolPtr = pointerCoderFuncs{ @@ -134,34 +136,36 @@ func appendBoolSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]b } // consumeBoolSlice wire decodes a []bool pointer as a repeated Bool. -func consumeBoolSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeBoolSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.BoolSlice() if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, wire.DecodeBool(v)) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, wire.DecodeBool(v)) - return n, nil + out.n = n + return out, nil } var coderBoolSlice = pointerCoderFuncs{ @@ -220,15 +224,16 @@ func appendBoolValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOp } // consumeBoolValue decodes a bool value as a Bool. -func consumeBoolValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeBoolValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfBool(wire.DecodeBool(v)), n, nil + out.n = n + return protoreflect.ValueOfBool(wire.DecodeBool(v)), out, nil } var coderBoolValue = valueCoderFuncs{ @@ -259,32 +264,34 @@ func appendBoolSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ } // consumeBoolSliceValue wire decodes a []bool value as a repeated Bool. -func consumeBoolSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeBoolSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfBool(wire.DecodeBool(v))) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfBool(wire.DecodeBool(v))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderBoolSliceValue = valueCoderFuncs{ @@ -348,15 +355,16 @@ func appendEnumValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOp } // consumeEnumValue decodes a value as a Enum. -func consumeEnumValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeEnumValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)), n, nil + out.n = n + return protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)), out, nil } var coderEnumValue = valueCoderFuncs{ @@ -387,32 +395,34 @@ func appendEnumSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ } // consumeEnumSliceValue wire decodes a [] value as a repeated Enum. -func consumeEnumSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeEnumSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v))) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderEnumSliceValue = valueCoderFuncs{ @@ -478,16 +488,17 @@ func appendInt32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, } // consumeInt32 wire decodes a int32 pointer as a Int32. -func consumeInt32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeInt32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Int32() = int32(v) - return n, nil + out.n = n + return out, nil } var coderInt32 = pointerCoderFuncs{ @@ -541,20 +552,21 @@ func appendInt32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]by } // consumeInt32Ptr wire decodes a *int32 pointer as a Int32. -func consumeInt32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeInt32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.Int32Ptr() if *vp == nil { *vp = new(int32) } **vp = int32(v) - return n, nil + out.n = n + return out, nil } var coderInt32Ptr = pointerCoderFuncs{ @@ -583,34 +595,36 @@ func appendInt32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([] } // consumeInt32Slice wire decodes a []int32 pointer as a repeated Int32. -func consumeInt32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeInt32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.Int32Slice() if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, int32(v)) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, int32(v)) - return n, nil + out.n = n + return out, nil } var coderInt32Slice = pointerCoderFuncs{ @@ -669,15 +683,16 @@ func appendInt32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalO } // consumeInt32Value decodes a int32 value as a Int32. -func consumeInt32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeInt32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfInt32(int32(v)), n, nil + out.n = n + return protoreflect.ValueOfInt32(int32(v)), out, nil } var coderInt32Value = valueCoderFuncs{ @@ -708,32 +723,34 @@ func appendInt32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ } // consumeInt32SliceValue wire decodes a []int32 value as a repeated Int32. -func consumeInt32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeInt32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfInt32(int32(v))) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfInt32(int32(v))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderInt32SliceValue = valueCoderFuncs{ @@ -799,16 +816,17 @@ func appendSint32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte } // consumeSint32 wire decodes a int32 pointer as a Sint32. -func consumeSint32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeSint32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Int32() = int32(wire.DecodeZigZag(v & math.MaxUint32)) - return n, nil + out.n = n + return out, nil } var coderSint32 = pointerCoderFuncs{ @@ -862,20 +880,21 @@ func appendSint32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]b } // consumeSint32Ptr wire decodes a *int32 pointer as a Sint32. -func consumeSint32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeSint32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.Int32Ptr() if *vp == nil { *vp = new(int32) } **vp = int32(wire.DecodeZigZag(v & math.MaxUint32)) - return n, nil + out.n = n + return out, nil } var coderSint32Ptr = pointerCoderFuncs{ @@ -904,34 +923,36 @@ func appendSint32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([ } // consumeSint32Slice wire decodes a []int32 pointer as a repeated Sint32. -func consumeSint32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeSint32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.Int32Slice() if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, int32(wire.DecodeZigZag(v&math.MaxUint32))) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, int32(wire.DecodeZigZag(v&math.MaxUint32))) - return n, nil + out.n = n + return out, nil } var coderSint32Slice = pointerCoderFuncs{ @@ -990,15 +1011,16 @@ func appendSint32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshal } // consumeSint32Value decodes a int32 value as a Sint32. -func consumeSint32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeSint32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32))), n, nil + out.n = n + return protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32))), out, nil } var coderSint32Value = valueCoderFuncs{ @@ -1029,32 +1051,34 @@ func appendSint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, } // consumeSint32SliceValue wire decodes a []int32 value as a repeated Sint32. -func consumeSint32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeSint32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32)))) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32)))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderSint32SliceValue = valueCoderFuncs{ @@ -1120,16 +1144,17 @@ func appendUint32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte } // consumeUint32 wire decodes a uint32 pointer as a Uint32. -func consumeUint32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeUint32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Uint32() = uint32(v) - return n, nil + out.n = n + return out, nil } var coderUint32 = pointerCoderFuncs{ @@ -1183,20 +1208,21 @@ func appendUint32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]b } // consumeUint32Ptr wire decodes a *uint32 pointer as a Uint32. -func consumeUint32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeUint32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.Uint32Ptr() if *vp == nil { *vp = new(uint32) } **vp = uint32(v) - return n, nil + out.n = n + return out, nil } var coderUint32Ptr = pointerCoderFuncs{ @@ -1225,34 +1251,36 @@ func appendUint32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([ } // consumeUint32Slice wire decodes a []uint32 pointer as a repeated Uint32. -func consumeUint32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeUint32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.Uint32Slice() if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, uint32(v)) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, uint32(v)) - return n, nil + out.n = n + return out, nil } var coderUint32Slice = pointerCoderFuncs{ @@ -1311,15 +1339,16 @@ func appendUint32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshal } // consumeUint32Value decodes a uint32 value as a Uint32. -func consumeUint32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeUint32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfUint32(uint32(v)), n, nil + out.n = n + return protoreflect.ValueOfUint32(uint32(v)), out, nil } var coderUint32Value = valueCoderFuncs{ @@ -1350,32 +1379,34 @@ func appendUint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, } // consumeUint32SliceValue wire decodes a []uint32 value as a repeated Uint32. -func consumeUint32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeUint32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfUint32(uint32(v))) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfUint32(uint32(v))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderUint32SliceValue = valueCoderFuncs{ @@ -1441,16 +1472,17 @@ func appendInt64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, } // consumeInt64 wire decodes a int64 pointer as a Int64. -func consumeInt64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeInt64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Int64() = int64(v) - return n, nil + out.n = n + return out, nil } var coderInt64 = pointerCoderFuncs{ @@ -1504,20 +1536,21 @@ func appendInt64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]by } // consumeInt64Ptr wire decodes a *int64 pointer as a Int64. -func consumeInt64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeInt64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.Int64Ptr() if *vp == nil { *vp = new(int64) } **vp = int64(v) - return n, nil + out.n = n + return out, nil } var coderInt64Ptr = pointerCoderFuncs{ @@ -1546,34 +1579,36 @@ func appendInt64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([] } // consumeInt64Slice wire decodes a []int64 pointer as a repeated Int64. -func consumeInt64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeInt64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.Int64Slice() if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, int64(v)) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, int64(v)) - return n, nil + out.n = n + return out, nil } var coderInt64Slice = pointerCoderFuncs{ @@ -1632,15 +1667,16 @@ func appendInt64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalO } // consumeInt64Value decodes a int64 value as a Int64. -func consumeInt64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeInt64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfInt64(int64(v)), n, nil + out.n = n + return protoreflect.ValueOfInt64(int64(v)), out, nil } var coderInt64Value = valueCoderFuncs{ @@ -1671,32 +1707,34 @@ func appendInt64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ } // consumeInt64SliceValue wire decodes a []int64 value as a repeated Int64. -func consumeInt64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeInt64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfInt64(int64(v))) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfInt64(int64(v))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderInt64SliceValue = valueCoderFuncs{ @@ -1762,16 +1800,17 @@ func appendSint64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte } // consumeSint64 wire decodes a int64 pointer as a Sint64. -func consumeSint64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeSint64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Int64() = wire.DecodeZigZag(v) - return n, nil + out.n = n + return out, nil } var coderSint64 = pointerCoderFuncs{ @@ -1825,20 +1864,21 @@ func appendSint64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]b } // consumeSint64Ptr wire decodes a *int64 pointer as a Sint64. -func consumeSint64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeSint64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.Int64Ptr() if *vp == nil { *vp = new(int64) } **vp = wire.DecodeZigZag(v) - return n, nil + out.n = n + return out, nil } var coderSint64Ptr = pointerCoderFuncs{ @@ -1867,34 +1907,36 @@ func appendSint64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([ } // consumeSint64Slice wire decodes a []int64 pointer as a repeated Sint64. -func consumeSint64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeSint64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.Int64Slice() if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, wire.DecodeZigZag(v)) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, wire.DecodeZigZag(v)) - return n, nil + out.n = n + return out, nil } var coderSint64Slice = pointerCoderFuncs{ @@ -1953,15 +1995,16 @@ func appendSint64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshal } // consumeSint64Value decodes a int64 value as a Sint64. -func consumeSint64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeSint64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfInt64(wire.DecodeZigZag(v)), n, nil + out.n = n + return protoreflect.ValueOfInt64(wire.DecodeZigZag(v)), out, nil } var coderSint64Value = valueCoderFuncs{ @@ -1992,32 +2035,34 @@ func appendSint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, } // consumeSint64SliceValue wire decodes a []int64 value as a repeated Sint64. -func consumeSint64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeSint64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfInt64(wire.DecodeZigZag(v))) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfInt64(wire.DecodeZigZag(v))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderSint64SliceValue = valueCoderFuncs{ @@ -2083,16 +2128,17 @@ func appendUint64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte } // consumeUint64 wire decodes a uint64 pointer as a Uint64. -func consumeUint64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeUint64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Uint64() = v - return n, nil + out.n = n + return out, nil } var coderUint64 = pointerCoderFuncs{ @@ -2146,20 +2192,21 @@ func appendUint64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]b } // consumeUint64Ptr wire decodes a *uint64 pointer as a Uint64. -func consumeUint64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeUint64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.Uint64Ptr() if *vp == nil { *vp = new(uint64) } **vp = v - return n, nil + out.n = n + return out, nil } var coderUint64Ptr = pointerCoderFuncs{ @@ -2188,34 +2235,36 @@ func appendUint64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([ } // consumeUint64Slice wire decodes a []uint64 pointer as a repeated Uint64. -func consumeUint64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeUint64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.Uint64Slice() if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, v) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, v) - return n, nil + out.n = n + return out, nil } var coderUint64Slice = pointerCoderFuncs{ @@ -2274,15 +2323,16 @@ func appendUint64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshal } // consumeUint64Value decodes a uint64 value as a Uint64. -func consumeUint64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeUint64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfUint64(v), n, nil + out.n = n + return protoreflect.ValueOfUint64(v), out, nil } var coderUint64Value = valueCoderFuncs{ @@ -2313,32 +2363,34 @@ func appendUint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, } // consumeUint64SliceValue wire decodes a []uint64 value as a repeated Uint64. -func consumeUint64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeUint64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfUint64(v)) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.VarintType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfUint64(v)) - return listv, n, nil + out.n = n + return listv, out, nil } var coderUint64SliceValue = valueCoderFuncs{ @@ -2404,16 +2456,17 @@ func appendSfixed32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]by } // consumeSfixed32 wire decodes a int32 pointer as a Sfixed32. -func consumeSfixed32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeSfixed32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.Fixed32Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Int32() = int32(v) - return n, nil + out.n = n + return out, nil } var coderSfixed32 = pointerCoderFuncs{ @@ -2466,20 +2519,21 @@ func appendSfixed32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([ } // consumeSfixed32Ptr wire decodes a *int32 pointer as a Sfixed32. -func consumeSfixed32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeSfixed32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.Fixed32Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.Int32Ptr() if *vp == nil { *vp = new(int32) } **vp = int32(v) - return n, nil + out.n = n + return out, nil } var coderSfixed32Ptr = pointerCoderFuncs{ @@ -2506,34 +2560,36 @@ func appendSfixed32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) } // consumeSfixed32Slice wire decodes a []int32 pointer as a repeated Sfixed32. -func consumeSfixed32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeSfixed32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.Int32Slice() if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeFixed32(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, int32(v)) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } if wtyp != wire.Fixed32Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, int32(v)) - return n, nil + out.n = n + return out, nil } var coderSfixed32Slice = pointerCoderFuncs{ @@ -2586,15 +2642,16 @@ func appendSfixed32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marsh } // consumeSfixed32Value decodes a int32 value as a Sfixed32. -func consumeSfixed32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeSfixed32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.Fixed32Type { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfInt32(int32(v)), n, nil + out.n = n + return protoreflect.ValueOfInt32(int32(v)), out, nil } var coderSfixed32Value = valueCoderFuncs{ @@ -2622,32 +2679,34 @@ func appendSfixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64 } // consumeSfixed32SliceValue wire decodes a []int32 value as a repeated Sfixed32. -func consumeSfixed32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeSfixed32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeFixed32(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfInt32(int32(v))) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.Fixed32Type { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfInt32(int32(v))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderSfixed32SliceValue = valueCoderFuncs{ @@ -2705,16 +2764,17 @@ func appendFixed32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byt } // consumeFixed32 wire decodes a uint32 pointer as a Fixed32. -func consumeFixed32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeFixed32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.Fixed32Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Uint32() = v - return n, nil + out.n = n + return out, nil } var coderFixed32 = pointerCoderFuncs{ @@ -2767,20 +2827,21 @@ func appendFixed32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([] } // consumeFixed32Ptr wire decodes a *uint32 pointer as a Fixed32. -func consumeFixed32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeFixed32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.Fixed32Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.Uint32Ptr() if *vp == nil { *vp = new(uint32) } **vp = v - return n, nil + out.n = n + return out, nil } var coderFixed32Ptr = pointerCoderFuncs{ @@ -2807,34 +2868,36 @@ func appendFixed32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ( } // consumeFixed32Slice wire decodes a []uint32 pointer as a repeated Fixed32. -func consumeFixed32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeFixed32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.Uint32Slice() if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeFixed32(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, v) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } if wtyp != wire.Fixed32Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, v) - return n, nil + out.n = n + return out, nil } var coderFixed32Slice = pointerCoderFuncs{ @@ -2887,15 +2950,16 @@ func appendFixed32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marsha } // consumeFixed32Value decodes a uint32 value as a Fixed32. -func consumeFixed32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeFixed32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.Fixed32Type { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfUint32(uint32(v)), n, nil + out.n = n + return protoreflect.ValueOfUint32(uint32(v)), out, nil } var coderFixed32Value = valueCoderFuncs{ @@ -2923,32 +2987,34 @@ func appendFixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, } // consumeFixed32SliceValue wire decodes a []uint32 value as a repeated Fixed32. -func consumeFixed32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeFixed32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeFixed32(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfUint32(uint32(v))) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.Fixed32Type { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfUint32(uint32(v))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderFixed32SliceValue = valueCoderFuncs{ @@ -3006,16 +3072,17 @@ func appendFloat(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, } // consumeFloat wire decodes a float32 pointer as a Float. -func consumeFloat(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeFloat(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.Fixed32Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Float32() = math.Float32frombits(v) - return n, nil + out.n = n + return out, nil } var coderFloat = pointerCoderFuncs{ @@ -3068,20 +3135,21 @@ func appendFloatPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]by } // consumeFloatPtr wire decodes a *float32 pointer as a Float. -func consumeFloatPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeFloatPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.Fixed32Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.Float32Ptr() if *vp == nil { *vp = new(float32) } **vp = math.Float32frombits(v) - return n, nil + out.n = n + return out, nil } var coderFloatPtr = pointerCoderFuncs{ @@ -3108,34 +3176,36 @@ func appendFloatSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([] } // consumeFloatSlice wire decodes a []float32 pointer as a repeated Float. -func consumeFloatSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeFloatSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.Float32Slice() if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeFixed32(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, math.Float32frombits(v)) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } if wtyp != wire.Fixed32Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, math.Float32frombits(v)) - return n, nil + out.n = n + return out, nil } var coderFloatSlice = pointerCoderFuncs{ @@ -3188,15 +3258,16 @@ func appendFloatValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalO } // consumeFloatValue decodes a float32 value as a Float. -func consumeFloatValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeFloatValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.Fixed32Type { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))), n, nil + out.n = n + return protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))), out, nil } var coderFloatValue = valueCoderFuncs{ @@ -3224,32 +3295,34 @@ func appendFloatSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ } // consumeFloatSliceValue wire decodes a []float32 value as a repeated Float. -func consumeFloatSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeFloatSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeFixed32(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v)))) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.Fixed32Type { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeFixed32(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v)))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderFloatSliceValue = valueCoderFuncs{ @@ -3307,16 +3380,17 @@ func appendSfixed64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]by } // consumeSfixed64 wire decodes a int64 pointer as a Sfixed64. -func consumeSfixed64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeSfixed64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.Fixed64Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Int64() = int64(v) - return n, nil + out.n = n + return out, nil } var coderSfixed64 = pointerCoderFuncs{ @@ -3369,20 +3443,21 @@ func appendSfixed64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([ } // consumeSfixed64Ptr wire decodes a *int64 pointer as a Sfixed64. -func consumeSfixed64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeSfixed64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.Fixed64Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.Int64Ptr() if *vp == nil { *vp = new(int64) } **vp = int64(v) - return n, nil + out.n = n + return out, nil } var coderSfixed64Ptr = pointerCoderFuncs{ @@ -3409,34 +3484,36 @@ func appendSfixed64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) } // consumeSfixed64Slice wire decodes a []int64 pointer as a repeated Sfixed64. -func consumeSfixed64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeSfixed64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.Int64Slice() if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeFixed64(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, int64(v)) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } if wtyp != wire.Fixed64Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, int64(v)) - return n, nil + out.n = n + return out, nil } var coderSfixed64Slice = pointerCoderFuncs{ @@ -3489,15 +3566,16 @@ func appendSfixed64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marsh } // consumeSfixed64Value decodes a int64 value as a Sfixed64. -func consumeSfixed64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeSfixed64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.Fixed64Type { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfInt64(int64(v)), n, nil + out.n = n + return protoreflect.ValueOfInt64(int64(v)), out, nil } var coderSfixed64Value = valueCoderFuncs{ @@ -3525,32 +3603,34 @@ func appendSfixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64 } // consumeSfixed64SliceValue wire decodes a []int64 value as a repeated Sfixed64. -func consumeSfixed64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeSfixed64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeFixed64(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfInt64(int64(v))) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.Fixed64Type { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfInt64(int64(v))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderSfixed64SliceValue = valueCoderFuncs{ @@ -3608,16 +3688,17 @@ func appendFixed64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byt } // consumeFixed64 wire decodes a uint64 pointer as a Fixed64. -func consumeFixed64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeFixed64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.Fixed64Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Uint64() = v - return n, nil + out.n = n + return out, nil } var coderFixed64 = pointerCoderFuncs{ @@ -3670,20 +3751,21 @@ func appendFixed64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([] } // consumeFixed64Ptr wire decodes a *uint64 pointer as a Fixed64. -func consumeFixed64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeFixed64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.Fixed64Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.Uint64Ptr() if *vp == nil { *vp = new(uint64) } **vp = v - return n, nil + out.n = n + return out, nil } var coderFixed64Ptr = pointerCoderFuncs{ @@ -3710,34 +3792,36 @@ func appendFixed64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ( } // consumeFixed64Slice wire decodes a []uint64 pointer as a repeated Fixed64. -func consumeFixed64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeFixed64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.Uint64Slice() if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeFixed64(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, v) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } if wtyp != wire.Fixed64Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, v) - return n, nil + out.n = n + return out, nil } var coderFixed64Slice = pointerCoderFuncs{ @@ -3790,15 +3874,16 @@ func appendFixed64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marsha } // consumeFixed64Value decodes a uint64 value as a Fixed64. -func consumeFixed64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeFixed64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.Fixed64Type { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfUint64(v), n, nil + out.n = n + return protoreflect.ValueOfUint64(v), out, nil } var coderFixed64Value = valueCoderFuncs{ @@ -3826,32 +3911,34 @@ func appendFixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, } // consumeFixed64SliceValue wire decodes a []uint64 value as a repeated Fixed64. -func consumeFixed64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeFixed64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeFixed64(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfUint64(v)) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.Fixed64Type { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfUint64(v)) - return listv, n, nil + out.n = n + return listv, out, nil } var coderFixed64SliceValue = valueCoderFuncs{ @@ -3909,16 +3996,17 @@ func appendDouble(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte } // consumeDouble wire decodes a float64 pointer as a Double. -func consumeDouble(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeDouble(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.Fixed64Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Float64() = math.Float64frombits(v) - return n, nil + out.n = n + return out, nil } var coderDouble = pointerCoderFuncs{ @@ -3971,20 +4059,21 @@ func appendDoublePtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]b } // consumeDoublePtr wire decodes a *float64 pointer as a Double. -func consumeDoublePtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeDoublePtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.Fixed64Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.Float64Ptr() if *vp == nil { *vp = new(float64) } **vp = math.Float64frombits(v) - return n, nil + out.n = n + return out, nil } var coderDoublePtr = pointerCoderFuncs{ @@ -4011,34 +4100,36 @@ func appendDoubleSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([ } // consumeDoubleSlice wire decodes a []float64 pointer as a repeated Double. -func consumeDoubleSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeDoubleSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.Float64Slice() if wtyp == wire.BytesType { s := *sp - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeFixed64(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } s = append(s, math.Float64frombits(v)) b = b[n:] } *sp = s - return n, nil + out.n = n + return out, nil } if wtyp != wire.Fixed64Type { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, math.Float64frombits(v)) - return n, nil + out.n = n + return out, nil } var coderDoubleSlice = pointerCoderFuncs{ @@ -4091,15 +4182,16 @@ func appendDoubleValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshal } // consumeDoubleValue decodes a float64 value as a Double. -func consumeDoubleValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeDoubleValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.Fixed64Type { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfFloat64(math.Float64frombits(v)), n, nil + out.n = n + return protoreflect.ValueOfFloat64(math.Float64frombits(v)), out, nil } var coderDoubleValue = valueCoderFuncs{ @@ -4127,32 +4219,34 @@ func appendDoubleSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, } // consumeDoubleSliceValue wire decodes a []float64 value as a repeated Double. -func consumeDoubleSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeDoubleSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeFixed64(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v))) b = b[n:] } - return listv, n, nil + out.n = n + return listv, out, nil } if wtyp != wire.Fixed64Type { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeFixed64(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderDoubleSliceValue = valueCoderFuncs{ @@ -4210,16 +4304,17 @@ func appendString(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte } // consumeString wire decodes a string pointer as a String. -func consumeString(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeString(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeString(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.String() = v - return n, nil + out.n = n + return out, nil } var coderString = pointerCoderFuncs{ @@ -4240,19 +4335,20 @@ func appendStringValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOpti } // consumeStringValidateUTF8 wire decodes a string pointer as a String. -func consumeStringValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeStringValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeString(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if !utf8.ValidString(v) { - return 0, errInvalidUTF8{} + return out, errInvalidUTF8{} } *p.String() = v - return n, nil + out.n = n + return out, nil } var coderStringValidateUTF8 = pointerCoderFuncs{ @@ -4327,20 +4423,21 @@ func appendStringPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]b } // consumeStringPtr wire decodes a *string pointer as a String. -func consumeStringPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeStringPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeString(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } vp := p.StringPtr() if *vp == nil { *vp = new(string) } **vp = v - return n, nil + out.n = n + return out, nil } var coderStringPtr = pointerCoderFuncs{ @@ -4369,17 +4466,18 @@ func appendStringSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([ } // consumeStringSlice wire decodes a []string pointer as a repeated String. -func consumeStringSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeStringSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.StringSlice() if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeString(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, v) - return n, nil + out.n = n + return out, nil } var coderStringSlice = pointerCoderFuncs{ @@ -4402,20 +4500,21 @@ func appendStringSliceValidateUTF8(b []byte, p pointer, wiretag uint64, _ marsha } // consumeStringSliceValidateUTF8 wire decodes a []string pointer as a repeated String. -func consumeStringSliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeStringSliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.StringSlice() if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeString(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if !utf8.ValidString(v) { - return 0, errInvalidUTF8{} + return out, errInvalidUTF8{} } *sp = append(*sp, v) - return n, nil + out.n = n + return out, nil } var coderStringSliceValidateUTF8 = pointerCoderFuncs{ @@ -4437,15 +4536,16 @@ func appendStringValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshal } // consumeStringValue decodes a string value as a String. -func consumeStringValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeStringValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeString(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfString(string(v)), n, nil + out.n = n + return protoreflect.ValueOfString(string(v)), out, nil } var coderStringValue = valueCoderFuncs{ @@ -4465,18 +4565,19 @@ func appendStringValueValidateUTF8(b []byte, v protoreflect.Value, wiretag uint6 } // consumeStringValueValidateUTF8 decodes a string value as a String. -func consumeStringValueValidateUTF8(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeStringValueValidateUTF8(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeString(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } if !utf8.ValidString(v) { - return protoreflect.Value{}, 0, errInvalidUTF8{} + return protoreflect.Value{}, out, errInvalidUTF8{} } - return protoreflect.ValueOfString(string(v)), n, nil + out.n = n + return protoreflect.ValueOfString(string(v)), out, nil } var coderStringValueValidateUTF8 = valueCoderFuncs{ @@ -4507,17 +4608,18 @@ func appendStringSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, } // consumeStringSliceValue wire decodes a []string value as a repeated String. -func consumeStringSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeStringSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp != wire.BytesType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeString(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfString(string(v))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderStringSliceValue = valueCoderFuncs{ @@ -4541,16 +4643,17 @@ func appendBytes(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, } // consumeBytes wire decodes a []byte pointer as a Bytes. -func consumeBytes(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeBytes(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Bytes() = append(emptyBuf[:], v...) - return n, nil + out.n = n + return out, nil } var coderBytes = pointerCoderFuncs{ @@ -4571,19 +4674,20 @@ func appendBytesValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptio } // consumeBytesValidateUTF8 wire decodes a []byte pointer as a Bytes. -func consumeBytesValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeBytesValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if !utf8.Valid(v) { - return 0, errInvalidUTF8{} + return out, errInvalidUTF8{} } *p.Bytes() = append(emptyBuf[:], v...) - return n, nil + out.n = n + return out, nil } var coderBytesValidateUTF8 = pointerCoderFuncs{ @@ -4616,16 +4720,17 @@ func appendBytesNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([ // consumeBytesNoZero wire decodes a []byte pointer as a Bytes. // The zero value is not decoded. -func consumeBytesNoZero(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeBytesNoZero(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *p.Bytes() = append(([]byte)(nil), v...) - return n, nil + out.n = n + return out, nil } var coderBytesNoZero = pointerCoderFuncs{ @@ -4650,19 +4755,20 @@ func appendBytesNoZeroValidateUTF8(b []byte, p pointer, wiretag uint64, _ marsha } // consumeBytesNoZeroValidateUTF8 wire decodes a []byte pointer as a Bytes. -func consumeBytesNoZeroValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeBytesNoZeroValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if !utf8.Valid(v) { - return 0, errInvalidUTF8{} + return out, errInvalidUTF8{} } *p.Bytes() = append(([]byte)(nil), v...) - return n, nil + out.n = n + return out, nil } var coderBytesNoZeroValidateUTF8 = pointerCoderFuncs{ @@ -4691,17 +4797,18 @@ func appendBytesSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([] } // consumeBytesSlice wire decodes a [][]byte pointer as a repeated Bytes. -func consumeBytesSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeBytesSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.BytesSlice() if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } *sp = append(*sp, append(emptyBuf[:], v...)) - return n, nil + out.n = n + return out, nil } var coderBytesSlice = pointerCoderFuncs{ @@ -4724,20 +4831,21 @@ func appendBytesSliceValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshal } // consumeBytesSliceValidateUTF8 wire decodes a [][]byte pointer as a repeated Bytes. -func consumeBytesSliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeBytesSliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { sp := p.BytesSlice() if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if !utf8.Valid(v) { - return 0, errInvalidUTF8{} + return out, errInvalidUTF8{} } *sp = append(*sp, append(emptyBuf[:], v...)) - return n, nil + out.n = n + return out, nil } var coderBytesSliceValidateUTF8 = pointerCoderFuncs{ @@ -4759,15 +4867,16 @@ func appendBytesValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalO } // consumeBytesValue decodes a []byte value as a Bytes. -func consumeBytesValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { +func consumeBytesValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } - return protoreflect.ValueOfBytes(append(emptyBuf[:], v...)), n, nil + out.n = n + return protoreflect.ValueOfBytes(append(emptyBuf[:], v...)), out, nil } var coderBytesValue = valueCoderFuncs{ @@ -4798,17 +4907,18 @@ func appendBytesSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ } // consumeBytesSliceValue wire decodes a [][]byte value as a repeated Bytes. -func consumeBytesSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { +func consumeBytesSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, out unmarshalOutput, err error) { list := listv.List() if wtyp != wire.BytesType { - return protoreflect.Value{}, 0, errUnknown + return protoreflect.Value{}, out, errUnknown } v, n := wire.ConsumeBytes(b) if n < 0 { - return protoreflect.Value{}, 0, wire.ParseError(n) + return protoreflect.Value{}, out, wire.ParseError(n) } list.Append(protoreflect.ValueOfBytes(append(emptyBuf[:], v...))) - return listv, n, nil + out.n = n + return listv, out, nil } var coderBytesSliceValue = valueCoderFuncs{ diff --git a/internal/impl/codec_map.go b/internal/impl/codec_map.go index 05d1ecd1..b69ee1aa 100644 --- a/internal/impl/codec_map.go +++ b/internal/impl/codec_map.go @@ -56,7 +56,7 @@ func encoderFuncsForMap(fd pref.FieldDescriptor, ft reflect.Type) (funcs pointer marshal: func(b []byte, p pointer, wiretag uint64, opts marshalOptions) ([]byte, error) { return appendMap(b, p.AsValueOf(ft).Elem(), wiretag, mapi, opts) }, - unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (int, error) { + unmarshal: func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (unmarshalOutput, error) { mp := p.AsValueOf(ft) if mp.Elem().IsNil() { mp.Elem().Set(reflect.MakeMap(mapi.goType)) @@ -104,13 +104,13 @@ func sizeMap(mapv reflect.Value, tagsize int, mapi *mapInfo, opts marshalOptions return n } -func consumeMap(b []byte, mapv reflect.Value, wtyp wire.Type, mapi *mapInfo, opts unmarshalOptions) (int, error) { +func consumeMap(b []byte, mapv reflect.Value, wtyp wire.Type, mapi *mapInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } var ( key = mapi.keyZero @@ -119,50 +119,55 @@ func consumeMap(b []byte, mapv reflect.Value, wtyp wire.Type, mapi *mapInfo, opt for len(b) > 0 { num, wtyp, n := wire.ConsumeTag(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if num > wire.MaxValidNumber { - return 0, errors.New("invalid field number") + return out, errors.New("invalid field number") } b = b[n:] err := errUnknown switch num { case 1: var v pref.Value - v, n, err = mapi.keyFuncs.unmarshal(b, key, num, wtyp, opts) + var o unmarshalOutput + v, o, err = mapi.keyFuncs.unmarshal(b, key, num, wtyp, opts) if err != nil { break } key = v + n = o.n case 2: var v pref.Value - v, n, err = mapi.valFuncs.unmarshal(b, val, num, wtyp, opts) + var o unmarshalOutput + v, o, err = mapi.valFuncs.unmarshal(b, val, num, wtyp, opts) if err != nil { break } val = v + n = o.n } if err == errUnknown { n = wire.ConsumeFieldValue(num, wtyp, b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } } else if err != nil { - return 0, err + return out, err } b = b[n:] } mapv.SetMapIndex(mapi.conv.keyConv.GoValueOf(key), mapi.conv.valConv.GoValueOf(val)) - return n, nil + out.n = n + return out, nil } -func consumeMapOfMessage(b []byte, mapv reflect.Value, wtyp wire.Type, mapi *mapInfo, opts unmarshalOptions) (int, error) { +func consumeMapOfMessage(b []byte, mapv reflect.Value, wtyp wire.Type, mapi *mapInfo, opts unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.BytesType { - return 0, errUnknown + return out, errUnknown } b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } var ( key = mapi.keyZero @@ -171,21 +176,23 @@ func consumeMapOfMessage(b []byte, mapv reflect.Value, wtyp wire.Type, mapi *map for len(b) > 0 { num, wtyp, n := wire.ConsumeTag(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if num > wire.MaxValidNumber { - return 0, errors.New("invalid field number") + return out, errors.New("invalid field number") } b = b[n:] err := errUnknown switch num { case 1: var v pref.Value - v, n, err = mapi.keyFuncs.unmarshal(b, key, num, wtyp, opts) + var o unmarshalOutput + v, o, err = mapi.keyFuncs.unmarshal(b, key, num, wtyp, opts) if err != nil { break } key = v + n = o.n case 2: if wtyp != wire.BytesType { break @@ -193,22 +200,23 @@ func consumeMapOfMessage(b []byte, mapv reflect.Value, wtyp wire.Type, mapi *map var v []byte v, n = wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } _, err = mapi.valMessageInfo.unmarshalPointer(v, pointerOfValue(val), 0, opts) } if err == errUnknown { n = wire.ConsumeFieldValue(num, wtyp, b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } } else if err != nil { - return 0, err + return out, err } b = b[n:] } mapv.SetMapIndex(mapi.conv.keyConv.GoValueOf(key), val) - return n, nil + out.n = n + return out, nil } func appendMapItem(b []byte, keyrv, valrv reflect.Value, mapi *mapInfo, opts marshalOptions) ([]byte, error) { diff --git a/internal/impl/codec_messageset.go b/internal/impl/codec_messageset.go index e917c7c7..16bc3dc4 100644 --- a/internal/impl/codec_messageset.go +++ b/internal/impl/codec_messageset.go @@ -90,9 +90,9 @@ func marshalMessageSetField(mi *MessageInfo, b []byte, x ExtensionField, opts ma return b, nil } -func unmarshalMessageSet(mi *MessageInfo, b []byte, p pointer, opts unmarshalOptions) (int, error) { +func unmarshalMessageSet(mi *MessageInfo, b []byte, p pointer, opts unmarshalOptions) (out unmarshalOutput, err error) { if !flags.ProtoLegacy { - return 0, errors.New("no support for message_set_wire_format") + return out, errors.New("no support for message_set_wire_format") } ep := p.Apply(mi.extensionOffset).Extensions() @@ -101,7 +101,7 @@ func unmarshalMessageSet(mi *MessageInfo, b []byte, p pointer, opts unmarshalOpt } ext := *ep unknown := p.Apply(mi.unknownOffset).Bytes() - err := messageset.Unmarshal(b, true, func(num wire.Number, v []byte) error { + err = messageset.Unmarshal(b, true, func(num wire.Number, v []byte) error { _, err := mi.unmarshalExtension(v, num, wire.BytesType, ext, opts) if err == errUnknown { *unknown = wire.AppendTag(*unknown, num, wire.BytesType) @@ -110,5 +110,6 @@ func unmarshalMessageSet(mi *MessageInfo, b []byte, p pointer, opts unmarshalOpt } return err }) - return len(b), err + out.n = len(b) + return out, err } diff --git a/internal/impl/codec_reflect.go b/internal/impl/codec_reflect.go index 5884ee41..75420d94 100644 --- a/internal/impl/codec_reflect.go +++ b/internal/impl/codec_reflect.go @@ -24,16 +24,17 @@ func appendEnum(b []byte, p pointer, wiretag uint64, opts marshalOptions) ([]byt return b, nil } -func consumeEnum(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { +func consumeEnum(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } p.v.Elem().SetInt(int64(v)) - return n, nil + out.n = n + return out, nil } var coderEnum = pointerCoderFuncs{ @@ -70,9 +71,9 @@ func appendEnumPtr(b []byte, p pointer, wiretag uint64, opts marshalOptions) ([] return appendEnum(b, pointer{p.v.Elem()}, wiretag, opts) } -func consumeEnumPtr(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (n int, err error) { +func consumeEnumPtr(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (out unmarshalOutput, err error) { if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } if p.v.Elem().IsNil() { p.v.Elem().Set(reflect.New(p.v.Elem().Type().Elem())) @@ -103,36 +104,38 @@ func appendEnumSlice(b []byte, p pointer, wiretag uint64, opts marshalOptions) ( return b, nil } -func consumeEnumSlice(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (n int, err error) { +func consumeEnumSlice(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (out unmarshalOutput, err error) { s := p.v.Elem() if wtyp == wire.BytesType { - b, n = wire.ConsumeBytes(b) + b, n := wire.ConsumeBytes(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } for len(b) > 0 { v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } rv := reflect.New(s.Type().Elem()).Elem() rv.SetInt(int64(v)) s.Set(reflect.Append(s, rv)) b = b[n:] } - return n, nil + out.n = n + return out, nil } if wtyp != wire.VarintType { - return 0, errUnknown + return out, errUnknown } v, n := wire.ConsumeVarint(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } rv := reflect.New(s.Type().Elem()).Elem() rv.SetInt(int64(v)) s.Set(reflect.Append(s, rv)) - return n, nil + out.n = n + return out, nil } var coderEnumSlice = pointerCoderFuncs{ diff --git a/internal/impl/codec_tables.go b/internal/impl/codec_tables.go index f421c782..38c4e7ef 100644 --- a/internal/impl/codec_tables.go +++ b/internal/impl/codec_tables.go @@ -17,7 +17,7 @@ import ( type pointerCoderFuncs struct { size func(p pointer, tagsize int, opts marshalOptions) int marshal func(b []byte, p pointer, wiretag uint64, opts marshalOptions) ([]byte, error) - unmarshal func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (int, error) + unmarshal func(b []byte, p pointer, wtyp wire.Type, opts unmarshalOptions) (unmarshalOutput, error) isInit func(p pointer) error } @@ -25,7 +25,7 @@ type pointerCoderFuncs struct { type valueCoderFuncs struct { size func(v pref.Value, tagsize int, opts marshalOptions) int marshal func(b []byte, v pref.Value, wiretag uint64, opts marshalOptions) ([]byte, error) - unmarshal func(b []byte, v pref.Value, num wire.Number, wtyp wire.Type, opts unmarshalOptions) (pref.Value, int, error) + unmarshal func(b []byte, v pref.Value, num wire.Number, wtyp wire.Type, opts unmarshalOptions) (pref.Value, unmarshalOutput, error) isInit func(v pref.Value) error } diff --git a/internal/impl/decode.go b/internal/impl/decode.go index 4d3718f7..84d31ac8 100644 --- a/internal/impl/decode.go +++ b/internal/impl/decode.go @@ -57,6 +57,10 @@ func (o unmarshalOptions) Options() proto.UnmarshalOptions { func (o unmarshalOptions) DiscardUnknown() bool { return o.flags&unmarshalDiscardUnknown != 0 } func (o unmarshalOptions) Resolver() preg.ExtensionTypeResolver { return o.resolver } +type unmarshalOutput struct { + n int // number of bytes consumed +} + // unmarshal is protoreflect.Methods.Unmarshal. func (mi *MessageInfo) unmarshal(m pref.Message, in piface.UnmarshalInput) (piface.UnmarshalOutput, error) { var p pointer @@ -77,7 +81,7 @@ func (mi *MessageInfo) unmarshal(m pref.Message, in piface.UnmarshalInput) (pifa // This is a sentinel error which should never be visible to the user. var errUnknown = errors.New("unknown") -func (mi *MessageInfo) unmarshalPointer(b []byte, p pointer, groupTag wire.Number, opts unmarshalOptions) (int, error) { +func (mi *MessageInfo) unmarshalPointer(b []byte, p pointer, groupTag wire.Number, opts unmarshalOptions) (out unmarshalOutput, err error) { mi.init() if flags.ProtoLegacy && mi.isMessageSet { return unmarshalMessageSet(mi, b, p, opts) @@ -89,18 +93,19 @@ func (mi *MessageInfo) unmarshalPointer(b []byte, p pointer, groupTag wire.Numbe // TODO: inline 1 and 2 byte variants? num, wtyp, n := wire.ConsumeTag(b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if num > wire.MaxValidNumber { - return 0, errors.New("invalid field number") + return out, errors.New("invalid field number") } b = b[n:] if wtyp == wire.EndGroupType { if num != groupTag { - return 0, errors.New("mismatching end group marker") + return out, errors.New("mismatching end group marker") } - return start - len(b), nil + out.n = start - len(b) + return out, nil } var f *coderFieldInfo @@ -115,7 +120,9 @@ func (mi *MessageInfo) unmarshalPointer(b []byte, p pointer, groupTag wire.Numbe if f.funcs.unmarshal == nil { break } - n, err = f.funcs.unmarshal(b, p.Apply(f.offset), wtyp, opts) + var o unmarshalOutput + o, err = f.funcs.unmarshal(b, p.Apply(f.offset), wtyp, opts) + n = o.n default: // Possible extension. if exts == nil && mi.extensionOffset.IsValid() { @@ -127,15 +134,17 @@ func (mi *MessageInfo) unmarshalPointer(b []byte, p pointer, groupTag wire.Numbe if exts == nil { break } - n, err = mi.unmarshalExtension(b, num, wtyp, *exts, opts) + var o unmarshalOutput + o, err = mi.unmarshalExtension(b, num, wtyp, *exts, opts) + n = o.n } if err != nil { if err != errUnknown { - return 0, err + return out, err } n = wire.ConsumeFieldValue(num, wtyp, b) if n < 0 { - return 0, wire.ParseError(n) + return out, wire.ParseError(n) } if mi.unknownOffset.IsValid() { u := p.Apply(mi.unknownOffset).Bytes() @@ -146,12 +155,13 @@ func (mi *MessageInfo) unmarshalPointer(b []byte, p pointer, groupTag wire.Numbe b = b[n:] } if groupTag != 0 { - return 0, errors.New("missing end group marker") + return out, errors.New("missing end group marker") } - return start, nil + out.n = start + return out, nil } -func (mi *MessageInfo) unmarshalExtension(b []byte, num wire.Number, wtyp wire.Type, exts map[int32]ExtensionField, opts unmarshalOptions) (n int, err error) { +func (mi *MessageInfo) unmarshalExtension(b []byte, num wire.Number, wtyp wire.Type, exts map[int32]ExtensionField, opts unmarshalOptions) (out unmarshalOutput, err error) { x := exts[int32(num)] xt := x.Type() if xt == nil { @@ -159,14 +169,14 @@ func (mi *MessageInfo) unmarshalExtension(b []byte, num wire.Number, wtyp wire.T xt, err = opts.Resolver().FindExtensionByNumber(mi.Desc.FullName(), num) if err != nil { if err == preg.NotFound { - return 0, errUnknown + return out, errUnknown } - return 0, err + return out, err } } xi := getExtensionFieldInfo(xt) if xi.funcs.unmarshal == nil { - return 0, errUnknown + return out, errUnknown } ival := x.Value() if !ival.IsValid() && xi.unmarshalNeedsValue { @@ -175,11 +185,11 @@ func (mi *MessageInfo) unmarshalExtension(b []byte, num wire.Number, wtyp wire.T // concrete type. ival = xt.New() } - v, n, err := xi.funcs.unmarshal(b, ival, num, wtyp, opts) + v, out, err := xi.funcs.unmarshal(b, ival, num, wtyp, opts) if err != nil { - return 0, err + return out, err } x.Set(xt, v) exts[int32(num)] = x - return n, nil + return out, nil }