VOL-2265 test go.mod and vendor consistency;
Update dependencies to resolve `410 Gone` errors when fetching modules
Change-Id: If0bdbc1b6d629ce819b9fa4701c016df812f92d5
diff --git a/vendor/github.com/jhump/protoreflect/dynamic/binary.go b/vendor/github.com/jhump/protoreflect/dynamic/binary.go
index b1fbe7c..91fd672 100644
--- a/vendor/github.com/jhump/protoreflect/dynamic/binary.go
+++ b/vendor/github.com/jhump/protoreflect/dynamic/binary.go
@@ -4,15 +4,9 @@
import (
"fmt"
- "io"
- "math"
- "reflect"
- "sort"
-
"github.com/golang/protobuf/proto"
- "github.com/golang/protobuf/protoc-gen-go/descriptor"
-
- "github.com/jhump/protoreflect/desc"
+ "github.com/jhump/protoreflect/codec"
+ "io"
)
// defaultDeterminism, if true, will mean that calls to Marshal will produce
@@ -24,11 +18,12 @@
// Marshal serializes this message to bytes, returning an error if the operation
// fails. The resulting bytes are in the standard protocol buffer binary format.
func (m *Message) Marshal() ([]byte, error) {
- var b codedBuffer
- if err := m.marshal(&b, defaultDeterminism); err != nil {
+ var b codec.Buffer
+ b.SetDeterministic(defaultDeterminism)
+ if err := m.marshal(&b); err != nil {
return nil, err
}
- return b.buf, nil
+ return b.Bytes(), nil
}
// MarshalAppend behaves exactly the same as Marshal, except instead of allocating a
@@ -37,11 +32,12 @@
// it's not guaranteed as a new backing array will automatically be allocated if
// more bytes need to be written than the provided buffer has capacity for.
func (m *Message) MarshalAppend(b []byte) ([]byte, error) {
- codedBuf := codedBuffer{buf: b}
- if err := m.marshal(&codedBuf, defaultDeterminism); err != nil {
+ codedBuf := codec.NewBuffer(b)
+ codedBuf.SetDeterministic(defaultDeterminism)
+ if err := m.marshal(codedBuf); err != nil {
return nil, err
}
- return codedBuf.buf, nil
+ return codedBuf.Bytes(), nil
}
// MarshalDeterministic serializes this message to bytes in a deterministic way,
@@ -51,21 +47,37 @@
// iteration order (which will be random). But for cases where determinism is
// more important than performance, use this method instead.
func (m *Message) MarshalDeterministic() ([]byte, error) {
- var b codedBuffer
- if err := m.marshal(&b, true); err != nil {
+ var b codec.Buffer
+ b.SetDeterministic(true)
+ if err := m.marshal(&b); err != nil {
return nil, err
}
- return b.buf, nil
+ return b.Bytes(), nil
}
-func (m *Message) marshal(b *codedBuffer, deterministic bool) error {
- if err := m.marshalKnownFields(b, deterministic); err != nil {
+// MarshalAppendDeterministic behaves exactly the same as MarshalDeterministic,
+// except instead of allocating a new byte slice to marshal into, it uses the
+// provided byte slice. The backing array for the returned byte slice *may* be
+// the same as the one that was passed in, but it's not guaranteed as a new
+// backing array will automatically be allocated if more bytes need to be written
+// than the provided buffer has capacity for.
+func (m *Message) MarshalAppendDeterministic(b []byte) ([]byte, error) {
+ codedBuf := codec.NewBuffer(b)
+ codedBuf.SetDeterministic(true)
+ if err := m.marshal(codedBuf); err != nil {
+ return nil, err
+ }
+ return codedBuf.Bytes(), nil
+}
+
+func (m *Message) marshal(b *codec.Buffer) error {
+ if err := m.marshalKnownFields(b); err != nil {
return err
}
return m.marshalUnknownFields(b)
}
-func (m *Message) marshalKnownFields(b *codedBuffer, deterministic bool) error {
+func (m *Message) marshalKnownFields(b *codec.Buffer) error {
for _, tag := range m.knownFieldTags() {
itag := int32(tag)
val := m.values[itag]
@@ -73,317 +85,51 @@
if fd == nil {
panic(fmt.Sprintf("Couldn't find field for tag %d", itag))
}
- if err := marshalField(itag, fd, val, b, deterministic); err != nil {
+ if err := b.EncodeFieldValue(fd, val); err != nil {
return err
}
}
return nil
}
-func (m *Message) marshalUnknownFields(b *codedBuffer) error {
+func (m *Message) marshalUnknownFields(b *codec.Buffer) error {
for _, tag := range m.unknownFieldTags() {
itag := int32(tag)
sl := m.unknownFields[itag]
for _, u := range sl {
- if err := b.encodeTagAndWireType(itag, u.Encoding); err != nil {
+ if err := b.EncodeTagAndWireType(itag, u.Encoding); err != nil {
return err
}
switch u.Encoding {
case proto.WireBytes:
- if err := b.encodeRawBytes(u.Contents); err != nil {
+ if err := b.EncodeRawBytes(u.Contents); err != nil {
return err
}
case proto.WireStartGroup:
- b.buf = append(b.buf, u.Contents...)
- if err := b.encodeTagAndWireType(itag, proto.WireEndGroup); err != nil {
+ _, _ = b.Write(u.Contents)
+ if err := b.EncodeTagAndWireType(itag, proto.WireEndGroup); err != nil {
return err
}
case proto.WireFixed32:
- if err := b.encodeFixed32(u.Value); err != nil {
+ if err := b.EncodeFixed32(u.Value); err != nil {
return err
}
case proto.WireFixed64:
- if err := b.encodeFixed64(u.Value); err != nil {
+ if err := b.EncodeFixed64(u.Value); err != nil {
return err
}
case proto.WireVarint:
- if err := b.encodeVarint(u.Value); err != nil {
+ if err := b.EncodeVarint(u.Value); err != nil {
return err
}
default:
- return proto.ErrInternalBadWireType
+ return codec.ErrBadWireType
}
}
}
return nil
}
-func marshalField(tag int32, fd *desc.FieldDescriptor, val interface{}, b *codedBuffer, deterministic bool) error {
- if fd.IsMap() {
- mp := val.(map[interface{}]interface{})
- entryType := fd.GetMessageType()
- keyType := entryType.FindFieldByNumber(1)
- valType := entryType.FindFieldByNumber(2)
- var entryBuffer codedBuffer
- if deterministic {
- keys := make([]interface{}, 0, len(mp))
- for k := range mp {
- keys = append(keys, k)
- }
- sort.Sort(sortable(keys))
- for _, k := range keys {
- v := mp[k]
- entryBuffer.reset()
- if err := marshalFieldElement(1, keyType, k, &entryBuffer, deterministic); err != nil {
- return err
- }
- if err := marshalFieldElement(2, valType, v, &entryBuffer, deterministic); err != nil {
- return err
- }
- if err := b.encodeTagAndWireType(tag, proto.WireBytes); err != nil {
- return err
- }
- if err := b.encodeRawBytes(entryBuffer.buf); err != nil {
- return err
- }
- }
- } else {
- for k, v := range mp {
- entryBuffer.reset()
- if err := marshalFieldElement(1, keyType, k, &entryBuffer, deterministic); err != nil {
- return err
- }
- if err := marshalFieldElement(2, valType, v, &entryBuffer, deterministic); err != nil {
- return err
- }
- if err := b.encodeTagAndWireType(tag, proto.WireBytes); err != nil {
- return err
- }
- if err := b.encodeRawBytes(entryBuffer.buf); err != nil {
- return err
- }
- }
- }
- return nil
- } else if fd.IsRepeated() {
- sl := val.([]interface{})
- wt, err := getWireType(fd.GetType())
- if err != nil {
- return err
- }
- if isPacked(fd) && len(sl) > 1 &&
- (wt == proto.WireVarint || wt == proto.WireFixed32 || wt == proto.WireFixed64) {
- // packed repeated field
- var packedBuffer codedBuffer
- for _, v := range sl {
- if err := marshalFieldValue(fd, v, &packedBuffer, deterministic); err != nil {
- return err
- }
- }
- if err := b.encodeTagAndWireType(tag, proto.WireBytes); err != nil {
- return err
- }
- return b.encodeRawBytes(packedBuffer.buf)
- } else {
- // non-packed repeated field
- for _, v := range sl {
- if err := marshalFieldElement(tag, fd, v, b, deterministic); err != nil {
- return err
- }
- }
- return nil
- }
- } else {
- return marshalFieldElement(tag, fd, val, b, deterministic)
- }
-}
-
-func isPacked(fd *desc.FieldDescriptor) bool {
- opts := fd.AsFieldDescriptorProto().GetOptions()
- // if set, use that value
- if opts != nil && opts.Packed != nil {
- return opts.GetPacked()
- }
- // if unset: proto2 defaults to false, proto3 to true
- return fd.GetFile().IsProto3()
-}
-
-// sortable is used to sort map keys. Values will be integers (int32, int64, uint32, and uint64),
-// bools, or strings.
-type sortable []interface{}
-
-func (s sortable) Len() int {
- return len(s)
-}
-
-func (s sortable) Less(i, j int) bool {
- vi := s[i]
- vj := s[j]
- switch reflect.TypeOf(vi).Kind() {
- case reflect.Int32:
- return vi.(int32) < vj.(int32)
- case reflect.Int64:
- return vi.(int64) < vj.(int64)
- case reflect.Uint32:
- return vi.(uint32) < vj.(uint32)
- case reflect.Uint64:
- return vi.(uint64) < vj.(uint64)
- case reflect.String:
- return vi.(string) < vj.(string)
- case reflect.Bool:
- return vi.(bool) && !vj.(bool)
- default:
- panic(fmt.Sprintf("cannot compare keys of type %v", reflect.TypeOf(vi)))
- }
-}
-
-func (s sortable) Swap(i, j int) {
- s[i], s[j] = s[j], s[i]
-}
-
-func marshalFieldElement(tag int32, fd *desc.FieldDescriptor, val interface{}, b *codedBuffer, deterministic bool) error {
- wt, err := getWireType(fd.GetType())
- if err != nil {
- return err
- }
- if err := b.encodeTagAndWireType(tag, wt); err != nil {
- return err
- }
- if err := marshalFieldValue(fd, val, b, deterministic); err != nil {
- return err
- }
- if wt == proto.WireStartGroup {
- return b.encodeTagAndWireType(tag, proto.WireEndGroup)
- }
- return nil
-}
-
-func marshalFieldValue(fd *desc.FieldDescriptor, val interface{}, b *codedBuffer, deterministic bool) error {
- switch fd.GetType() {
- case descriptor.FieldDescriptorProto_TYPE_BOOL:
- v := val.(bool)
- if v {
- return b.encodeVarint(1)
- } else {
- return b.encodeVarint(0)
- }
-
- case descriptor.FieldDescriptorProto_TYPE_ENUM,
- descriptor.FieldDescriptorProto_TYPE_INT32:
- v := val.(int32)
- return b.encodeVarint(uint64(v))
-
- case descriptor.FieldDescriptorProto_TYPE_SFIXED32:
- v := val.(int32)
- return b.encodeFixed32(uint64(v))
-
- case descriptor.FieldDescriptorProto_TYPE_SINT32:
- v := val.(int32)
- return b.encodeVarint(encodeZigZag32(v))
-
- case descriptor.FieldDescriptorProto_TYPE_UINT32:
- v := val.(uint32)
- return b.encodeVarint(uint64(v))
-
- case descriptor.FieldDescriptorProto_TYPE_FIXED32:
- v := val.(uint32)
- return b.encodeFixed32(uint64(v))
-
- case descriptor.FieldDescriptorProto_TYPE_INT64:
- v := val.(int64)
- return b.encodeVarint(uint64(v))
-
- case descriptor.FieldDescriptorProto_TYPE_SFIXED64:
- v := val.(int64)
- return b.encodeFixed64(uint64(v))
-
- case descriptor.FieldDescriptorProto_TYPE_SINT64:
- v := val.(int64)
- return b.encodeVarint(encodeZigZag64(v))
-
- case descriptor.FieldDescriptorProto_TYPE_UINT64:
- v := val.(uint64)
- return b.encodeVarint(v)
-
- case descriptor.FieldDescriptorProto_TYPE_FIXED64:
- v := val.(uint64)
- return b.encodeFixed64(v)
-
- case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
- v := val.(float64)
- return b.encodeFixed64(math.Float64bits(v))
-
- case descriptor.FieldDescriptorProto_TYPE_FLOAT:
- v := val.(float32)
- return b.encodeFixed32(uint64(math.Float32bits(v)))
-
- case descriptor.FieldDescriptorProto_TYPE_BYTES:
- v := val.([]byte)
- return b.encodeRawBytes(v)
-
- case descriptor.FieldDescriptorProto_TYPE_STRING:
- v := val.(string)
- return b.encodeRawBytes(([]byte)(v))
-
- case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
- m := val.(proto.Message)
- if bytes, err := proto.Marshal(m); err != nil {
- return err
- } else {
- return b.encodeRawBytes(bytes)
- }
-
- case descriptor.FieldDescriptorProto_TYPE_GROUP:
- // just append the nested message to this buffer
- dm, ok := val.(*Message)
- if ok {
- return dm.marshal(b, deterministic)
- } else {
- m := val.(proto.Message)
- return b.encodeMessage(m)
- }
- // whosoever writeth start-group tag (e.g. caller) is responsible for writing end-group tag
-
- default:
- return fmt.Errorf("unrecognized field type: %v", fd.GetType())
- }
-}
-
-func getWireType(t descriptor.FieldDescriptorProto_Type) (int8, error) {
- switch t {
- case descriptor.FieldDescriptorProto_TYPE_ENUM,
- descriptor.FieldDescriptorProto_TYPE_BOOL,
- descriptor.FieldDescriptorProto_TYPE_INT32,
- descriptor.FieldDescriptorProto_TYPE_SINT32,
- descriptor.FieldDescriptorProto_TYPE_UINT32,
- descriptor.FieldDescriptorProto_TYPE_INT64,
- descriptor.FieldDescriptorProto_TYPE_SINT64,
- descriptor.FieldDescriptorProto_TYPE_UINT64:
- return proto.WireVarint, nil
-
- case descriptor.FieldDescriptorProto_TYPE_FIXED32,
- descriptor.FieldDescriptorProto_TYPE_SFIXED32,
- descriptor.FieldDescriptorProto_TYPE_FLOAT:
- return proto.WireFixed32, nil
-
- case descriptor.FieldDescriptorProto_TYPE_FIXED64,
- descriptor.FieldDescriptorProto_TYPE_SFIXED64,
- descriptor.FieldDescriptorProto_TYPE_DOUBLE:
- return proto.WireFixed64, nil
-
- case descriptor.FieldDescriptorProto_TYPE_BYTES,
- descriptor.FieldDescriptorProto_TYPE_STRING,
- descriptor.FieldDescriptorProto_TYPE_MESSAGE:
- return proto.WireBytes, nil
-
- case descriptor.FieldDescriptorProto_TYPE_GROUP:
- return proto.WireStartGroup, nil
-
- default:
- return 0, proto.ErrInternalBadWireType
- }
-}
-
// Unmarshal de-serializes the message that is present in the given bytes into
// this message. It first resets the current message. It returns an error if the
// given bytes do not contain a valid encoding of this message type.
@@ -400,34 +146,36 @@
// instead merging the data in the given bytes into the existing data in this
// message.
func (m *Message) UnmarshalMerge(b []byte) error {
- return m.unmarshal(newCodedBuffer(b), false)
+ return m.unmarshal(codec.NewBuffer(b), false)
}
-func (m *Message) unmarshal(buf *codedBuffer, isGroup bool) error {
- for !buf.eof() {
- tagNumber, wireType, err := buf.decodeTagAndWireType()
+func (m *Message) unmarshal(buf *codec.Buffer, isGroup bool) error {
+ for !buf.EOF() {
+ fd, val, err := buf.DecodeFieldValue(m.FindFieldDescriptor, m.mf)
if err != nil {
+ if err == codec.ErrWireTypeEndGroup {
+ if isGroup {
+ // finished parsing group
+ return nil
+ }
+ return codec.ErrBadWireType
+ }
return err
}
- if wireType == proto.WireEndGroup {
- if isGroup {
- // finished parsing group
- return nil
- } else {
- return proto.ErrInternalBadWireType
- }
- }
- fd := m.FindFieldDescriptor(tagNumber)
+
if fd == nil {
- err := m.unmarshalUnknownField(tagNumber, wireType, buf)
- if err != nil {
- return err
+ if m.unknownFields == nil {
+ m.unknownFields = map[int32][]UnknownField{}
}
- } else {
- err := m.unmarshalKnownField(fd, wireType, buf)
- if err != nil {
- return err
+ uv := val.(codec.UnknownField)
+ u := UnknownField{
+ Encoding: uv.Encoding,
+ Value: uv.Value,
+ Contents: uv.Contents,
}
+ m.unknownFields[uv.Tag] = append(m.unknownFields[uv.Tag], u)
+ } else if err := mergeField(m, fd, val); err != nil {
+ return err
}
}
if isGroup {
@@ -435,280 +183,3 @@
}
return nil
}
-
-func unmarshalSimpleField(fd *desc.FieldDescriptor, v uint64) (interface{}, error) {
- switch fd.GetType() {
- case descriptor.FieldDescriptorProto_TYPE_BOOL:
- return v != 0, nil
- case descriptor.FieldDescriptorProto_TYPE_UINT32,
- descriptor.FieldDescriptorProto_TYPE_FIXED32:
- if v > math.MaxUint32 {
- return nil, NumericOverflowError
- }
- return uint32(v), nil
-
- case descriptor.FieldDescriptorProto_TYPE_INT32,
- descriptor.FieldDescriptorProto_TYPE_ENUM:
- s := int64(v)
- if s > math.MaxInt32 || s < math.MinInt32 {
- return nil, NumericOverflowError
- }
- return int32(s), nil
-
- case descriptor.FieldDescriptorProto_TYPE_SFIXED32:
- if v > math.MaxUint32 {
- return nil, NumericOverflowError
- }
- return int32(v), nil
-
- case descriptor.FieldDescriptorProto_TYPE_SINT32:
- if v > math.MaxUint32 {
- return nil, NumericOverflowError
- }
- return decodeZigZag32(v), nil
-
- case descriptor.FieldDescriptorProto_TYPE_UINT64,
- descriptor.FieldDescriptorProto_TYPE_FIXED64:
- return v, nil
-
- case descriptor.FieldDescriptorProto_TYPE_INT64,
- descriptor.FieldDescriptorProto_TYPE_SFIXED64:
- return int64(v), nil
-
- case descriptor.FieldDescriptorProto_TYPE_SINT64:
- return decodeZigZag64(v), nil
-
- case descriptor.FieldDescriptorProto_TYPE_FLOAT:
- if v > math.MaxUint32 {
- return nil, NumericOverflowError
- }
- return math.Float32frombits(uint32(v)), nil
-
- case descriptor.FieldDescriptorProto_TYPE_DOUBLE:
- return math.Float64frombits(v), nil
-
- default:
- // bytes, string, message, and group cannot be represented as a simple numeric value
- return nil, fmt.Errorf("bad input; field %s requires length-delimited wire type", fd.GetFullyQualifiedName())
- }
-}
-
-func unmarshalLengthDelimitedField(fd *desc.FieldDescriptor, bytes []byte, mf *MessageFactory) (interface{}, error) {
- switch {
- case fd.GetType() == descriptor.FieldDescriptorProto_TYPE_BYTES:
- return bytes, nil
-
- case fd.GetType() == descriptor.FieldDescriptorProto_TYPE_STRING:
- return string(bytes), nil
-
- case fd.GetType() == descriptor.FieldDescriptorProto_TYPE_MESSAGE ||
- fd.GetType() == descriptor.FieldDescriptorProto_TYPE_GROUP:
- msg := mf.NewMessage(fd.GetMessageType())
- err := proto.Unmarshal(bytes, msg)
- if err != nil {
- return nil, err
- } else {
- return msg, nil
- }
-
- default:
- // even if the field is not repeated or not packed, we still parse it as such for
- // backwards compatibility (e.g. message we are de-serializing could have been both
- // repeated and packed at the time of serialization)
- packedBuf := newCodedBuffer(bytes)
- var slice []interface{}
- var val interface{}
- for !packedBuf.eof() {
- var v uint64
- var err error
- if varintTypes[fd.GetType()] {
- v, err = packedBuf.decodeVarint()
- } else if fixed32Types[fd.GetType()] {
- v, err = packedBuf.decodeFixed32()
- } else if fixed64Types[fd.GetType()] {
- v, err = packedBuf.decodeFixed64()
- } else {
- return nil, fmt.Errorf("bad input; cannot parse length-delimited wire type for field %s", fd.GetFullyQualifiedName())
- }
- if err != nil {
- return nil, err
- }
- val, err = unmarshalSimpleField(fd, v)
- if err != nil {
- return nil, err
- }
- if fd.IsRepeated() {
- slice = append(slice, val)
- }
- }
- if fd.IsRepeated() {
- return slice, nil
- } else {
- // if not a repeated field, last value wins
- return val, nil
- }
- }
-}
-
-func (m *Message) unmarshalKnownField(fd *desc.FieldDescriptor, encoding int8, b *codedBuffer) error {
- var val interface{}
- var err error
- switch encoding {
- case proto.WireFixed32:
- var num uint64
- num, err = b.decodeFixed32()
- if err == nil {
- val, err = unmarshalSimpleField(fd, num)
- }
- case proto.WireFixed64:
- var num uint64
- num, err = b.decodeFixed64()
- if err == nil {
- val, err = unmarshalSimpleField(fd, num)
- }
- case proto.WireVarint:
- var num uint64
- num, err = b.decodeVarint()
- if err == nil {
- val, err = unmarshalSimpleField(fd, num)
- }
-
- case proto.WireBytes:
- if fd.GetType() == descriptor.FieldDescriptorProto_TYPE_BYTES {
- val, err = b.decodeRawBytes(true) // defensive copy
- } else if fd.GetType() == descriptor.FieldDescriptorProto_TYPE_STRING {
- var raw []byte
- raw, err = b.decodeRawBytes(true) // defensive copy
- if err == nil {
- val = string(raw)
- }
- } else {
- var raw []byte
- raw, err = b.decodeRawBytes(false)
- if err == nil {
- val, err = unmarshalLengthDelimitedField(fd, raw, m.mf)
- }
- }
-
- case proto.WireStartGroup:
- if fd.GetMessageType() == nil {
- return fmt.Errorf("cannot parse field %s from group-encoded wire type", fd.GetFullyQualifiedName())
- }
- msg := m.mf.NewMessage(fd.GetMessageType())
- if dm, ok := msg.(*Message); ok {
- err = dm.unmarshal(b, true)
- if err == nil {
- val = dm
- }
- } else {
- var groupEnd, dataEnd int
- groupEnd, dataEnd, err = skipGroup(b)
- if err == nil {
- err = proto.Unmarshal(b.buf[b.index:dataEnd], msg)
- if err == nil {
- val = msg
- }
- b.index = groupEnd
- }
- }
-
- default:
- return proto.ErrInternalBadWireType
- }
- if err != nil {
- return err
- }
-
- return mergeField(m, fd, val)
-}
-
-func (m *Message) unmarshalUnknownField(tagNumber int32, encoding int8, b *codedBuffer) error {
- u := UnknownField{Encoding: encoding}
- var err error
- switch encoding {
- case proto.WireFixed32:
- u.Value, err = b.decodeFixed32()
- case proto.WireFixed64:
- u.Value, err = b.decodeFixed64()
- case proto.WireVarint:
- u.Value, err = b.decodeVarint()
- case proto.WireBytes:
- u.Contents, err = b.decodeRawBytes(true)
- case proto.WireStartGroup:
- var groupEnd, dataEnd int
- groupEnd, dataEnd, err = skipGroup(b)
- if err == nil {
- u.Contents = make([]byte, dataEnd-b.index)
- copy(u.Contents, b.buf[b.index:])
- b.index = groupEnd
- }
- default:
- err = proto.ErrInternalBadWireType
- }
- if err != nil {
- return err
- }
- if m.unknownFields == nil {
- m.unknownFields = map[int32][]UnknownField{}
- }
- m.unknownFields[tagNumber] = append(m.unknownFields[tagNumber], u)
- return nil
-}
-
-func skipGroup(b *codedBuffer) (int, int, error) {
- bs := b.buf
- start := b.index
- defer func() {
- b.index = start
- }()
- for {
- fieldStart := b.index
- // read a field tag
- _, wireType, err := b.decodeTagAndWireType()
- if err != nil {
- return 0, 0, err
- }
- // skip past the field's data
- switch wireType {
- case proto.WireFixed32:
- if !b.skip(4) {
- return 0, 0, io.ErrUnexpectedEOF
- }
- case proto.WireFixed64:
- if !b.skip(8) {
- return 0, 0, io.ErrUnexpectedEOF
- }
- case proto.WireVarint:
- // skip varint by finding last byte (has high bit unset)
- i := b.index
- for {
- if i >= len(bs) {
- return 0, 0, io.ErrUnexpectedEOF
- }
- if bs[i]&0x80 == 0 {
- break
- }
- i++
- }
- b.index = i + 1
- case proto.WireBytes:
- l, err := b.decodeVarint()
- if err != nil {
- return 0, 0, err
- }
- if !b.skip(int(l)) {
- return 0, 0, io.ErrUnexpectedEOF
- }
- case proto.WireStartGroup:
- endIndex, _, err := skipGroup(b)
- if err != nil {
- return 0, 0, err
- }
- b.index = endIndex
- case proto.WireEndGroup:
- return b.index, fieldStart, nil
- default:
- return 0, 0, proto.ErrInternalBadWireType
- }
- }
-}
diff --git a/vendor/github.com/jhump/protoreflect/dynamic/codec.go b/vendor/github.com/jhump/protoreflect/dynamic/codec.go
deleted file mode 100644
index 9d70ab7..0000000
--- a/vendor/github.com/jhump/protoreflect/dynamic/codec.go
+++ /dev/null
@@ -1,350 +0,0 @@
-package dynamic
-
-// A reader/writer type that assists with encoding and decoding protobuf's binary representation.
-// This code is largely a fork of proto.Buffer, which cannot be used because it has no exported
-// field or method that provides access to its underlying reader index.
-
-import (
- "errors"
- "fmt"
- "io"
- "math"
-
- "github.com/golang/protobuf/proto"
-)
-
-// ErrOverflow is returned when an integer is too large to be represented.
-var ErrOverflow = errors.New("proto: integer overflow")
-
-type codedBuffer struct {
- buf []byte
- index int
-}
-
-func newCodedBuffer(buf []byte) *codedBuffer {
- return &codedBuffer{buf: buf}
-}
-
-func (cb *codedBuffer) reset() {
- cb.buf = []byte(nil)
- cb.index = 0
-}
-
-func (cb *codedBuffer) eof() bool {
- return cb.index >= len(cb.buf)
-}
-
-func (cb *codedBuffer) skip(count int) bool {
- newIndex := cb.index + count
- if newIndex > len(cb.buf) {
- return false
- }
- cb.index = newIndex
- return true
-}
-
-func (cb *codedBuffer) decodeVarintSlow() (x uint64, err error) {
- i := cb.index
- l := len(cb.buf)
-
- for shift := uint(0); shift < 64; shift += 7 {
- if i >= l {
- err = io.ErrUnexpectedEOF
- return
- }
- b := cb.buf[i]
- i++
- x |= (uint64(b) & 0x7F) << shift
- if b < 0x80 {
- cb.index = i
- return
- }
- }
-
- // The number is too large to represent in a 64-bit value.
- err = ErrOverflow
- return
-}
-
-// DecodeVarint reads a varint-encoded integer from the Buffer.
-// This is the format for the
-// int32, int64, uint32, uint64, bool, and enum
-// protocol buffer types.
-func (cb *codedBuffer) decodeVarint() (uint64, error) {
- i := cb.index
- buf := cb.buf
-
- if i >= len(buf) {
- return 0, io.ErrUnexpectedEOF
- } else if buf[i] < 0x80 {
- cb.index++
- return uint64(buf[i]), nil
- } else if len(buf)-i < 10 {
- return cb.decodeVarintSlow()
- }
-
- var b uint64
- // we already checked the first byte
- x := uint64(buf[i]) - 0x80
- i++
-
- b = uint64(buf[i])
- i++
- x += b << 7
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 7
-
- b = uint64(buf[i])
- i++
- x += b << 14
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 14
-
- b = uint64(buf[i])
- i++
- x += b << 21
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 21
-
- b = uint64(buf[i])
- i++
- x += b << 28
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 28
-
- b = uint64(buf[i])
- i++
- x += b << 35
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 35
-
- b = uint64(buf[i])
- i++
- x += b << 42
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 42
-
- b = uint64(buf[i])
- i++
- x += b << 49
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 49
-
- b = uint64(buf[i])
- i++
- x += b << 56
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 56
-
- b = uint64(buf[i])
- i++
- x += b << 63
- if b&0x80 == 0 {
- goto done
- }
- // x -= 0x80 << 63 // Always zero.
-
- return 0, ErrOverflow
-
-done:
- cb.index = i
- return x, nil
-}
-
-func (cb *codedBuffer) decodeTagAndWireType() (tag int32, wireType int8, err error) {
- var v uint64
- v, err = cb.decodeVarint()
- if err != nil {
- return
- }
- // low 7 bits is wire type
- wireType = int8(v & 7)
- // rest is int32 tag number
- v = v >> 3
- if v > math.MaxInt32 {
- err = fmt.Errorf("tag number out of range: %d", v)
- return
- }
- tag = int32(v)
- return
-}
-
-// DecodeFixed64 reads a 64-bit integer from the Buffer.
-// This is the format for the
-// fixed64, sfixed64, and double protocol buffer types.
-func (cb *codedBuffer) decodeFixed64() (x uint64, err error) {
- // x, err already 0
- i := cb.index + 8
- if i < 0 || i > len(cb.buf) {
- err = io.ErrUnexpectedEOF
- return
- }
- cb.index = i
-
- x = uint64(cb.buf[i-8])
- x |= uint64(cb.buf[i-7]) << 8
- x |= uint64(cb.buf[i-6]) << 16
- x |= uint64(cb.buf[i-5]) << 24
- x |= uint64(cb.buf[i-4]) << 32
- x |= uint64(cb.buf[i-3]) << 40
- x |= uint64(cb.buf[i-2]) << 48
- x |= uint64(cb.buf[i-1]) << 56
- return
-}
-
-// DecodeFixed32 reads a 32-bit integer from the Buffer.
-// This is the format for the
-// fixed32, sfixed32, and float protocol buffer types.
-func (cb *codedBuffer) decodeFixed32() (x uint64, err error) {
- // x, err already 0
- i := cb.index + 4
- if i < 0 || i > len(cb.buf) {
- err = io.ErrUnexpectedEOF
- return
- }
- cb.index = i
-
- x = uint64(cb.buf[i-4])
- x |= uint64(cb.buf[i-3]) << 8
- x |= uint64(cb.buf[i-2]) << 16
- x |= uint64(cb.buf[i-1]) << 24
- return
-}
-
-func decodeZigZag32(v uint64) int32 {
- return int32((uint32(v) >> 1) ^ uint32((int32(v&1)<<31)>>31))
-}
-
-func decodeZigZag64(v uint64) int64 {
- return int64((v >> 1) ^ uint64((int64(v&1)<<63)>>63))
-}
-
-// These are not ValueDecoders: they produce an array of bytes or a string.
-// bytes, embedded messages
-
-// DecodeRawBytes reads a count-delimited byte buffer from the Buffer.
-// This is the format used for the bytes protocol buffer
-// type and for embedded messages.
-func (cb *codedBuffer) decodeRawBytes(alloc bool) (buf []byte, err error) {
- n, err := cb.decodeVarint()
- if err != nil {
- return nil, err
- }
-
- nb := int(n)
- if nb < 0 {
- return nil, fmt.Errorf("proto: bad byte length %d", nb)
- }
- end := cb.index + nb
- if end < cb.index || end > len(cb.buf) {
- return nil, io.ErrUnexpectedEOF
- }
-
- if !alloc {
- buf = cb.buf[cb.index:end]
- cb.index += nb
- return
- }
-
- buf = make([]byte, nb)
- copy(buf, cb.buf[cb.index:])
- cb.index += nb
- return
-}
-
-// EncodeVarint writes a varint-encoded integer to the Buffer.
-// This is the format for the
-// int32, int64, uint32, uint64, bool, and enum
-// protocol buffer types.
-func (cb *codedBuffer) encodeVarint(x uint64) error {
- for x >= 1<<7 {
- cb.buf = append(cb.buf, uint8(x&0x7f|0x80))
- x >>= 7
- }
- cb.buf = append(cb.buf, uint8(x))
- return nil
-}
-
-func (cb *codedBuffer) encodeTagAndWireType(tag int32, wireType int8) error {
- v := uint64((int64(tag) << 3) | int64(wireType))
- return cb.encodeVarint(v)
-}
-
-// TODO: decodeTagAndWireType
-
-// EncodeFixed64 writes a 64-bit integer to the Buffer.
-// This is the format for the
-// fixed64, sfixed64, and double protocol buffer types.
-func (cb *codedBuffer) encodeFixed64(x uint64) error {
- cb.buf = append(cb.buf,
- uint8(x),
- uint8(x>>8),
- uint8(x>>16),
- uint8(x>>24),
- uint8(x>>32),
- uint8(x>>40),
- uint8(x>>48),
- uint8(x>>56))
- return nil
-}
-
-// EncodeFixed32 writes a 32-bit integer to the Buffer.
-// This is the format for the
-// fixed32, sfixed32, and float protocol buffer types.
-func (cb *codedBuffer) encodeFixed32(x uint64) error {
- cb.buf = append(cb.buf,
- uint8(x),
- uint8(x>>8),
- uint8(x>>16),
- uint8(x>>24))
- return nil
-}
-
-func encodeZigZag64(v int64) uint64 {
- return (uint64(v) << 1) ^ uint64(v>>63)
-}
-
-func encodeZigZag32(v int32) uint64 {
- return uint64((uint32(v) << 1) ^ uint32((v >> 31)))
-}
-
-// EncodeRawBytes writes a count-delimited byte buffer to the Buffer.
-// This is the format used for the bytes protocol buffer
-// type and for embedded messages.
-func (cb *codedBuffer) encodeRawBytes(b []byte) error {
- cb.encodeVarint(uint64(len(b)))
- cb.buf = append(cb.buf, b...)
- return nil
-}
-
-func (cb *codedBuffer) encodeMessage(pm proto.Message) error {
- bytes, err := proto.Marshal(pm)
- if err != nil {
- return err
- }
- if len(bytes) == 0 {
- return nil
- }
-
- if err := cb.encodeVarint(uint64(len(bytes))); err != nil {
- return err
- }
- cb.buf = append(cb.buf, bytes...)
- return nil
-}
diff --git a/vendor/github.com/jhump/protoreflect/dynamic/dynamic_message.go b/vendor/github.com/jhump/protoreflect/dynamic/dynamic_message.go
index ac7e52f..3f19d6b 100644
--- a/vendor/github.com/jhump/protoreflect/dynamic/dynamic_message.go
+++ b/vendor/github.com/jhump/protoreflect/dynamic/dynamic_message.go
@@ -12,6 +12,7 @@
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
+ "github.com/jhump/protoreflect/codec"
"github.com/jhump/protoreflect/desc"
)
@@ -68,29 +69,6 @@
var typeOfDynamicMessage = reflect.TypeOf((*Message)(nil))
var typeOfBytes = reflect.TypeOf(([]byte)(nil))
-var varintTypes = map[descriptor.FieldDescriptorProto_Type]bool{}
-var fixed32Types = map[descriptor.FieldDescriptorProto_Type]bool{}
-var fixed64Types = map[descriptor.FieldDescriptorProto_Type]bool{}
-
-func init() {
- varintTypes[descriptor.FieldDescriptorProto_TYPE_BOOL] = true
- varintTypes[descriptor.FieldDescriptorProto_TYPE_INT32] = true
- varintTypes[descriptor.FieldDescriptorProto_TYPE_INT64] = true
- varintTypes[descriptor.FieldDescriptorProto_TYPE_UINT32] = true
- varintTypes[descriptor.FieldDescriptorProto_TYPE_UINT64] = true
- varintTypes[descriptor.FieldDescriptorProto_TYPE_SINT32] = true
- varintTypes[descriptor.FieldDescriptorProto_TYPE_SINT64] = true
- varintTypes[descriptor.FieldDescriptorProto_TYPE_ENUM] = true
-
- fixed32Types[descriptor.FieldDescriptorProto_TYPE_FIXED32] = true
- fixed32Types[descriptor.FieldDescriptorProto_TYPE_SFIXED32] = true
- fixed32Types[descriptor.FieldDescriptorProto_TYPE_FLOAT] = true
-
- fixed64Types[descriptor.FieldDescriptorProto_TYPE_FIXED64] = true
- fixed64Types[descriptor.FieldDescriptorProto_TYPE_SFIXED64] = true
- fixed64Types[descriptor.FieldDescriptorProto_TYPE_DOUBLE] = true
-}
-
// Message is a dynamic protobuf message. Instead of a generated struct,
// like most protobuf messages, this is a map of field number to values and
// a message descriptor, which is used to validate the field values and
@@ -1221,7 +1199,6 @@
if mp, err = m.parseUnknownField(fd); err != nil {
return err
} else if mp == nil {
- mp = map[interface{}]interface{}{}
m.internalSetField(fd, map[interface{}]interface{}{ki: vi})
return nil
}
@@ -1777,9 +1754,9 @@
for _, unk := range unks {
var val interface{}
if unk.Encoding == proto.WireBytes || unk.Encoding == proto.WireStartGroup {
- val, err = unmarshalLengthDelimitedField(fd, unk.Contents, m.mf)
+ val, err = codec.DecodeLengthDelimitedField(fd, unk.Contents, m.mf)
} else {
- val, err = unmarshalSimpleField(fd, unk.Value)
+ val, err = codec.DecodeScalarField(fd, unk.Value)
}
if err != nil {
return nil, err
@@ -2292,14 +2269,15 @@
// if we have fields that the given message doesn't know about, add to its unknown fields
if len(unknownTags) > 0 {
ub := u.Interface().([]byte)
- var b codedBuffer
+ var b codec.Buffer
+ b.SetDeterministic(defaultDeterminism)
for tag := range unknownTags {
fd := m.FindFieldDescriptor(tag)
- if err := marshalField(tag, fd, m.values[tag], &b, false); err != nil {
+ if err := b.EncodeFieldValue(fd, m.values[tag]); err != nil {
return err
}
}
- ub = append(ub, b.buf...)
+ ub = append(ub, b.Bytes()...)
u.Set(reflect.ValueOf(ub))
}
@@ -2307,9 +2285,9 @@
// (this will append to its unknown fields if not known; if somehow the given message recognizes
// a field even though the dynamic message did not, it will get correctly unmarshalled)
if unknownTags != nil && len(m.unknownFields) > 0 {
- var b codedBuffer
- m.marshalUnknownFields(&b)
- proto.UnmarshalMerge(b.buf, pm)
+ var b codec.Buffer
+ _ = m.marshalUnknownFields(&b)
+ _ = proto.UnmarshalMerge(b.Bytes(), pm)
}
return nil
@@ -2535,7 +2513,7 @@
u := src.FieldByName("XXX_unrecognized")
if u.IsValid() && u.Type() == typeOfBytes {
// ignore any error returned: pulling in unknown fields is best-effort
- m.UnmarshalMerge(u.Interface().([]byte))
+ _ = m.UnmarshalMerge(u.Interface().([]byte))
}
// lastly, also extract any unknown extensions the message may have (unknown extensions
@@ -2543,7 +2521,7 @@
// more than just the step above...)
if len(unknownExtensions) > 0 {
// pulling in unknown fields is best-effort, so we just ignore errors
- m.UnmarshalMerge(unknownExtensions)
+ _ = m.UnmarshalMerge(unknownExtensions)
}
return nil
}
diff --git a/vendor/github.com/jhump/protoreflect/dynamic/extension.go b/vendor/github.com/jhump/protoreflect/dynamic/extension.go
index a0ff6af..1d38161 100644
--- a/vendor/github.com/jhump/protoreflect/dynamic/extension.go
+++ b/vendor/github.com/jhump/protoreflect/dynamic/extension.go
@@ -5,6 +5,7 @@
"github.com/golang/protobuf/proto"
+ "github.com/jhump/protoreflect/codec"
"github.com/jhump/protoreflect/desc"
)
@@ -35,10 +36,11 @@
return err
}
- var b codedBuffer
- if err := marshalField(extd.GetNumber(), extd, val, &b, defaultDeterminism); err != nil {
+ var b codec.Buffer
+ b.SetDeterministic(defaultDeterminism)
+ if err := b.EncodeFieldValue(extd, val); err != nil {
return err
}
- proto.SetRawExtension(msg, extd.GetNumber(), b.buf)
+ proto.SetRawExtension(msg, extd.GetNumber(), b.Bytes())
return nil
}
diff --git a/vendor/github.com/jhump/protoreflect/dynamic/json.go b/vendor/github.com/jhump/protoreflect/dynamic/json.go
index f79b4ac..7dfae09 100644
--- a/vendor/github.com/jhump/protoreflect/dynamic/json.go
+++ b/vendor/github.com/jhump/protoreflect/dynamic/json.go
@@ -308,6 +308,39 @@
}
}
+// sortable is used to sort map keys. Values will be integers (int32, int64, uint32, and uint64),
+// bools, or strings.
+type sortable []interface{}
+
+func (s sortable) Len() int {
+ return len(s)
+}
+
+func (s sortable) Less(i, j int) bool {
+ vi := s[i]
+ vj := s[j]
+ switch reflect.TypeOf(vi).Kind() {
+ case reflect.Int32:
+ return vi.(int32) < vj.(int32)
+ case reflect.Int64:
+ return vi.(int64) < vj.(int64)
+ case reflect.Uint32:
+ return vi.(uint32) < vj.(uint32)
+ case reflect.Uint64:
+ return vi.(uint64) < vj.(uint64)
+ case reflect.String:
+ return vi.(string) < vj.(string)
+ case reflect.Bool:
+ return !vi.(bool) && vj.(bool)
+ default:
+ panic(fmt.Sprintf("cannot compare keys of type %v", reflect.TypeOf(vi)))
+ }
+}
+
+func (s sortable) Swap(i, j int) {
+ s[i], s[j] = s[j], s[i]
+}
+
func isNil(v interface{}) bool {
if v == nil {
return true
@@ -345,7 +378,9 @@
func marshalKnownFieldValueJSON(b *indentBuffer, fd *desc.FieldDescriptor, v interface{}, opts *jsonpb.Marshaler) error {
rv := reflect.ValueOf(v)
switch rv.Kind() {
- case reflect.Int32, reflect.Int64:
+ case reflect.Int64:
+ return writeJsonString(b, strconv.FormatInt(rv.Int(), 10))
+ case reflect.Int32:
ed := fd.GetEnumType()
if !opts.EnumsAsInts && ed != nil {
n := int32(rv.Int())
@@ -360,7 +395,9 @@
_, err := b.WriteString(strconv.FormatInt(rv.Int(), 10))
return err
}
- case reflect.Uint32, reflect.Uint64:
+ case reflect.Uint64:
+ return writeJsonString(b, strconv.FormatUint(rv.Uint(), 10))
+ case reflect.Uint32:
_, err := b.WriteString(strconv.FormatUint(rv.Uint(), 10))
return err
case reflect.Float32, reflect.Float64:
diff --git a/vendor/github.com/jhump/protoreflect/dynamic/text.go b/vendor/github.com/jhump/protoreflect/dynamic/text.go
index 2d0fa04..72636f2 100644
--- a/vendor/github.com/jhump/protoreflect/dynamic/text.go
+++ b/vendor/github.com/jhump/protoreflect/dynamic/text.go
@@ -17,6 +17,7 @@
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
+ "github.com/jhump/protoreflect/codec"
"github.com/jhump/protoreflect/desc"
)
@@ -124,7 +125,7 @@
if err != nil {
return err
}
- in := newCodedBuffer(uf.Contents)
+ in := codec.NewBuffer(uf.Contents)
err = marshalUnknownGroupText(b, in, true)
if err != nil {
return err
@@ -360,17 +361,17 @@
return b.WriteByte('"')
}
-func marshalUnknownGroupText(b *indentBuffer, in *codedBuffer, topLevel bool) error {
+func marshalUnknownGroupText(b *indentBuffer, in *codec.Buffer, topLevel bool) error {
first := true
for {
- if in.eof() {
+ if in.EOF() {
if topLevel {
return nil
}
// this is a nested message: we are expecting an end-group tag, not EOF!
return io.ErrUnexpectedEOF
}
- tag, wireType, err := in.decodeTagAndWireType()
+ tag, wireType, err := in.DecodeTagAndWireType()
if err != nil {
return err
}
@@ -413,7 +414,7 @@
return err
}
if wireType == proto.WireBytes {
- contents, err := in.decodeRawBytes(false)
+ contents, err := in.DecodeRawBytes(false)
if err != nil {
return err
}
@@ -425,11 +426,11 @@
var v uint64
switch wireType {
case proto.WireVarint:
- v, err = in.decodeVarint()
+ v, err = in.DecodeVarint()
case proto.WireFixed32:
- v, err = in.decodeFixed32()
+ v, err = in.DecodeFixed32()
case proto.WireFixed64:
- v, err = in.decodeFixed64()
+ v, err = in.DecodeFixed64()
default:
return proto.ErrInternalBadWireType
}