textproto

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package textproto converts text protobuffer files to and from CUE.

Note that textproto is an unofficial standard and that there are no specifications: the recommended packages are the de facto standard for the relevant programming languages and the recommended implementations may vary considerably between them.

Also, the standard text proto parsing libraries are rather buggy. Please verify that a parsing issues is not related these libraries before filing bugs with CUE.

API Status: DRAFT: API may change without notice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

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

A Decoder caches conversions of cue.Value between calls to its methods.

func NewDecoder

func NewDecoder(option ...Option) *Decoder

NewDecoder returns a new Decoder

func (*Decoder) Parse

func (d *Decoder) Parse(schema cue.Value, filename string, b []byte) (ast.Expr, error)

Parse parses the given textproto bytes and converts them to a CUE expression, using schema as the guideline for conversion using the following rules:

  • the @protobuf attribute is optional, but is necessary for:
  • interpreting protobuf maps
  • using a name different from the CUE name
  • fields in the textproto that have no corresponding field in schema are ignored

NOTE: the filename is used for associating position information. However, currently no position information is associated with the text proto because the position information of github.com/protocolbuffers/txtpbfmt is too unreliable to be useful.

type Encoder

type Encoder struct {
}

Encoder marshals CUE into text proto.

func NewEncoder

func NewEncoder(options ...Option) *Encoder

NewEncoder returns a new encoder, where the given options are default options.

func (*Encoder) Encode

func (e *Encoder) Encode(v cue.Value, options ...Option) ([]byte, error)

Encode converts a CUE value to a text proto file.

Fields do not need to have a @protobuf attribute except for in the following cases:

  • it is explicitly required that only fields with an attribute are exported
  • a struct represents a Protobuf map
  • custom naming

type Option

type Option func(*options)

Option defines options for the decoder. There are currently no options.

Jump to

Keyboard shortcuts

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