Skip to content

Decoding not existing oneof field should return an error #94

@pallix

Description

@pallix

When decoding a message using a oneof with a field that has not been defined by the code doing the decoding, no error is thrown. Instead, the field has the nil value. It would be better if the decode function would fail with an explicit error instead of giving an invalid result.

Example:

one_of.proto


message SampleOneofMsg {
  optional string one = 1;

  oneof foo {
    string body = 3;
    uint32 code = 4;
  }
}

message SampleOneofExtMsg {
  optional string one = 1;

  oneof foo {
    string body = 3;
    uint32 code = 4;
    string meta = 5;
  }
}

This code:

    msg_ext = Msgs.SampleOneofExtMsg.new(foo: {:meta, "meta"}, one: "test")
    enc_msg = Protobuf.Serializable.serialize(msg_ext)

    IO.inspect(Msgs.SampleOneofMsg.decode(enc_msg))

will return:

%Protobuf.Oneof.Test.Msgs.SampleOneofMsg{foo: nil, one: "test"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions