Arwalk / zig-protobuf

a protobuf 3 implementation for zig.
MIT License
229 stars 27 forks source link

Can't generate proto files without package name #57

Open osztenkurden opened 2 months ago

osztenkurden commented 2 months ago

Overall, love the generator, and the only thing that stumbled me was the fact that I can't generate zig files from protos without "package" directive.

Currently working on game data parser, and protos look like this:

import "networkbasetypes.proto";
import "usercmd.proto";

message CSGOInterpolationInfoPB {
    optional int32 src_tick = 1 [default = -1];
    optional int32 dst_tick = 2 [default = -1];
    optional float frac = 3 [default = 0];
}

message CSGOInputHistoryEntryPB {
    optional .CMsgQAngle view_angles = 2;
    optional int32 render_tick_count = 4;
    optional float render_tick_fraction = 5;
    optional int32 player_tick_count = 6;
    optional float player_tick_fraction = 7;
    optional .CSGOInterpolationInfoPB cl_interp = 12;
    optional .CSGOInterpolationInfoPB sv_interp0 = 13;
    optional .CSGOInterpolationInfoPB sv_interp1 = 14;
    optional .CSGOInterpolationInfoPB player_interp = 15;
    optional int32 frame_number = 20;
    optional int32 target_ent_index = 8 [default = -1];
    optional .CMsgVector shoot_position = 3;
    optional .CMsgVector target_head_pos_check = 9;
    optional .CMsgVector target_abs_pos_check = 10;
    optional .CMsgQAngle target_abs_ang_check = 11;
}

...

So, no package name. To make it work, Im adding package name by hand, and then I have to also remove dots from the field types on messages (so optional .CSGOInterpolationInfoPB cl_interp = 12; will become optional CSGOInterpolationInfoPB cl_interp = 12;). I'm trying currently to make it work on the fork of the project, but I'm quite new to zig, so it's not going super fast

Arwalk commented 2 months ago

Hello there, thanks for your interest and issue.

Overall, love the generator, and the only thing that stumbled me was the fact that I can't generate zig files from protos without "package" directive.

I think we inherited this behaviour from the original generator that served as basis of this one. It was a go-based one, and it required packages. I'll take a look into it to know if i can find a workaround about this.

I have to also remove dots from the field types on messages

Looking a the proto language spec :

image

It would seem that a dot is allowed before a type name, for some reason. It's also allowed for inner messages, i think. I'll have to look into that, and handle at least properly the beginning dot.

Thank you again.

osztenkurden commented 2 months ago

Thanks, ill try tweaking through the weekend and try to make a PR, but I dont think it will be fast

osztenkurden commented 2 months ago

PR #58 created, still WIP, but I'd appreciate veryfing if it doesn't break existing protos