v0.4.0-alpha.1
This release introduces a more comprehensive implementation of protobuf, supporting textproto and JSON protobuf mappings, and paving the way for binary protobuf support as well.
This release required some significant changes to the cue command logic.
A hallmark property of protobuf data formats is that they cannot be parsed without a schema (unlike JSON, for instance). This is true to various degrees for the different formats, but it holds true in some shape or form for all of these. This required some changes in the CUE tooling to make this possible. It also required some backwards incompatible changes.
Protobuf changes
Filetype *.textproto
CUE now supports interpreting and writing text proto files. Text proto files cannot be interpreted, or even parsed, without a schema. This means that .textproto files can only be read with an explicit schema using the --schema/-d flag. Moreover, the schema must have @protobuf for certain types, such as maps, to be interpreted properly.
Note that the available .textproto parsing libraries are incredibly buggy. So there will be some rough edges that are kind out of CUE’s hands.
JSON conversion: package jsonpb and json+pb
The Protobuf documentation has a recommendation on how Proto messages should map to JSON. Package jsonpb now supports this mapping in both directions. It implements this by rewriting a CUE AST based on a given schema, a cue.Value. This allows this mapping to also be combined in conjunction with Yaml, for instance.
On the command line this feature can be used through the pb “interpretation”, for instance as json+pb or yaml+pb. Both input and output are supported.
Note that interpretations to CUE require a schema for the interpretation. This can be an explicitly specified schema using the --schema/-d flag or an implicit only by unifying it with a schema value or playing it within a schema using the placement flags (see cue help flags).
Backwards incompatible changes
@protobuf tag
The protobuf previously had only one required argument: the numeric value of the enum. The type was optional and only included if different in name from the CUE type. As it turned out, though, the CUE type was not always sufficient information to be able to represent proto values. Most notably, integer values are encoded differently in JSON depending on the type of integer in the proto specification (this is not a typo!!).
The new format includes the type unconditionally as the second argument. CUE does its best to recognize old formats for backwards compatibility purposes, but this may cause issues.
@protobuf(<tag num>,<type>, ...options)Protobuf options are still represented as string literals, allowing CUE options, such as alternative names (name=x) to be represented as the usual <key>=<value> format.
Another change is the representation for map types. Previously, the Protobuf map type was included verbatim (map<T,U>). This was somewhat inconvenient for parsing attributes, though: angular brackets are, unlike (), [], and {} not matched. So the comma in the map type commanded some escaping. To avoid this, maps are now represented as map[T]U. We contemplated using [T]:U, but opted for the map prefix for clarity and future extendibility.
JSON mappings
An initial design decision for the Proto to CUE mapping was to have CUE follow the Proto to JSON mapping. By hindsight, though, this did not make much sense. The inconsistency of having integers represented as strings does not make sense for a language that supports expressions on such integers (unless we want to give up typing, perhaps).
The stance now is to take the representation that makes sense, and have a protobuf-specific CUE to/from JSON converters. This is akin to the JSON schema and OpenAPI converters, which map CUE to some data format, using JSON or YAML, for instance, as a transport layer.
Luckily, the Protobuf to CUE mapping already deviated from the recommended mapping, always defaulting to int for integer types. So there are no changes there, other than that there is now support for following the recommended mappings for import and export.
Enum mappings
The most noteworthy backwards incompatible change is how enum types are mapped. Previously, CUE followed the recommended JSON mapping of using strings. This turned out to be a bad idea for various reasons. Firstly, the source of truth are integer values, really, not the names. There may be multiple names per number, making comparing names somewhat meaningless. Finally, most other languages used integers as representations, making the CUE representation not interoperate well with such languages.
Although the old mapping is still supported, the integer-based mapping is now recommended.
The default enum representation when using cue import proto is now to represent enums as integers in CUE. The --proto_enum=json flag can be used to invoke the old conversion behavior.
The API will keep converting using the JSON format, but now has a Config.EnumMode option for selecting the alternative behavior.
The Protobuf to JSON interpretation (filetype json+pb or package jsonpb) supports converting back and forth in either format.
All changes
19 changesby area
cmd5
cmd/cue/cmdcompute schema before valuescmd/cue/cmdhook up protobuf encodings typescmd/cue/cmdparseArgs: split values and schemas earlycmd/cue/cmdpreparse command line path expressionscmd/cue/cmdsimplify parseArgs in preparation of proto support
cue6
cue/buildorganized Instance fieldscue/buildremove support for file listscueadd ReferencePathcueeliminate context typecueget rid of internal index typecuerefactor index
encoding5
encoding/protobuf/jsonpbadd encoderencoding/protobuf/textprotoadd decoder implementationencoding/protobuf/textprotoadd encoderencoding/protobufalways include type as second argumentencoding/protobufsupport integer enums
internal3
internal/encodingpass schema to configinternalmove DebugStr to new astinternal packageinternalreplace internal.CoreValue with more type-safe variant
Downloads
Every file this release published on GitHub, with its SHA-256. Most people install CUE as Installing CUE describes, which also shows how to check a download.
Archives
| Platform | File and SHA-256 |
|---|---|
| macOS, Intel | cue_06d25f8f53ee6f9214a5fbb200f1d24c478dd4c2c0634dac3372b7d61baa67f4 |
| Linux, x86-64 | cue_9903f10fa1e9dfc3c32918a5734cca35bc78135778fef00384210bfe1cbbc00a |
| Linux, Arm64 | cue_0cd98cb2017cc7fae61fd6a80c39a957191f299d930a424f08f21ee02478ab35 |
| Windows, x86-64 | cue_b9773d3dcd5929e759279942a6a90642e44fe030803ba687434844712e8d7e10 |
SHA-256 checksums for all of these: checksums.txt