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 ¶
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 multiples times on an expression gives the same result.