mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-26 18:35:25 +00:00
all: return less-specific, but more informative wire unmarshal errors
When proto.Unmarshal fails, it is almost always due to being passed input which is not a wire-format message. (A text-format message, a message with framing left intact, and so forth.) An error like "variable length integer overflow" can be confusing in this case, since it implies the problem is the varint rather than the input being entirely wrong. Replace all Unmarshal parse errors with "cannot parse invalid wire-format data". Change-Id: Id97253bd39ac604e569df71778194f37b3c86c28 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/244297 Reviewed-by: Joe Tsai <joetsai@google.com>
This commit is contained in:
parent
28b807b56e
commit
b5523e32b3
@ -114,7 +114,7 @@ func consume{{.Name}}(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInf
|
||||
}
|
||||
{{template "Consume" .}}
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
*p.{{.GoType.PointerMethod}}() = {{.ToGoType}}
|
||||
out.n = n
|
||||
@ -147,7 +147,7 @@ func consume{{.Name}}ValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *c
|
||||
}
|
||||
{{template "Consume" .}}
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
if !utf8.Valid{{if eq .Name "String"}}String{{end}}(v) {
|
||||
return out, errInvalidUTF8{}
|
||||
@ -196,7 +196,7 @@ func consume{{.Name}}NoZero(b []byte, p pointer, wtyp protowire.Type, f *coderFi
|
||||
}
|
||||
{{template "Consume" .}}
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
*p.{{.GoType.PointerMethod}}() = {{.ToGoTypeNoZero}}
|
||||
out.n = n
|
||||
@ -235,7 +235,7 @@ func consume{{.Name}}NoZeroValidateUTF8(b []byte, p pointer, wtyp protowire.Type
|
||||
}
|
||||
{{template "Consume" .}}
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
if !utf8.Valid{{if eq .Name "String"}}String{{end}}(v) {
|
||||
return out, errInvalidUTF8{}
|
||||
@ -280,7 +280,7 @@ func consume{{.Name}}Ptr(b []byte, p pointer, wtyp protowire.Type, f *coderField
|
||||
}
|
||||
{{template "Consume" .}}
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
vp := p.{{.GoType.PointerMethod}}Ptr()
|
||||
if *vp == nil {
|
||||
@ -319,7 +319,7 @@ func consume{{.Name}}PtrValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f
|
||||
}
|
||||
{{template "Consume" .}}
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
if !utf8.Valid{{if eq .Name "String"}}String{{end}}(v) {
|
||||
return out, errInvalidUTF8{}
|
||||
@ -372,12 +372,12 @@ func consume{{.Name}}Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFie
|
||||
s := *sp
|
||||
b, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
for len(b) > 0 {
|
||||
{{template "Consume" .}}
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
s = append(s, {{.ToGoType}})
|
||||
b = b[n:]
|
||||
@ -392,7 +392,7 @@ func consume{{.Name}}Slice(b []byte, p pointer, wtyp protowire.Type, f *coderFie
|
||||
}
|
||||
{{template "Consume" .}}
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
*sp = append(*sp, {{.ToGoType}})
|
||||
out.n = n
|
||||
@ -428,7 +428,7 @@ func consume{{.Name}}SliceValidateUTF8(b []byte, p pointer, wtyp protowire.Type,
|
||||
}
|
||||
{{template "Consume" .}}
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
if !utf8.Valid{{if eq .Name "String"}}String{{end}}(v) {
|
||||
return out, errInvalidUTF8{}
|
||||
@ -516,7 +516,7 @@ func consume{{.Name}}Value(b []byte, _ protoreflect.Value, _ protowire.Number, w
|
||||
}
|
||||
{{template "Consume" .}}
|
||||
if n < 0 {
|
||||
return protoreflect.Value{}, out, protowire.ParseError(n)
|
||||
return protoreflect.Value{}, out, errDecode
|
||||
}
|
||||
out.n = n
|
||||
return {{.ToValue}}, out, nil
|
||||
@ -551,7 +551,7 @@ func consume{{.Name}}ValueValidateUTF8(b []byte, _ protoreflect.Value, _ protowi
|
||||
}
|
||||
{{template "Consume" .}}
|
||||
if n < 0 {
|
||||
return protoreflect.Value{}, out, protowire.ParseError(n)
|
||||
return protoreflect.Value{}, out, errDecode
|
||||
}
|
||||
if !utf8.ValidString(v) {
|
||||
return protoreflect.Value{}, out, errInvalidUTF8{}
|
||||
@ -600,12 +600,12 @@ func consume{{.Name}}SliceValue(b []byte, listv protoreflect.Value, _ protowire.
|
||||
if wtyp == protowire.BytesType {
|
||||
b, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return protoreflect.Value{}, out, protowire.ParseError(n)
|
||||
return protoreflect.Value{}, out, errDecode
|
||||
}
|
||||
for len(b) > 0 {
|
||||
{{template "Consume" .}}
|
||||
if n < 0 {
|
||||
return protoreflect.Value{}, out, protowire.ParseError(n)
|
||||
return protoreflect.Value{}, out, errDecode
|
||||
}
|
||||
list.Append({{.ToValue}})
|
||||
b = b[n:]
|
||||
@ -619,7 +619,7 @@ func consume{{.Name}}SliceValue(b []byte, listv protoreflect.Value, _ protowire.
|
||||
}
|
||||
{{template "Consume" .}}
|
||||
if n < 0 {
|
||||
return protoreflect.Value{}, out, protowire.ParseError(n)
|
||||
return protoreflect.Value{}, out, errDecode
|
||||
}
|
||||
list.Append({{.ToValue}})
|
||||
out.n = n
|
||||
|
@ -290,7 +290,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
v, n := protowire.Consume{{.WireType}}(b)
|
||||
{{- end}}
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
{{if (eq .Name "String") -}}
|
||||
if strs.EnforceUTF8(fd) && !utf8.Valid(v) {
|
||||
@ -312,12 +312,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.Consume{{.WireType}}(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append({{.ToValue}})
|
||||
@ -334,7 +334,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
v, n := protowire.Consume{{.WireType}}(b)
|
||||
{{- end}}
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
{{if (eq .Name "String") -}}
|
||||
if strs.EnforceUTF8(fd) && !utf8.Valid(v) {
|
||||
|
@ -242,7 +242,7 @@ func consumeMessageInfo(b []byte, p pointer, wtyp protowire.Type, f *coderFieldI
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
if p.Elem().IsNil() {
|
||||
p.SetPointer(pointerOfValue(reflect.New(f.mi.GoReflectType.Elem())))
|
||||
@ -276,7 +276,7 @@ func consumeMessage(b []byte, m proto.Message, wtyp protowire.Type, opts unmarsh
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
o, err := opts.Options().UnmarshalState(piface.UnmarshalInput{
|
||||
Buf: v,
|
||||
@ -420,7 +420,7 @@ func consumeGroup(b []byte, m proto.Message, num protowire.Number, wtyp protowir
|
||||
}
|
||||
b, n := protowire.ConsumeGroup(num, b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
o, err := opts.Options().UnmarshalState(piface.UnmarshalInput{
|
||||
Buf: b,
|
||||
@ -494,7 +494,7 @@ func consumeMessageSliceInfo(b []byte, p pointer, wtyp protowire.Type, f *coderF
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
m := reflect.New(f.mi.GoReflectType.Elem()).Interface()
|
||||
mp := pointerOfIface(m)
|
||||
@ -550,7 +550,7 @@ func consumeMessageSlice(b []byte, p pointer, goType reflect.Type, wtyp protowir
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
mp := reflect.New(goType.Elem())
|
||||
o, err := opts.Options().UnmarshalState(piface.UnmarshalInput{
|
||||
@ -613,7 +613,7 @@ func consumeMessageSliceValue(b []byte, listv pref.Value, _ protowire.Number, wt
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return pref.Value{}, out, protowire.ParseError(n)
|
||||
return pref.Value{}, out, errDecode
|
||||
}
|
||||
m := list.NewElement()
|
||||
o, err := opts.Options().UnmarshalState(piface.UnmarshalInput{
|
||||
@ -681,7 +681,7 @@ func consumeGroupSliceValue(b []byte, listv pref.Value, num protowire.Number, wt
|
||||
}
|
||||
b, n := protowire.ConsumeGroup(num, b)
|
||||
if n < 0 {
|
||||
return pref.Value{}, out, protowire.ParseError(n)
|
||||
return pref.Value{}, out, errDecode
|
||||
}
|
||||
m := list.NewElement()
|
||||
o, err := opts.Options().UnmarshalState(piface.UnmarshalInput{
|
||||
@ -767,7 +767,7 @@ func consumeGroupSlice(b []byte, p pointer, num protowire.Number, wtyp protowire
|
||||
}
|
||||
b, n := protowire.ConsumeGroup(num, b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
mp := reflect.New(goType.Elem())
|
||||
o, err := opts.Options().UnmarshalState(piface.UnmarshalInput{
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,6 @@
|
||||
package impl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"sort"
|
||||
|
||||
@ -118,7 +117,7 @@ func consumeMap(b []byte, mapv reflect.Value, wtyp protowire.Type, mapi *mapInfo
|
||||
}
|
||||
b, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
var (
|
||||
key = mapi.keyZero
|
||||
@ -127,10 +126,10 @@ func consumeMap(b []byte, mapv reflect.Value, wtyp protowire.Type, mapi *mapInfo
|
||||
for len(b) > 0 {
|
||||
num, wtyp, n := protowire.ConsumeTag(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
if num > protowire.MaxValidNumber {
|
||||
return out, errors.New("invalid field number")
|
||||
return out, errDecode
|
||||
}
|
||||
b = b[n:]
|
||||
err := errUnknown
|
||||
@ -157,7 +156,7 @@ func consumeMap(b []byte, mapv reflect.Value, wtyp protowire.Type, mapi *mapInfo
|
||||
if err == errUnknown {
|
||||
n = protowire.ConsumeFieldValue(num, wtyp, b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
} else if err != nil {
|
||||
return out, err
|
||||
@ -175,7 +174,7 @@ func consumeMapOfMessage(b []byte, mapv reflect.Value, wtyp protowire.Type, mapi
|
||||
}
|
||||
b, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
var (
|
||||
key = mapi.keyZero
|
||||
@ -184,10 +183,10 @@ func consumeMapOfMessage(b []byte, mapv reflect.Value, wtyp protowire.Type, mapi
|
||||
for len(b) > 0 {
|
||||
num, wtyp, n := protowire.ConsumeTag(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
if num > protowire.MaxValidNumber {
|
||||
return out, errors.New("invalid field number")
|
||||
return out, errDecode
|
||||
}
|
||||
b = b[n:]
|
||||
err := errUnknown
|
||||
@ -208,7 +207,7 @@ func consumeMapOfMessage(b []byte, mapv reflect.Value, wtyp protowire.Type, mapi
|
||||
var v []byte
|
||||
v, n = protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
var o unmarshalOutput
|
||||
o, err = f.mi.unmarshalPointer(v, pointerOfValue(val), 0, opts)
|
||||
@ -221,7 +220,7 @@ func consumeMapOfMessage(b []byte, mapv reflect.Value, wtyp protowire.Type, mapi
|
||||
if err == errUnknown {
|
||||
n = protowire.ConsumeFieldValue(num, wtyp, b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
} else if err != nil {
|
||||
return out, err
|
||||
|
@ -30,7 +30,7 @@ func consumeEnum(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, _
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
p.v.Elem().SetInt(int64(v))
|
||||
out.n = n
|
||||
@ -130,12 +130,12 @@ func consumeEnumSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInf
|
||||
if wtyp == protowire.BytesType {
|
||||
b, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
for len(b) > 0 {
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
rv := reflect.New(s.Type().Elem()).Elem()
|
||||
rv.SetInt(int64(v))
|
||||
@ -150,7 +150,7 @@ func consumeEnumSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInf
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
rv := reflect.New(s.Type().Elem()).Elem()
|
||||
rv.SetInt(int64(v))
|
||||
|
@ -17,6 +17,8 @@ import (
|
||||
piface "google.golang.org/protobuf/runtime/protoiface"
|
||||
)
|
||||
|
||||
var errDecode = errors.New("cannot parse invalid wire-format data")
|
||||
|
||||
type unmarshalOptions struct {
|
||||
flags protoiface.UnmarshalInputFlags
|
||||
resolver interface {
|
||||
@ -100,13 +102,13 @@ func (mi *MessageInfo) unmarshalPointer(b []byte, p pointer, groupTag protowire.
|
||||
var n int
|
||||
tag, n = protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
b = b[n:]
|
||||
}
|
||||
var num protowire.Number
|
||||
if n := tag >> 3; n < uint64(protowire.MinValidNumber) || n > uint64(protowire.MaxValidNumber) {
|
||||
return out, errors.New("invalid field number")
|
||||
return out, errDecode
|
||||
} else {
|
||||
num = protowire.Number(n)
|
||||
}
|
||||
@ -114,7 +116,7 @@ func (mi *MessageInfo) unmarshalPointer(b []byte, p pointer, groupTag protowire.
|
||||
|
||||
if wtyp == protowire.EndGroupType {
|
||||
if num != groupTag {
|
||||
return out, errors.New("mismatching end group marker")
|
||||
return out, errDecode
|
||||
}
|
||||
groupTag = 0
|
||||
break
|
||||
@ -170,7 +172,7 @@ func (mi *MessageInfo) unmarshalPointer(b []byte, p pointer, groupTag protowire.
|
||||
}
|
||||
n = protowire.ConsumeFieldValue(num, wtyp, b)
|
||||
if n < 0 {
|
||||
return out, protowire.ParseError(n)
|
||||
return out, errDecode
|
||||
}
|
||||
if !opts.DiscardUnknown() && mi.unknownOffset.IsValid() {
|
||||
u := p.Apply(mi.unknownOffset).Bytes()
|
||||
@ -181,7 +183,7 @@ func (mi *MessageInfo) unmarshalPointer(b []byte, p pointer, groupTag protowire.
|
||||
b = b[n:]
|
||||
}
|
||||
if groupTag != 0 {
|
||||
return out, errors.New("missing end group marker")
|
||||
return out, errDecode
|
||||
}
|
||||
if mi.numRequiredFields > 0 && bits.OnesCount64(requiredMask) != int(mi.numRequiredFields) {
|
||||
initialized = false
|
||||
@ -221,7 +223,7 @@ func (mi *MessageInfo) unmarshalExtension(b []byte, num protowire.Number, wtyp p
|
||||
return out, nil
|
||||
}
|
||||
case ValidationInvalid:
|
||||
return out, errors.New("invalid wire format")
|
||||
return out, errDecode
|
||||
case ValidationUnknown:
|
||||
}
|
||||
}
|
||||
|
@ -116,10 +116,10 @@ func (o UnmarshalOptions) unmarshalMessageSlow(b []byte, m protoreflect.Message)
|
||||
// Parse the tag (field number and wire type).
|
||||
num, wtyp, tagLen := protowire.ConsumeTag(b)
|
||||
if tagLen < 0 {
|
||||
return protowire.ParseError(tagLen)
|
||||
return errDecode
|
||||
}
|
||||
if num > protowire.MaxValidNumber {
|
||||
return errors.New("invalid field number")
|
||||
return errDecode
|
||||
}
|
||||
|
||||
// Find the field descriptor for this field number.
|
||||
@ -159,7 +159,7 @@ func (o UnmarshalOptions) unmarshalMessageSlow(b []byte, m protoreflect.Message)
|
||||
}
|
||||
valLen = protowire.ConsumeFieldValue(num, wtyp, b[tagLen:])
|
||||
if valLen < 0 {
|
||||
return protowire.ParseError(valLen)
|
||||
return errDecode
|
||||
}
|
||||
if !o.DiscardUnknown {
|
||||
m.SetUnknown(append(m.GetUnknown(), b[:tagLen+valLen]...))
|
||||
@ -194,7 +194,7 @@ func (o UnmarshalOptions) unmarshalMap(b []byte, wtyp protowire.Type, mapv proto
|
||||
}
|
||||
b, n = protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
var (
|
||||
keyField = fd.MapKey()
|
||||
@ -213,10 +213,10 @@ func (o UnmarshalOptions) unmarshalMap(b []byte, wtyp protowire.Type, mapv proto
|
||||
for len(b) > 0 {
|
||||
num, wtyp, n := protowire.ConsumeTag(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
if num > protowire.MaxValidNumber {
|
||||
return 0, errors.New("invalid field number")
|
||||
return 0, errDecode
|
||||
}
|
||||
b = b[n:]
|
||||
err = errUnknown
|
||||
@ -246,7 +246,7 @@ func (o UnmarshalOptions) unmarshalMap(b []byte, wtyp protowire.Type, mapv proto
|
||||
if err == errUnknown {
|
||||
n = protowire.ConsumeFieldValue(num, wtyp, b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
} else if err != nil {
|
||||
return 0, err
|
||||
@ -272,3 +272,5 @@ func (o UnmarshalOptions) unmarshalMap(b []byte, wtyp protowire.Type, mapv proto
|
||||
// to the unknown field set of a message. It is never returned from an exported
|
||||
// function.
|
||||
var errUnknown = errors.New("BUG: internal error (unknown)")
|
||||
|
||||
var errDecode = errors.New("cannot parse invalid wire-format data")
|
||||
|
@ -27,7 +27,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfBool(protowire.DecodeBool(v)), n, nil
|
||||
case protoreflect.EnumKind:
|
||||
@ -36,7 +36,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)), n, nil
|
||||
case protoreflect.Int32Kind:
|
||||
@ -45,7 +45,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfInt32(int32(v)), n, nil
|
||||
case protoreflect.Sint32Kind:
|
||||
@ -54,7 +54,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))), n, nil
|
||||
case protoreflect.Uint32Kind:
|
||||
@ -63,7 +63,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfUint32(uint32(v)), n, nil
|
||||
case protoreflect.Int64Kind:
|
||||
@ -72,7 +72,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfInt64(int64(v)), n, nil
|
||||
case protoreflect.Sint64Kind:
|
||||
@ -81,7 +81,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)), n, nil
|
||||
case protoreflect.Uint64Kind:
|
||||
@ -90,7 +90,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfUint64(v), n, nil
|
||||
case protoreflect.Sfixed32Kind:
|
||||
@ -99,7 +99,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeFixed32(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfInt32(int32(v)), n, nil
|
||||
case protoreflect.Fixed32Kind:
|
||||
@ -108,7 +108,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeFixed32(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfUint32(uint32(v)), n, nil
|
||||
case protoreflect.FloatKind:
|
||||
@ -117,7 +117,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeFixed32(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))), n, nil
|
||||
case protoreflect.Sfixed64Kind:
|
||||
@ -126,7 +126,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeFixed64(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfInt64(int64(v)), n, nil
|
||||
case protoreflect.Fixed64Kind:
|
||||
@ -135,7 +135,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeFixed64(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfUint64(v), n, nil
|
||||
case protoreflect.DoubleKind:
|
||||
@ -144,7 +144,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeFixed64(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfFloat64(math.Float64frombits(v)), n, nil
|
||||
case protoreflect.StringKind:
|
||||
@ -153,7 +153,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
if strs.EnforceUTF8(fd) && !utf8.Valid(v) {
|
||||
return protoreflect.Value{}, 0, errors.InvalidUTF8(string(fd.FullName()))
|
||||
@ -165,7 +165,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfBytes(append(emptyBuf[:], v...)), n, nil
|
||||
case protoreflect.MessageKind:
|
||||
@ -174,7 +174,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfBytes(v), n, nil
|
||||
case protoreflect.GroupKind:
|
||||
@ -183,7 +183,7 @@ func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp protowire.Type, fd prot
|
||||
}
|
||||
v, n := protowire.ConsumeGroup(fd.Number(), b)
|
||||
if n < 0 {
|
||||
return val, 0, protowire.ParseError(n)
|
||||
return val, 0, errDecode
|
||||
}
|
||||
return protoreflect.ValueOfBytes(v), n, nil
|
||||
default:
|
||||
@ -197,12 +197,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeVarint(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfBool(protowire.DecodeBool(v)))
|
||||
@ -214,7 +214,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfBool(protowire.DecodeBool(v)))
|
||||
return n, nil
|
||||
@ -222,12 +222,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeVarint(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
|
||||
@ -239,7 +239,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
|
||||
return n, nil
|
||||
@ -247,12 +247,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeVarint(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfInt32(int32(v)))
|
||||
@ -264,7 +264,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfInt32(int32(v)))
|
||||
return n, nil
|
||||
@ -272,12 +272,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeVarint(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))))
|
||||
@ -289,7 +289,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfInt32(int32(protowire.DecodeZigZag(v & math.MaxUint32))))
|
||||
return n, nil
|
||||
@ -297,12 +297,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeVarint(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfUint32(uint32(v)))
|
||||
@ -314,7 +314,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfUint32(uint32(v)))
|
||||
return n, nil
|
||||
@ -322,12 +322,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeVarint(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfInt64(int64(v)))
|
||||
@ -339,7 +339,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfInt64(int64(v)))
|
||||
return n, nil
|
||||
@ -347,12 +347,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeVarint(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)))
|
||||
@ -364,7 +364,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfInt64(protowire.DecodeZigZag(v)))
|
||||
return n, nil
|
||||
@ -372,12 +372,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeVarint(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfUint64(v))
|
||||
@ -389,7 +389,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfUint64(v))
|
||||
return n, nil
|
||||
@ -397,12 +397,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeFixed32(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfInt32(int32(v)))
|
||||
@ -414,7 +414,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeFixed32(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfInt32(int32(v)))
|
||||
return n, nil
|
||||
@ -422,12 +422,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeFixed32(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfUint32(uint32(v)))
|
||||
@ -439,7 +439,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeFixed32(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfUint32(uint32(v)))
|
||||
return n, nil
|
||||
@ -447,12 +447,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeFixed32(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
|
||||
@ -464,7 +464,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeFixed32(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
|
||||
return n, nil
|
||||
@ -472,12 +472,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeFixed64(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfInt64(int64(v)))
|
||||
@ -489,7 +489,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeFixed64(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfInt64(int64(v)))
|
||||
return n, nil
|
||||
@ -497,12 +497,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeFixed64(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfUint64(v))
|
||||
@ -514,7 +514,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeFixed64(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfUint64(v))
|
||||
return n, nil
|
||||
@ -522,12 +522,12 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
if wtyp == protowire.BytesType {
|
||||
buf, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
for len(buf) > 0 {
|
||||
v, n := protowire.ConsumeFixed64(buf)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
buf = buf[n:]
|
||||
list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
|
||||
@ -539,7 +539,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeFixed64(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
|
||||
return n, nil
|
||||
@ -549,7 +549,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
if strs.EnforceUTF8(fd) && !utf8.Valid(v) {
|
||||
return 0, errors.InvalidUTF8(string(fd.FullName()))
|
||||
@ -562,7 +562,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
list.Append(protoreflect.ValueOfBytes(append(emptyBuf[:], v...)))
|
||||
return n, nil
|
||||
@ -572,7 +572,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
m := list.NewElement()
|
||||
if err := o.unmarshalMessage(v, m.Message()); err != nil {
|
||||
@ -586,7 +586,7 @@ func (o UnmarshalOptions) unmarshalList(b []byte, wtyp protowire.Type, list prot
|
||||
}
|
||||
v, n := protowire.ConsumeGroup(fd.Number(), b)
|
||||
if n < 0 {
|
||||
return 0, protowire.ParseError(n)
|
||||
return 0, errDecode
|
||||
}
|
||||
m := list.NewElement()
|
||||
if err := o.unmarshalMessage(v, m.Message()); err != nil {
|
||||
|
@ -818,7 +818,7 @@ var testValidMessages = []testProto{
|
||||
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1156),
|
||||
}),
|
||||
protopack.Tag{71, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
protopack.Tag{1, protopack.BytesType}, protopack.String(0),
|
||||
protopack.Tag{1, protopack.BytesType}, protopack.String(""),
|
||||
protopack.Tag{2, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{}),
|
||||
protopack.Tag{1, protopack.BytesType}, protopack.String("71.1.key"),
|
||||
protopack.Tag{2, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
|
||||
|
Loading…
x
Reference in New Issue
Block a user