protoc-gen-cue
This protoc plugin generates CUE files.
Conversions
Complies with protojson.
Basic Types
Proto Type |
CUE Type |
Comments |
map<K, V> |
{ [string]: V } |
All keys are converted to strings. |
repeated V |
[...V] |
|
bool |
*false | bool |
|
string |
*"" | string |
|
bytes |
*'' | bytes |
|
int32 |
*0 | int32 |
|
fixed32 |
*0 | int32 |
|
uint32 |
*0 | uint32 |
|
int64 |
*0 | int64 |
|
fixed64 |
*0 | fixed64 |
|
uint32 |
*0 | uint64 |
|
float |
*0 | float32 |
|
double |
*0 | float64 |
|
Any |
*null | { "@type": string, ... } |
|
Struct |
*null | { [string]: _ } |
|
Value |
*null | _ |
|
ListValue |
*null | [...] |
|
NullValue |
*null | null |
|
BoolValue |
*null | bool |
|
StringValue |
*null | string |
|
Int32Value |
*null | int32 |
|
UInt32Value |
*null | uint32 |
|
Int64Value |
*null | int64 |
|
UInt64Value |
*null | uint64 |
|
FloatValue |
*null | float32 |
|
DoubleValue |
*null | double |
|
Empty |
*null | close({}) |
|
Timestamp |
*null | string |
See the Timestamp section for more information. |
Duration |
*null | string |
See the Duration section for more information. |
FieldMask |
*null | { paths: [...string] } |
|
Message
import "github.com/ornew/protoc-gen-cue/pkg/options/cue.proto";
message Foo {
string name = 1 [(cue.field).expr = '!="xxx"'];
int32 age = 2 [(cue.field).expr = '<100'];
int32 age_next_year = 3 [(cue.field).expr = 'age+1'];
}
To:
#Foo: {
name: *"" | string
name: !="xxx"
age: *0 | int32
age: <100
ageNextYear: *0 | int32
ageNextYear: age+1
}
Enum
enum Bar {
ZERO = 0;
ONE = 1;
}
To:
#Bar: *#Bar_ZERO | #Bar_ONE
#Bar_ZERO: "ZERO"
#Bar_ONE: "ONE"
Oneof
message Car {
oneof id {
string product_name = 1;
int32 serial_number = 2;
}
}
To:
#Car: {
_oneof_id: productName & serialNumber
productName?: string
serialNumber?: int32
}
Timestamp
Currently defined by an unconstrained string
. This is due to the fact that CUE's built-in time.Time
constraint is incompatible with the JSON format defined in the timestamppb
. We plan to fix this issue in a future version to follow the original format. See for more details: time.Time on pkg.go.dev and timestamppb.Timestamp
Duration
Currently defined by an unconstrained string
. This is due to the fact that CUE's built-in time.Duration
constraint is incompatible with the JSON format defined in the durationpb
. We plan to fix this issue in a future version to follow the original format. See for more details: time.Duration in pkg.go.dev and descriptorpb.Duration
Optional (proto3)
message Dog {
optional string nick_name = 1;
}
To:
#Dog: {
nickName?: string
}