Created
January 2, 2021 11:56
-
-
Save drygdryg/17a7c693330ccf932989fb9401e7eb92 to your computer and use it in GitHub Desktop.
protobuf-nim 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 | |
parseProtoFile("test.proto") | |
var msg = new Example | |
msg.field1 = @[] | |
let exampleNested = initExample_ExampleNested() | |
exampleNested.field1 = initExample_ExampleNested_ExampleNested2(field1 = "Test", field2 = @[]) | |
let exampleNested3 = initExample_ExampleNested_ExampleNested2_ExampleNested3(field1 = "Test") | |
let exampleNested3_1 = initExample_ExampleNested_ExampleNested2_ExampleNested3(field1 = "Test") | |
exampleNested.field1.field2.add(exampleNested3) | |
exampleNested.field1.field2.add(exampleNested3_1) | |
msg.field1.add(exampleNested) | |
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 Example { | |
message ExampleNested { | |
message ExampleNested2 { | |
string field1 = 1; | |
message ExampleNested3 { | |
string field1 = 1; | |
} | |
repeated ExampleNested3 field2 = 2; | |
} | |
ExampleNested2 field1 = 1; | |
} | |
repeated ExampleNested field1 = 1; | |
} |
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 | |
msg = test_pb2.Example() | |
exampleNested = msg.field1.add() | |
exampleNested.field1.field1 = "Test" | |
exampleNested3 = exampleNested.field1.field2.add() | |
exampleNested3.field1 = "Test" | |
exampleNested3_1 = exampleNested.field1.field2.add() | |
exampleNested3_1.field1 = "Test" | |
with open("data.bin", "wb") as f: | |
f.write(msg.SerializeToString()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment