Update dependencies
This commit is contained in:
160
vendor/google.golang.org/protobuf/encoding/protodelim/protodelim.go
generated
vendored
Normal file
160
vendor/google.golang.org/protobuf/encoding/protodelim/protodelim.go
generated
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
// Copyright 2022 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.
|
||||
|
||||
// Package protodelim marshals and unmarshals varint size-delimited messages.
|
||||
package protodelim
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
"google.golang.org/protobuf/internal/errors"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// MarshalOptions is a configurable varint size-delimited marshaler.
|
||||
type MarshalOptions struct{ proto.MarshalOptions }
|
||||
|
||||
// MarshalTo writes a varint size-delimited wire-format message to w.
|
||||
// If w returns an error, MarshalTo returns it unchanged.
|
||||
func (o MarshalOptions) MarshalTo(w io.Writer, m proto.Message) (int, error) {
|
||||
msgBytes, err := o.MarshalOptions.Marshal(m)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
sizeBytes := protowire.AppendVarint(nil, uint64(len(msgBytes)))
|
||||
sizeWritten, err := w.Write(sizeBytes)
|
||||
if err != nil {
|
||||
return sizeWritten, err
|
||||
}
|
||||
msgWritten, err := w.Write(msgBytes)
|
||||
if err != nil {
|
||||
return sizeWritten + msgWritten, err
|
||||
}
|
||||
return sizeWritten + msgWritten, nil
|
||||
}
|
||||
|
||||
// MarshalTo writes a varint size-delimited wire-format message to w
|
||||
// with the default options.
|
||||
//
|
||||
// See the documentation for [MarshalOptions.MarshalTo].
|
||||
func MarshalTo(w io.Writer, m proto.Message) (int, error) {
|
||||
return MarshalOptions{}.MarshalTo(w, m)
|
||||
}
|
||||
|
||||
// UnmarshalOptions is a configurable varint size-delimited unmarshaler.
|
||||
type UnmarshalOptions struct {
|
||||
proto.UnmarshalOptions
|
||||
|
||||
// MaxSize is the maximum size in wire-format bytes of a single message.
|
||||
// Unmarshaling a message larger than MaxSize will return an error.
|
||||
// A zero MaxSize will default to 4 MiB.
|
||||
// Setting MaxSize to -1 disables the limit.
|
||||
MaxSize int64
|
||||
}
|
||||
|
||||
const defaultMaxSize = 4 << 20 // 4 MiB, corresponds to the default gRPC max request/response size
|
||||
|
||||
// SizeTooLargeError is an error that is returned when the unmarshaler encounters a message size
|
||||
// that is larger than its configured [UnmarshalOptions.MaxSize].
|
||||
type SizeTooLargeError struct {
|
||||
// Size is the varint size of the message encountered
|
||||
// that was larger than the provided MaxSize.
|
||||
Size uint64
|
||||
|
||||
// MaxSize is the MaxSize limit configured in UnmarshalOptions, which Size exceeded.
|
||||
MaxSize uint64
|
||||
}
|
||||
|
||||
func (e *SizeTooLargeError) Error() string {
|
||||
return fmt.Sprintf("message size %d exceeded unmarshaler's maximum configured size %d", e.Size, e.MaxSize)
|
||||
}
|
||||
|
||||
// Reader is the interface expected by [UnmarshalFrom].
|
||||
// It is implemented by *[bufio.Reader].
|
||||
type Reader interface {
|
||||
io.Reader
|
||||
io.ByteReader
|
||||
}
|
||||
|
||||
// UnmarshalFrom parses and consumes a varint size-delimited wire-format message
|
||||
// from r.
|
||||
// The provided message must be mutable (e.g., a non-nil pointer to a message).
|
||||
//
|
||||
// The error is [io.EOF] error only if no bytes are read.
|
||||
// If an EOF happens after reading some but not all the bytes,
|
||||
// UnmarshalFrom returns a non-io.EOF error.
|
||||
// In particular if r returns a non-io.EOF error, UnmarshalFrom returns it unchanged,
|
||||
// and if only a size is read with no subsequent message, [io.ErrUnexpectedEOF] is returned.
|
||||
func (o UnmarshalOptions) UnmarshalFrom(r Reader, m proto.Message) error {
|
||||
var sizeArr [binary.MaxVarintLen64]byte
|
||||
sizeBuf := sizeArr[:0]
|
||||
for i := range sizeArr {
|
||||
b, err := r.ReadByte()
|
||||
if err != nil {
|
||||
// Immediate EOF is unexpected.
|
||||
if err == io.EOF && i != 0 {
|
||||
break
|
||||
}
|
||||
return err
|
||||
}
|
||||
sizeBuf = append(sizeBuf, b)
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
size, n := protowire.ConsumeVarint(sizeBuf)
|
||||
if n < 0 {
|
||||
return protowire.ParseError(n)
|
||||
}
|
||||
|
||||
maxSize := o.MaxSize
|
||||
if maxSize == 0 {
|
||||
maxSize = defaultMaxSize
|
||||
}
|
||||
if maxSize != -1 && size > uint64(maxSize) {
|
||||
return errors.Wrap(&SizeTooLargeError{Size: size, MaxSize: uint64(maxSize)}, "")
|
||||
}
|
||||
|
||||
var b []byte
|
||||
var err error
|
||||
if br, ok := r.(*bufio.Reader); ok {
|
||||
// Use the []byte from the bufio.Reader instead of having to allocate one.
|
||||
// This reduces CPU usage and allocated bytes.
|
||||
b, err = br.Peek(int(size))
|
||||
if err == nil {
|
||||
defer br.Discard(int(size))
|
||||
} else {
|
||||
b = nil
|
||||
}
|
||||
}
|
||||
if b == nil {
|
||||
b = make([]byte, size)
|
||||
_, err = io.ReadFull(r, b)
|
||||
}
|
||||
|
||||
if err == io.EOF {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := o.Unmarshal(b, m); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalFrom parses and consumes a varint size-delimited wire-format message
|
||||
// from r with the default options.
|
||||
// The provided message must be mutable (e.g., a non-nil pointer to a message).
|
||||
//
|
||||
// See the documentation for [UnmarshalOptions.UnmarshalFrom].
|
||||
func UnmarshalFrom(r Reader, m proto.Message) error {
|
||||
return UnmarshalOptions{}.UnmarshalFrom(r, m)
|
||||
}
|
||||
9
vendor/google.golang.org/protobuf/encoding/prototext/decode.go
generated
vendored
9
vendor/google.golang.org/protobuf/encoding/prototext/decode.go
generated
vendored
@@ -84,7 +84,7 @@ type decoder struct {
|
||||
}
|
||||
|
||||
// newError returns an error object with position info.
|
||||
func (d decoder) newError(pos int, f string, x ...interface{}) error {
|
||||
func (d decoder) newError(pos int, f string, x ...any) error {
|
||||
line, column := d.Position(pos)
|
||||
head := fmt.Sprintf("(line %d:%d): ", line, column)
|
||||
return errors.New(head+f, x...)
|
||||
@@ -96,7 +96,7 @@ func (d decoder) unexpectedTokenError(tok text.Token) error {
|
||||
}
|
||||
|
||||
// syntaxError returns a syntax error for given position.
|
||||
func (d decoder) syntaxError(pos int, f string, x ...interface{}) error {
|
||||
func (d decoder) syntaxError(pos int, f string, x ...any) error {
|
||||
line, column := d.Position(pos)
|
||||
head := fmt.Sprintf("syntax error (line %d:%d): ", line, column)
|
||||
return errors.New(head+f, x...)
|
||||
@@ -185,11 +185,6 @@ func (d decoder) unmarshalMessage(m protoreflect.Message, checkDelims bool) erro
|
||||
} else if xtErr != nil && xtErr != protoregistry.NotFound {
|
||||
return d.newError(tok.Pos(), "unable to resolve [%s]: %v", tok.RawString(), xtErr)
|
||||
}
|
||||
if flags.ProtoLegacy {
|
||||
if fd != nil && fd.IsWeak() && fd.Message().IsPlaceholder() {
|
||||
fd = nil // reset since the weak reference is not linked in
|
||||
}
|
||||
}
|
||||
|
||||
// Handle unknown fields.
|
||||
if fd == nil {
|
||||
|
||||
20
vendor/google.golang.org/protobuf/encoding/prototext/encode.go
generated
vendored
20
vendor/google.golang.org/protobuf/encoding/prototext/encode.go
generated
vendored
@@ -27,15 +27,17 @@ const defaultIndent = " "
|
||||
|
||||
// Format formats the message as a multiline string.
|
||||
// This function is only intended for human consumption and ignores errors.
|
||||
// Do not depend on the output being stable. It may change over time across
|
||||
// different versions of the program.
|
||||
// Do not depend on the output being stable. Its output will change across
|
||||
// different builds of your program, even when using the same version of the
|
||||
// protobuf module.
|
||||
func Format(m proto.Message) string {
|
||||
return MarshalOptions{Multiline: true}.Format(m)
|
||||
}
|
||||
|
||||
// Marshal writes the given [proto.Message] in textproto format using default
|
||||
// options. Do not depend on the output being stable. It may change over time
|
||||
// across different versions of the program.
|
||||
// options. Do not depend on the output being stable. Its output will change
|
||||
// across different builds of your program, even when using the same version of
|
||||
// the protobuf module.
|
||||
func Marshal(m proto.Message) ([]byte, error) {
|
||||
return MarshalOptions{}.Marshal(m)
|
||||
}
|
||||
@@ -84,8 +86,9 @@ type MarshalOptions struct {
|
||||
|
||||
// Format formats the message as a string.
|
||||
// This method is only intended for human consumption and ignores errors.
|
||||
// Do not depend on the output being stable. It may change over time across
|
||||
// different versions of the program.
|
||||
// Do not depend on the output being stable. Its output will change across
|
||||
// different builds of your program, even when using the same version of the
|
||||
// protobuf module.
|
||||
func (o MarshalOptions) Format(m proto.Message) string {
|
||||
if m == nil || !m.ProtoReflect().IsValid() {
|
||||
return "<nil>" // invalid syntax, but okay since this is for debugging
|
||||
@@ -98,8 +101,9 @@ func (o MarshalOptions) Format(m proto.Message) string {
|
||||
}
|
||||
|
||||
// Marshal writes the given [proto.Message] in textproto format using options in
|
||||
// MarshalOptions object. Do not depend on the output being stable. It may
|
||||
// change over time across different versions of the program.
|
||||
// MarshalOptions object. Do not depend on the output being stable. Its output
|
||||
// will change across different builds of your program, even when using the
|
||||
// same version of the protobuf module.
|
||||
func (o MarshalOptions) Marshal(m proto.Message) ([]byte, error) {
|
||||
return o.marshal(nil, m)
|
||||
}
|
||||
|
||||
26
vendor/google.golang.org/protobuf/encoding/protowire/wire.go
generated
vendored
26
vendor/google.golang.org/protobuf/encoding/protowire/wire.go
generated
vendored
@@ -371,7 +371,31 @@ func ConsumeVarint(b []byte) (v uint64, n int) {
|
||||
func SizeVarint(v uint64) int {
|
||||
// This computes 1 + (bits.Len64(v)-1)/7.
|
||||
// 9/64 is a good enough approximation of 1/7
|
||||
return int(9*uint32(bits.Len64(v))+64) / 64
|
||||
//
|
||||
// The Go compiler can translate the bits.LeadingZeros64 call into the LZCNT
|
||||
// instruction, which is very fast on CPUs from the last few years. The
|
||||
// specific way of expressing the calculation matches C++ Protobuf, see
|
||||
// https://godbolt.org/z/4P3h53oM4 for the C++ code and how gcc/clang
|
||||
// optimize that function for GOAMD64=v1 and GOAMD64=v3 (-march=haswell).
|
||||
|
||||
// By OR'ing v with 1, we guarantee that v is never 0, without changing the
|
||||
// result of SizeVarint. LZCNT is not defined for 0, meaning the compiler
|
||||
// needs to add extra instructions to handle that case.
|
||||
//
|
||||
// The Go compiler currently (go1.24.4) does not make use of this knowledge.
|
||||
// This opportunity (removing the XOR instruction, which handles the 0 case)
|
||||
// results in a small (1%) performance win across CPU architectures.
|
||||
//
|
||||
// Independently of avoiding the 0 case, we need the v |= 1 line because
|
||||
// it allows the Go compiler to eliminate an extra XCHGL barrier.
|
||||
v |= 1
|
||||
|
||||
// It would be clearer to write log2value := 63 - uint32(...), but
|
||||
// writing uint32(...) ^ 63 is much more efficient (-14% ARM, -20% Intel).
|
||||
// Proof of identity for our value range [0..63]:
|
||||
// https://go.dev/play/p/Pdn9hEWYakX
|
||||
log2value := uint32(bits.LeadingZeros64(v)) ^ 63
|
||||
return int((log2value*9 + (64 + 9)) / 64)
|
||||
}
|
||||
|
||||
// AppendFixed32 appends v to b as a little-endian uint32.
|
||||
|
||||
Reference in New Issue
Block a user