protomarshal

package
v0.0.0-...-0588a43 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 12 Imported by: 11

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyJSON

func ApplyJSON(js string, pb proto.Message) error

ApplyJSON unmarshals a JSON string into a proto message.

func ApplyJSONStrict

func ApplyJSONStrict(js string, pb proto.Message) error

ApplyJSONStrict unmarshals a JSON string into a proto message.

func ApplyYAML

func ApplyYAML(yml string, pb proto.Message) error

ApplyYAML unmarshals a YAML string into a proto message. Unknown fields are allowed.

func ApplyYAMLStrict

func ApplyYAMLStrict(yml string, pb proto.Message) error

ApplyYAMLStrict unmarshals a YAML string into a proto message. Unknown fields are not allowed.

func Clone

func Clone[T proto.Message](obj T) T

Clone is a small wrapper that handles the upstream function not returning a typed message

func Marshal

func Marshal(msg proto.Message) ([]byte, error)

Marshal marshals a proto to canonical JSON

func MarshalIndent

func MarshalIndent(msg proto.Message, indent string) ([]byte, error)

MarshalIndent marshals a proto to canonical JSON with indentation

func MarshalIndentWithGlobalTypesResolver

func MarshalIndentWithGlobalTypesResolver(msg proto.Message, indent string) ([]byte, error)

MarshalIndentWithGlobalTypesResolver marshals a proto to canonical JSON with indentation and multiline while using generic types resolver

func MarshalProtoNames

func MarshalProtoNames(msg proto.Message) ([]byte, error)

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 ToJSON

func ToJSON(msg proto.Message) (string, error)

ToJSON marshals a proto to canonical JSON

func ToJSONMap

func ToJSONMap(msg proto.Message) (map[string]any, error)

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 ToJSONWithAnyResolver(msg proto.Message, indent string, anyResolver jsonpb.AnyResolver) (string, error)

func ToJSONWithIndent

func ToJSONWithIndent(msg proto.Message, indent string) (string, error)

ToJSONWithIndent marshals a proto to canonical JSON with pretty printed string

func ToJSONWithOptions

func ToJSONWithOptions(msg proto.Message, indent string, enumsAsInts bool) (string, error)

ToJSONWithOptions marshals a proto to canonical JSON with options to indent and print enums' int values

func ToYAML

func ToYAML(msg proto.Message) (string, error)

ToYAML marshals a proto to canonical YAML

func Unmarshal

func Unmarshal(b []byte, m proto.Message) error

func UnmarshalAllowUnknown

func UnmarshalAllowUnknown(b []byte, m proto.Message) error

func UnmarshalAllowUnknownWithAnyResolver

func UnmarshalAllowUnknownWithAnyResolver(anyResolver resolver, b []byte, m proto.Message) error

func UnmarshalString

func UnmarshalString(s string, m proto.Message) error

Types

type ComparableMessage

type ComparableMessage interface {
	comparable
	proto.Message
}

Jump to

Keyboard shortcuts

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