123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600 |
- // Copyright 2018 The Go Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style.
- // license that can be found in the LICENSE file.
- // Code generated by generate-types. DO NOT EDIT.
- package proto
- import (
- "math"
- "unicode/utf8"
- "google.golang.org/protobuf/internal/encoding/wire"
- "google.golang.org/protobuf/internal/errors"
- "google.golang.org/protobuf/internal/strs"
- "google.golang.org/protobuf/reflect/protoreflect"
- )
- // unmarshalScalar decodes a value of the given kind.
- //
- // Message values are decoded into a []byte which aliases the input data.
- func (o UnmarshalOptions) unmarshalScalar(b []byte, wtyp wire.Type, fd protoreflect.FieldDescriptor) (val protoreflect.Value, n int, err error) {
- switch fd.Kind() {
- case protoreflect.BoolKind:
- if wtyp != wire.VarintType {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfBool(wire.DecodeBool(v)), n, nil
- case protoreflect.EnumKind:
- if wtyp != wire.VarintType {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)), n, nil
- case protoreflect.Int32Kind:
- if wtyp != wire.VarintType {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfInt32(int32(v)), n, nil
- case protoreflect.Sint32Kind:
- if wtyp != wire.VarintType {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32))), n, nil
- case protoreflect.Uint32Kind:
- if wtyp != wire.VarintType {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfUint32(uint32(v)), n, nil
- case protoreflect.Int64Kind:
- if wtyp != wire.VarintType {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfInt64(int64(v)), n, nil
- case protoreflect.Sint64Kind:
- if wtyp != wire.VarintType {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfInt64(wire.DecodeZigZag(v)), n, nil
- case protoreflect.Uint64Kind:
- if wtyp != wire.VarintType {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfUint64(v), n, nil
- case protoreflect.Sfixed32Kind:
- if wtyp != wire.Fixed32Type {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeFixed32(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfInt32(int32(v)), n, nil
- case protoreflect.Fixed32Kind:
- if wtyp != wire.Fixed32Type {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeFixed32(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfUint32(uint32(v)), n, nil
- case protoreflect.FloatKind:
- if wtyp != wire.Fixed32Type {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeFixed32(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))), n, nil
- case protoreflect.Sfixed64Kind:
- if wtyp != wire.Fixed64Type {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeFixed64(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfInt64(int64(v)), n, nil
- case protoreflect.Fixed64Kind:
- if wtyp != wire.Fixed64Type {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeFixed64(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfUint64(v), n, nil
- case protoreflect.DoubleKind:
- if wtyp != wire.Fixed64Type {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeFixed64(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfFloat64(math.Float64frombits(v)), n, nil
- case protoreflect.StringKind:
- if wtyp != wire.BytesType {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeBytes(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- if strs.EnforceUTF8(fd) && !utf8.Valid(v) {
- return protoreflect.Value{}, 0, errors.InvalidUTF8(string(fd.FullName()))
- }
- return protoreflect.ValueOfString(string(v)), n, nil
- case protoreflect.BytesKind:
- if wtyp != wire.BytesType {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeBytes(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfBytes(append(([]byte)(nil), v...)), n, nil
- case protoreflect.MessageKind:
- if wtyp != wire.BytesType {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeBytes(b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfBytes(v), n, nil
- case protoreflect.GroupKind:
- if wtyp != wire.StartGroupType {
- return val, 0, errUnknown
- }
- v, n := wire.ConsumeGroup(fd.Number(), b)
- if n < 0 {
- return val, 0, wire.ParseError(n)
- }
- return protoreflect.ValueOfBytes(v), n, nil
- default:
- return val, 0, errUnknown
- }
- }
- func (o UnmarshalOptions) unmarshalList(b []byte, wtyp wire.Type, list protoreflect.List, fd protoreflect.FieldDescriptor) (n int, err error) {
- switch fd.Kind() {
- case protoreflect.BoolKind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeVarint(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfBool(wire.DecodeBool(v)))
- }
- return n, nil
- }
- if wtyp != wire.VarintType {
- return 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfBool(wire.DecodeBool(v)))
- return n, nil
- case protoreflect.EnumKind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeVarint(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
- }
- return n, nil
- }
- if wtyp != wire.VarintType {
- return 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)))
- return n, nil
- case protoreflect.Int32Kind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeVarint(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfInt32(int32(v)))
- }
- return n, nil
- }
- if wtyp != wire.VarintType {
- return 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfInt32(int32(v)))
- return n, nil
- case protoreflect.Sint32Kind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeVarint(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32))))
- }
- return n, nil
- }
- if wtyp != wire.VarintType {
- return 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32))))
- return n, nil
- case protoreflect.Uint32Kind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeVarint(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfUint32(uint32(v)))
- }
- return n, nil
- }
- if wtyp != wire.VarintType {
- return 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfUint32(uint32(v)))
- return n, nil
- case protoreflect.Int64Kind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeVarint(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfInt64(int64(v)))
- }
- return n, nil
- }
- if wtyp != wire.VarintType {
- return 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfInt64(int64(v)))
- return n, nil
- case protoreflect.Sint64Kind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeVarint(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfInt64(wire.DecodeZigZag(v)))
- }
- return n, nil
- }
- if wtyp != wire.VarintType {
- return 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfInt64(wire.DecodeZigZag(v)))
- return n, nil
- case protoreflect.Uint64Kind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeVarint(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfUint64(v))
- }
- return n, nil
- }
- if wtyp != wire.VarintType {
- return 0, errUnknown
- }
- v, n := wire.ConsumeVarint(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfUint64(v))
- return n, nil
- case protoreflect.Sfixed32Kind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeFixed32(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfInt32(int32(v)))
- }
- return n, nil
- }
- if wtyp != wire.Fixed32Type {
- return 0, errUnknown
- }
- v, n := wire.ConsumeFixed32(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfInt32(int32(v)))
- return n, nil
- case protoreflect.Fixed32Kind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeFixed32(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfUint32(uint32(v)))
- }
- return n, nil
- }
- if wtyp != wire.Fixed32Type {
- return 0, errUnknown
- }
- v, n := wire.ConsumeFixed32(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfUint32(uint32(v)))
- return n, nil
- case protoreflect.FloatKind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeFixed32(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
- }
- return n, nil
- }
- if wtyp != wire.Fixed32Type {
- return 0, errUnknown
- }
- v, n := wire.ConsumeFixed32(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))))
- return n, nil
- case protoreflect.Sfixed64Kind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeFixed64(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfInt64(int64(v)))
- }
- return n, nil
- }
- if wtyp != wire.Fixed64Type {
- return 0, errUnknown
- }
- v, n := wire.ConsumeFixed64(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfInt64(int64(v)))
- return n, nil
- case protoreflect.Fixed64Kind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeFixed64(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfUint64(v))
- }
- return n, nil
- }
- if wtyp != wire.Fixed64Type {
- return 0, errUnknown
- }
- v, n := wire.ConsumeFixed64(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfUint64(v))
- return n, nil
- case protoreflect.DoubleKind:
- if wtyp == wire.BytesType {
- buf, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- for len(buf) > 0 {
- v, n := wire.ConsumeFixed64(buf)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- buf = buf[n:]
- list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
- }
- return n, nil
- }
- if wtyp != wire.Fixed64Type {
- return 0, errUnknown
- }
- v, n := wire.ConsumeFixed64(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v)))
- return n, nil
- case protoreflect.StringKind:
- if wtyp != wire.BytesType {
- return 0, errUnknown
- }
- v, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- if strs.EnforceUTF8(fd) && !utf8.Valid(v) {
- return 0, errors.InvalidUTF8(string(fd.FullName()))
- }
- list.Append(protoreflect.ValueOfString(string(v)))
- return n, nil
- case protoreflect.BytesKind:
- if wtyp != wire.BytesType {
- return 0, errUnknown
- }
- v, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- list.Append(protoreflect.ValueOfBytes(append(([]byte)(nil), v...)))
- return n, nil
- case protoreflect.MessageKind:
- if wtyp != wire.BytesType {
- return 0, errUnknown
- }
- v, n := wire.ConsumeBytes(b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- m := list.NewElement()
- if err := o.unmarshalMessage(v, m.Message()); err != nil {
- return 0, err
- }
- list.Append(m)
- return n, nil
- case protoreflect.GroupKind:
- if wtyp != wire.StartGroupType {
- return 0, errUnknown
- }
- v, n := wire.ConsumeGroup(fd.Number(), b)
- if n < 0 {
- return 0, wire.ParseError(n)
- }
- m := list.NewElement()
- if err := o.unmarshalMessage(v, m.Message()); err != nil {
- return 0, err
- }
- list.Append(m)
- return n, nil
- default:
- return 0, errUnknown
- }
- }
|