protoyaml

package module
v0.0.0-...-bd6c3de Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2022 License: MIT Imports: 13 Imported by: 0

README

ProtoYAML

A YAML decoder for Go in the spirit of what protojson is for JSON.

Maturity

This is in early development.

Special Considerations

  • YAML names correspond to Protobuf names, not JSON-names.
  • Enums can be provied as names or numbers.

Running Tests

$ go generate ./..
$ go test ./...

License

MIT License

Documentation

Overview

Package protoyaml contains a YAML decoder in the spirit of what https://pkg.go.dev/google.golang.org/protobuf/encoding/protojson is for JSON.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(bs []byte, m protoreflect.ProtoMessage) error

Unmarshal interprets the bytes as YAML and populates m.

Example
var got testproto.Message
if err := Unmarshal([]byte(`astring: hello`), &got); err != nil {
	return nil, err
}
return &got, nil
Output:

Types

type Decoder

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

A Decoder can be used to decode one or more YAML documents as Protobuf messages. It is not goroutine-safe, but is goroutine-compatible.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creats a new decoder reading from the given stream of YAML text.

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) error

Decode decodes the next document as a message. The argument can either be a proto.Message, or a protoreflect.Message. Returns io.EOF if there are no more documents.

func (*Decoder) MessageTypeResolver

func (d *Decoder) MessageTypeResolver(r protoregistry.MessageTypeResolver)

MessageTypeResolver sets a custom resolver for anypb.Any types. The default in NewDecoder is protoregistry.GlobalTypes.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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