Documentation ¶
Overview ¶
Package jsonpb rewrites a CUE expression based upon the Protobuf interpretation of JSON.
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 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 corresponding error values. enums: if a field is of type int and does not have a standard integer type for its @protobuf attribute, this is assumed to represent a protobuf enum value. Enum names are converted to integers by interpreting the definitions of the disjunction constants as the symbol names. If CUE uses the string representation for enums, then an #enumValue integer associated with the string value is used for the conversion. {}: 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 ¶
NewDecoder creates a Decoder for the given schema.
func (*Decoder) RewriteExpr ¶
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 ¶
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 multiple times on an expression gives the same result.
type Encoder ¶ added in v0.4.0
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder rewrites CUE values according to the Protobuf to JSON mappings, based on a given CUE schema.
It bases the mapping on the underlying CUE type, without consulting Protobuf attributes.
Mappings per CUE type:
for any CUE type: int: if the expression value is an integer and the schema value is an int64, it is converted to a string. {}: 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. _: Adds a `@type` URL (TODO).
func NewEncoder ¶ added in v0.4.0
NewEncoder creates an Encoder for the given schema.
func (*Encoder) RewriteExpr ¶ added in v0.4.0
RewriteExpr modifies file, modifying it to conform to the Protocol buffer to JSON mapping it in terms of the given schema.
RewriteExpr is idempotent, calling it multiples times on an expression gives the same result.
func (*Encoder) RewriteFile ¶ added in v0.4.0
RewriteFile modifies file, modifying it to conform to the Protocol buffer to JSON mapping it in terms of the given schema.
RewriteFile is idempotent, calling it multiples times on an expression gives the same result.