jsonpb

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2021 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package jsonpb rewrites a CUE expression based upon the Protobuf interpretation of JSON.

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 interprets CUE expressions as JSON protobuf encodings based on an underlying schema.

It bases the mapping on the underlying CUE type, without consulting Protobuf attributes.

Mappings per CUE type:

for any CUE type:
           null is omitted if null is not specifically allowed.
bytes:     if the expression is a string, it is reinterpreted using a
           base64 encoding. Either standard or URL-safe base64 encoding
           with/without paddings are accepted.
int:       string values are interpreted as integers
float:     string values are interpreted as numbers, and the values "NaN",
           "Infinity", and "-Infinity" are allowed and converted to
           to corresponding error values.
disjunction of strings:
           this is assumed to represent a protobuf enum value. Strings
           are left as is. For integers, the disjunction is resolved
           by converting it to the string that has a corresponding #intValue
           value.
{}:        JSON objects representing any values will be left as is.
           If the CUE type corresponding to the URL can be determined within
           the module context it will be unified.
time.Time / time.Duration:
           left as is
_:         left as is.

func NewDecoder

func NewDecoder(schema cue.Value, options ...Option) *Decoder

NewDecoder creates a Decoder for the given schema.

func (*Decoder) RewriteExpr

func (d *Decoder) RewriteExpr(expr ast.Expr) (ast.Expr, error)

RewriteExpr modifies expr, interpreting it in terms of the given schema according to the protocol buffer to JSON mapping defined in the protocol buffer spec.

RewriteExpr is idempotent, calling it multiples times on an expression gives the same result.

func (*Decoder) RewriteFile

func (d *Decoder) RewriteFile(file *ast.File) error

RewriteFile modifies file, interpreting it in terms of the given schema according to the protocol buffer to JSON mapping defined in the protocol buffer spec.

RewriteFile is idempotent, calling it multiples times on an expression gives the same result.

type Option

type Option func()

Option is an option.

There are currently no options.

Jump to

Keyboard shortcuts

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