mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-28 19:29:57 +00:00
TUN-8407: Upgrade go to version 1.22.2
This commit is contained in:
59
vendor/google.golang.org/protobuf/encoding/protojson/encode.go
generated
vendored
59
vendor/google.golang.org/protobuf/encoding/protojson/encode.go
generated
vendored
@@ -25,15 +25,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 JSON format using default options.
|
||||
// Do not depend on the output being stable. It may change over time across
|
||||
// different versions of the program.
|
||||
// Marshal writes the given [proto.Message] in JSON format using default 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)
|
||||
}
|
||||
@@ -81,6 +83,25 @@ type MarshalOptions struct {
|
||||
// ╚═══════╧════════════════════════════╝
|
||||
EmitUnpopulated bool
|
||||
|
||||
// EmitDefaultValues specifies whether to emit default-valued primitive fields,
|
||||
// empty lists, and empty maps. The fields affected are as follows:
|
||||
// ╔═══════╤════════════════════════════════════════╗
|
||||
// ║ JSON │ Protobuf field ║
|
||||
// ╠═══════╪════════════════════════════════════════╣
|
||||
// ║ false │ non-optional scalar boolean fields ║
|
||||
// ║ 0 │ non-optional scalar numeric fields ║
|
||||
// ║ "" │ non-optional scalar string/byte fields ║
|
||||
// ║ [] │ empty repeated fields ║
|
||||
// ║ {} │ empty map fields ║
|
||||
// ╚═══════╧════════════════════════════════════════╝
|
||||
//
|
||||
// Behaves similarly to EmitUnpopulated, but does not emit "null"-value fields,
|
||||
// i.e. presence-sensing fields that are omitted will remain omitted to preserve
|
||||
// presence-sensing.
|
||||
// EmitUnpopulated takes precedence over EmitDefaultValues since the former generates
|
||||
// a strict superset of the latter.
|
||||
EmitDefaultValues bool
|
||||
|
||||
// Resolver is used for looking up types when expanding google.protobuf.Any
|
||||
// messages. If nil, this defaults to using protoregistry.GlobalTypes.
|
||||
Resolver interface {
|
||||
@@ -91,8 +112,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
|
||||
@@ -102,9 +124,10 @@ func (o MarshalOptions) Format(m proto.Message) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// Marshal marshals the given proto.Message in the JSON format using options in
|
||||
// MarshalOptions. Do not depend on the output being stable. It may change over
|
||||
// time across different versions of the program.
|
||||
// Marshal marshals the given [proto.Message] in the JSON format using options in
|
||||
// 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)
|
||||
}
|
||||
@@ -178,7 +201,11 @@ func (m typeURLFieldRanger) Range(f func(protoreflect.FieldDescriptor, protorefl
|
||||
|
||||
// unpopulatedFieldRanger wraps a protoreflect.Message and modifies its Range
|
||||
// method to additionally iterate over unpopulated fields.
|
||||
type unpopulatedFieldRanger struct{ protoreflect.Message }
|
||||
type unpopulatedFieldRanger struct {
|
||||
protoreflect.Message
|
||||
|
||||
skipNull bool
|
||||
}
|
||||
|
||||
func (m unpopulatedFieldRanger) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
|
||||
fds := m.Descriptor().Fields()
|
||||
@@ -192,6 +219,9 @@ func (m unpopulatedFieldRanger) Range(f func(protoreflect.FieldDescriptor, proto
|
||||
isProto2Scalar := fd.Syntax() == protoreflect.Proto2 && fd.Default().IsValid()
|
||||
isSingularMessage := fd.Cardinality() != protoreflect.Repeated && fd.Message() != nil
|
||||
if isProto2Scalar || isSingularMessage {
|
||||
if m.skipNull {
|
||||
continue
|
||||
}
|
||||
v = protoreflect.Value{} // use invalid value to emit null
|
||||
}
|
||||
if !f(fd, v) {
|
||||
@@ -217,8 +247,11 @@ func (e encoder) marshalMessage(m protoreflect.Message, typeURL string) error {
|
||||
defer e.EndObject()
|
||||
|
||||
var fields order.FieldRanger = m
|
||||
if e.opts.EmitUnpopulated {
|
||||
fields = unpopulatedFieldRanger{m}
|
||||
switch {
|
||||
case e.opts.EmitUnpopulated:
|
||||
fields = unpopulatedFieldRanger{Message: m, skipNull: false}
|
||||
case e.opts.EmitDefaultValues:
|
||||
fields = unpopulatedFieldRanger{Message: m, skipNull: true}
|
||||
}
|
||||
if typeURL != "" {
|
||||
fields = typeURLFieldRanger{fields, typeURL}
|
||||
|
Reference in New Issue
Block a user