Documentation ¶
Overview ¶
Package protomarshal provides operations to marshal and unmarshal protobuf objects. Unlike the rest of this repo, which uses the new google.golang.org/protobuf API, this package explicitly uses the legacy jsonpb package. This is due to a number of compatibility concerns with the new API: * https://github.com/golang/protobuf/issues/1374 * https://github.com/golang/protobuf/issues/1373
Index ¶
- func ApplyJSON(js string, pb proto.Message) error
- func ApplyJSONStrict(js string, pb proto.Message) error
- func ApplyYAML(yml string, pb proto.Message) error
- func ApplyYAMLStrict(yml string, pb proto.Message) error
- func Clone[T proto.Message](obj T) T
- func Marshal(msg proto.Message) ([]byte, error)
- func MarshalIndent(msg proto.Message, indent string) ([]byte, error)
- func MarshalIndentWithGlobalTypesResolver(msg proto.Message, indent string) ([]byte, error)
- func MarshalProtoNames(msg proto.Message) ([]byte, error)
- func ShallowClone[T ComparableMessage](src T) T
- func ToJSON(msg proto.Message) (string, error)
- func ToJSONMap(msg proto.Message) (map[string]any, error)
- func ToJSONWithAnyResolver(msg proto.Message, indent string, anyResolver jsonpb.AnyResolver) (string, error)
- func ToJSONWithIndent(msg proto.Message, indent string) (string, error)
- func ToJSONWithOptions(msg proto.Message, indent string, enumsAsInts bool) (string, error)
- func ToYAML(msg proto.Message) (string, error)
- func Unmarshal(b []byte, m proto.Message) error
- func UnmarshalAllowUnknown(b []byte, m proto.Message) error
- func UnmarshalAllowUnknownWithAnyResolver(anyResolver resolver, b []byte, m proto.Message) error
- func UnmarshalString(s string, m proto.Message) error
- type ComparableMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyJSONStrict ¶
ApplyJSONStrict unmarshals a JSON string into a proto message.
func ApplyYAML ¶
ApplyYAML unmarshals a YAML string into a proto message. Unknown fields are allowed.
func ApplyYAMLStrict ¶
ApplyYAMLStrict unmarshals a YAML string into a proto message. Unknown fields are not allowed.
func Clone ¶
Clone is a small wrapper that handles the upstream function not returning a typed message
func MarshalIndent ¶
MarshalIndent marshals a proto to canonical JSON with indentation
func MarshalIndentWithGlobalTypesResolver ¶
MarshalIndentWithGlobalTypesResolver marshals a proto to canonical JSON with indentation and multiline while using generic types resolver
func MarshalProtoNames ¶
MarshalProtoNames marshals a proto to canonical JSON original protobuf names
func ShallowClone ¶
func ShallowClone[T ComparableMessage](src T) T
ShallowClone performs a shallow clone of the object. For a deep clone, use Clone.
func ToJSONMap ¶
ToJSONMap converts a proto message to a generic map using canonical JSON encoding JSON encoding is specified here: https://developers.google.com/protocol-buffers/docs/proto3#json
func ToJSONWithAnyResolver ¶
func ToJSONWithIndent ¶
ToJSONWithIndent marshals a proto to canonical JSON with pretty printed string
func ToJSONWithOptions ¶
ToJSONWithOptions marshals a proto to canonical JSON with options to indent and print enums' int values
Types ¶
type ComparableMessage ¶
type ComparableMessage interface { comparable proto.Message }