bsonpb

package
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMessageSet

func IsMessageSet(md pref.MessageDescriptor) bool

IsMessageSet returns whether the message uses the MessageSet wire format.

func IsMessageSetExtension

func IsMessageSetExtension(fd pref.FieldDescriptor) bool

IsMessageSetExtension reports this field extends a MessageSet.

func JSONCamelCase

func JSONCamelCase(s string) string

JSONCamelCase converts a snake_case identifier to a camelCase identifier, according to the protobuf JSON specification.

func JSONSnakeCase

func JSONSnakeCase(s string) string

JSONSnakeCase converts a camelCase identifier to a snake_case identifier, according to the protobuf JSON specification.

func Marshal

func Marshal(m proto.Message) (bson.D, error)

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.

func Unmarshal

func Unmarshal(doc interface{}, m proto.Message) error

Unmarshal reads the given bson.D into the given proto.Message.

Types

type Ints

type Ints struct {
	// contains filtered or unexported fields
}

Ints represents a set of integers within the range of 0..math.MaxUint64.

func (*Ints) Clear

func (bs *Ints) Clear(n uint64)

func (*Ints) Has

func (bs *Ints) Has(n uint64) bool

func (*Ints) Len

func (bs *Ints) Len() int

func (*Ints) Set

func (bs *Ints) Set(n uint64)

type MarshalOptions

type MarshalOptions struct {
	NoUnkeyedLiterals

	// Multiline specifies whether the marshaler should format the output in
	// indented-form with every textual element on a new line.
	// If Indent is an empty string, then an arbitrary indent is chosen.
	Multiline bool

	// Indent specifies the set of indentation characters to use in a multiline
	// formatted output such that every entry is preceded by Indent and
	// terminated by a newline. If non-empty, then Multiline is treated as true.
	// Indent can only be composed of space or tab characters.
	Indent string

	// AllowPartial allows messages that have missing required fields to marshal
	// without returning an error. If AllowPartial is false (the default),
	// Marshal will return error if there are any missing required fields.
	AllowPartial bool

	// UseProtoNames uses proto field name instead of lowerCamelCase name in JSON
	// field names.
	UseProtoNames bool

	// UseEnumNumbers emits enum values as numbers.
	UseEnumNumbers bool

	// EmitUnpopulated specifies whether to emit unpopulated fields. It does not
	// emit unpopulated oneof fields or unpopulated extension fields.
	// The JSON value emitted for unpopulated fields are as follows:
	//  ╔═══════╤════════════════════════════╗
	//  ║ JSON  │ Protobuf field             ║
	//  ╠═══════╪════════════════════════════╣
	//  ║ false │ proto3 boolean fields      ║
	//  ║ 0     │ proto3 numeric fields      ║
	//  ║ ""    │ proto3 string/bytes fields ║
	//  ║ null  │ proto2 scalar fields       ║
	//  ║ null  │ message fields             ║
	//  ║ []    │ list fields                ║
	//  ║ {}    │ map fields                 ║
	//  ╚═══════╧════════════════════════════╝
	EmitUnpopulated bool
	EmitNull        bool

	// Resolver is used for looking up types when expanding google.protobuf.Any
	// messages. If nil, this defaults to using protoregistry.GlobalTypes.
	Resolver interface {
		protoregistry.ExtensionTypeResolver
		protoregistry.MessageTypeResolver
	}
}

MarshalOptions is a configurable JSON format marshaler.

func (MarshalOptions) Marshal

func (o MarshalOptions) Marshal(m proto.Message) (interface{}, error)

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.

type NoUnkeyedLiterals

type NoUnkeyedLiterals struct{}

NoUnkeyedLiterals can be embedded in a struct to prevent unkeyed literals.

type UnmarshalOptions

type UnmarshalOptions struct {
	NoUnkeyedLiterals

	// If AllowPartial is set, input for messages that will result in missing
	// required fields will not return an error.
	AllowPartial bool

	// If DiscardUnknown is set, unknown fields are ignored.
	DiscardUnknown bool

	// Resolver is used for looking up types when unmarshaling
	// google.protobuf.Any messages or extension fields.
	// If nil, this defaults to using protoregistry.GlobalTypes.
	Resolver interface {
		protoregistry.MessageTypeResolver
		protoregistry.ExtensionTypeResolver
	}
}

UnmarshalOptions is a configurable JSON format parser.

func (UnmarshalOptions) Unmarshal

func (o UnmarshalOptions) Unmarshal(doc interface{}, m proto.Message) error

Unmarshal reads the given []byte and populates the given proto.Message using options in UnmarshalOptions object. It will clear the message first before setting the fields. If it returns an error, the given message may be partially set.

func (UnmarshalOptions) UnmarshalBytes

func (o UnmarshalOptions) UnmarshalBytes(b []byte, m proto.Message) error

UnmarshalBytes ...

Directories

Path Synopsis
internal
genid
Package genid contains constants for declarations in descriptor.proto and the well-known types.
Package genid contains constants for declarations in descriptor.proto and the well-known types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL