Self referential types in `oneOf` results in error
If there are self referential types in oneOf, then it results in the following error from Zig: struct 'proto.foobar.pb.Node' depends on itself.
Here's an example proto file:
syntax = "proto3";
package foobar;
message Result {
int32 version = 1;
Node node = 2;
}
message Node {
oneof node {
SubNode sub_node = 1;
string some_string = 2;
}
}
message SubNode {
Node sub = 1;
string another_string = 2;
}
The corresponding main file:
const std = @import("std");
const protobuf = @import("protobuf");
const proto = @import("./proto/foobar.pb.zig");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
var arena = std.heap.ArenaAllocator.init(gpa.allocator());
defer arena.deinit();
const foo = try protobuf.pb_decode(proto.Result, "", arena.allocator());
_ = foo;
}
Hello, thanks for your issue.
Zig doesn't allow structures referencing itself, as it tries to calculate the size of the structure at compile time.
I'll look into how we can handle this properly, might have to go through fun pointers with it.
hello @guacs , the branch 69-self-referential-types-in-oneof-resul should have a working solution using a "ManagedStruct" approach (like ManagedString). Would you like to test it?
Sorry for the long time it took to get into it.