Created
December 31, 2020 05:38
-
-
Save drygdryg/19319a61ca9a7c83f251b63946ed86c2 to your computer and use it in GitHub Desktop.
nim-protobuf-bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streams | |
import protobuf | |
const protoSpec = """ | |
syntax = "proto3"; | |
message Example2 { | |
string field1 = 1; | |
int32 field2 = 2; | |
} | |
message Example { | |
message ExampleNested { | |
int32 field1 = 1; | |
repeated Example2 example2 = 2; | |
int32 field3 = 3; | |
} | |
ExampleNested exampleNested = 1; | |
int32 field2 = 2; | |
} | |
""" | |
parseProto(protoSpec) | |
var msg = new Example | |
msg.exampleNested = initExample_ExampleNested(field1 = 5, field3 = 6) | |
let example2 = initExample2(field1 = "Test", field2 = 123) | |
msg.exampleNested.example2 = @[example2] | |
msg.field2 = 5 | |
var strm = newFileStream("data_bug.bin", fmWrite) | |
strm.write(msg) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto3"; | |
message Example2 { | |
string field1 = 1; | |
int32 field2 = 2; | |
} | |
message Example { | |
message ExampleNested { | |
int32 field1 = 1; | |
repeated Example2 example2 = 2; | |
int32 field3 = 3; | |
} | |
ExampleNested exampleNested = 1; | |
int32 field2 = 2; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import test_pb2 | |
message = test_pb2.Example() | |
message.exampleNested.field1 = 5 | |
message.exampleNested.field3 = 6 | |
example2 = message.exampleNested.example2.add() | |
example2.field1 = "Test" | |
example2.field2 = 123 | |
message.field2 = 5 | |
with open("data.bin", "wb") as f: | |
f.write(message.SerializeToString()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment