protomarshal

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "proto"

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 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 MessageToStructSlow

func MessageToStructSlow(msg proto.Message) (*structpb.Struct, error)

MessageToStructSlow encodes a protobuf Message into a Struct. It roundtrips trough JSON so it is slow. Copied from https://github.com/envoyproxy/go-control-plane/blob/d77bd2ea68bdbb72afd65a7ddf6fe8969e556c45/pkg/conversion/struct.go#L29

func ToJSON

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

ToJSON marshals a proto to canonical 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

Types

type Codec

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

func (*Codec) Marshal

func (c *Codec) Marshal(v any) (mem.BufferSlice, error)

func (Codec) Name

func (Codec) Name() string

func (*Codec) Unmarshal

func (c *Codec) Unmarshal(data mem.BufferSlice, v any) error

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