oniksan / godobuf

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

bug: proto3 default map key breaks deserialization #23

Closed conradhappeliv closed 2 years ago

conradhappeliv commented 2 years ago

I have a proto3 map field with int32 keys:

message GameState {
    map<int32, PlayerData> player_data = 6;
}

This normally works, except when the map key is 0.

For example, this code is broken because from_bytes returns error REQUIRED_FIELDS:

var s = API.GameState.new()
s.add_player_data(0)
print(s.from_bytes(s.to_bytes()))  # Prints -9, aka "REQUIRED_FIELDS".

However, when I change the map key to something else (e.g. 1), deserialization works fine.

I assume this is due to improper handling of default values as map keys. I haven't tested it, but I assume the same issue is present for other default types (e.g. empty strings).

oniksan commented 2 years ago

Bug fixed in v 0.5.0