Skip to content

Commit

Permalink
add rust scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f committed Jun 18, 2024
1 parent c7e9def commit cd87b7c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
15 changes: 15 additions & 0 deletions resources/scalars.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"protoType": "double",
"notes": "",
"cppType": "double",
"rustType": "f64",
"csType": "double",
"goType": "float64",
"javaType": "double",
Expand All @@ -14,6 +15,7 @@
"protoType": "float",
"notes": "",
"cppType": "float",
"rustType": "f32",
"csType": "float",
"goType": "float32",
"javaType": "float",
Expand All @@ -25,6 +27,7 @@
"protoType": "int32",
"notes": "Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead.",
"cppType": "int32",
"rustType": "i32",
"csType": "int",
"goType": "int32",
"javaType": "int",
Expand All @@ -36,6 +39,7 @@
"protoType": "int64",
"notes": "Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead.",
"cppType": "int64",
"rustType": "i64",
"csType": "long",
"goType": "int64",
"javaType": "long",
Expand All @@ -47,6 +51,7 @@
"protoType": "uint32",
"notes": "Uses variable-length encoding.",
"cppType": "uint32",
"rustType": "u32",
"csType": "uint",
"goType": "uint32",
"javaType": "int",
Expand All @@ -58,6 +63,7 @@
"protoType": "uint64",
"notes": "Uses variable-length encoding.",
"cppType": "uint64",
"rustType": "u64",
"csType": "ulong",
"goType": "uint64",
"javaType": "long",
Expand All @@ -69,6 +75,7 @@
"protoType": "sint32",
"notes": "Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s.",
"cppType": "int32",
"rustType": "i32",
"csType": "int",
"goType": "int32",
"javaType": "int",
Expand All @@ -80,6 +87,7 @@
"protoType": "sint64",
"notes": "Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s.",
"cppType": "int64",
"rustType": "i64",
"csType": "long",
"goType": "int64",
"javaType": "long",
Expand All @@ -91,6 +99,7 @@
"protoType": "fixed32",
"notes": "Always four bytes. More efficient than uint32 if values are often greater than 2^28.",
"cppType": "uint32",
"rustType": "u64",
"csType": "uint",
"goType": "uint32",
"javaType": "int",
Expand All @@ -102,6 +111,7 @@
"protoType": "fixed64",
"notes": "Always eight bytes. More efficient than uint64 if values are often greater than 2^56.",
"cppType": "uint64",
"rustType": "u64",
"csType": "ulong",
"goType": "uint64",
"javaType": "long",
Expand All @@ -113,6 +123,7 @@
"protoType": "sfixed32",
"notes": "Always four bytes.",
"cppType": "int32",
"rustType": "i32",
"csType": "int",
"goType": "int32",
"javaType": "int",
Expand All @@ -124,6 +135,7 @@
"protoType": "sfixed64",
"notes": "Always eight bytes.",
"cppType": "int64",
"rustType": "i64",
"csType": "long",
"goType": "int64",
"javaType": "long",
Expand All @@ -135,6 +147,7 @@
"protoType": "bool",
"notes": "",
"cppType": "bool",
"rustType": "bool",
"csType": "bool",
"goType": "bool",
"javaType": "boolean",
Expand All @@ -146,6 +159,7 @@
"protoType": "string",
"notes": "A string must always contain UTF-8 encoded or 7-bit ASCII text.",
"cppType": "string",
"rustType": "String",
"csType": "string",
"goType": "string",
"javaType": "String",
Expand All @@ -157,6 +171,7 @@
"protoType": "bytes",
"notes": "May contain any arbitrary sequence of bytes.",
"cppType": "string",
"rustType": "Vec<u8>",
"csType": "ByteString",
"goType": "[]byte",
"javaType": "ByteString",
Expand Down
4 changes: 3 additions & 1 deletion template.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ func NewTemplate(descs []*protokit.FileDescriptor) *Template {
if valueField.Name != "value" {
panic(fmt.Sprintf("expected map entry's first field to be 'value', not '%s'", valueField.Name))
}
typeName := fmt.Sprintf("map<%s, %s>", keyField.Type, valueField.Type)
typeName := fmt.Sprintf("map&lt;%s, %s&gt;", keyField.Type, valueField.Type)
f.Label = ""
f.Type = typeName
f.FullType = typeName
f.LongType = typeName
Expand Down Expand Up @@ -424,6 +425,7 @@ type ScalarValue struct {
Notes string `json:"notes"`
CppType string `json:"cppType"`
CSharp string `json:"csType"`
RustType string `json:"rustType"`
GoType string `json:"goType"`
JavaType string `json:"javaType"`
PhpType string `json:"phpType"`
Expand Down
8 changes: 4 additions & 4 deletions template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ func TestFieldProperties(t *testing.T) {

field = findField("properties", findMessage("Vehicle", vehicleFile))
require.Equal(t, "properties", field.Name)
require.Equal(t, "repeated", field.Label)
require.Equal(t, "map<string, string>", field.Type)
require.Equal(t, "map<string, string>", field.LongType)
require.Equal(t, "map<string, string>", field.FullType)
require.Equal(t, "", field.Label)
require.Equal(t, "map&lt;string, string&gt;", field.Type)
require.Equal(t, "map&lt;string, string&gt;", field.LongType)
require.Equal(t, "map&lt;string, string&gt;", field.FullType)
require.Empty(t, field.DefaultValue)
require.True(t, field.IsMap)
require.False(t, field.IsOneof)
Expand Down

0 comments on commit cd87b7c

Please sign in to comment.