Skip to content

Instantly share code, notes, and snippets.

@drygdryg
Created January 2, 2021 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drygdryg/17a7c693330ccf932989fb9401e7eb92 to your computer and use it in GitHub Desktop.
Save drygdryg/17a7c693330ccf932989fb9401e7eb92 to your computer and use it in GitHub Desktop.
protobuf-nim bug
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)
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;
}
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