oniksan / godobuf

A Google Protobuf implementation for Godot / GDScript
BSD 3-Clause "New" or "Revised" License
248 stars 34 forks source link

oneof field with messages in it not generating set method #9

Closed Quak0r closed 3 years ago

Quak0r commented 3 years ago

Hello, first of a BIG thank you for all the work that went into this project!

I'm trying to have a message wrapper so I can send only one message over the wire in order to have easier message recognition on the receiving end.

syntax = "proto3";

enum PlayerCommand {
    SHOOT = 0;
}
message PlayerPosition {
    int32 id = 1;
    float x = 2;
    float y = 3;
    float rot = 4;
}

message PlayerInput {
    int32 id = 1;
    float rotL = 2;
    float rotM = 3;
    repeated PlayerCommand com = 4;
}

message PlayerPositions {
    repeated PlayerPosition playerpos = 1;
}

message CompositeMessage {
    oneof payload {
        PlayerPosition playerstart = 1;
        PlayerInput playerupdate = 2;
        int32 removeplayer = 3;
        PlayerPositions allplayersupdate = 4;
    }
  }

the generated code however does not seem to have the setter functions for playerstart, playerupdate and allplayersupdate. The only setter generated is set_removeplayer. The other type of functions like get_playerupdate , clear_playerupdate and new_playerupdate are generated correctly.

oniksan commented 3 years ago

Hello, Quak0r. Your CompositeMessage contains one of three Objects (messages) or one simple type (int32). All simple types are set by setters:

var compositeMessage = MyProto.CompositeMessage.new()
compositeMessage.set_removeplayer(42)

But All Messages are set by creating new Messages (see manual):

var compositeMessage = MyProto.CompositeMessage.new()
var player = compositeMessage.new_playerupdate()
player.set_id(10)
player.rotL(15.)
...

It seems something like this :)

Quak0r commented 3 years ago

Ah! I must have missed that in the manual. Just tested it quickly and it adds the different messages to the CompositeMessage wrapper correctly!

Thank you!