Skip to content

fix: add UNSPECIFIED = 0 to enums without a zero value#38

Open
VolatilCapital wants to merge 1 commit into
spotware:mainfrom
VolatilCapital:fix/add-enum-zero-values
Open

fix: add UNSPECIFIED = 0 to enums without a zero value#38
VolatilCapital wants to merge 1 commit into
spotware:mainfrom
VolatilCapital:fix/add-enum-zero-values

Conversation

@VolatilCapital

Copy link
Copy Markdown

Summary

  • Adds an UNSPECIFIED = 0 entry to 18 enums that lack a zero value
  • Fixes silent serialization issues with modern protobuf code generators that skip fields matching the first enum value (treated as default)
  • Fully backward-compatible: no existing numeric values are changed

Fixes #37

Affected enums

ProtoPayloadType, ProtoErrorCode, ProtoOAPayloadType, ProtoOACommissionType, ProtoOASymbolDistanceType, ProtoOAMinCommissionType, ProtoOAPositionStatus, ProtoOATradeSide, ProtoOAOrderType, ProtoOATimeInForce, ProtoOAOrderStatus, ProtoOAOrderTriggerMethod, ProtoOAExecutionType, ProtoOADealStatus, ProtoOATrendbarPeriod, ProtoOAQuoteType, ProtoOANotificationType, ProtoOAErrorCode

Modern protobuf code generators treat the first enum value as the
default and skip serialization when a field matches it. This causes
silent data loss for enums like ProtoOATradeSide (BUY=1) or
ProtoOATrendbarPeriod (M1=1) where the first value is a valid choice.

Adding UNSPECIFIED = 0 ensures all real values are always serialized.
This is fully backward-compatible: existing numeric values are unchanged.

Fixes spotware#37
@raul-gherman

Copy link
Copy Markdown

you only consider your use case
I doubt this request will be approved and implemented, as it would require consistent changes on the backend
not sure about your protobuf generator, but rust goes very well - both prost and quick_protobuf...
just my 2 cents

PS
don't get me wrong - I understand your issue, and I have many (some reported here, some placed in forum, discord or email threads, but most of them silenced -- adjust .proto on your end as you like as long as you make sure you do not sent invalid / illegal values over the wire -- and yes, this comes at an extra cost of maintaining .proto on your own, instead of waiting for a fix that might not come)
no need to hear me out on this one, just study this repo's issues and history...

@VolatilCapital

Copy link
Copy Markdown
Author

Thanks for your feedback.

To clarify: these changes in the .proto files will not affect the server, in the sense that they do not change the server’s processing. Their sole purpose is to force the sending of default values, whereas according to the standard protocol specification, these values would normally not need to be sent.

In other words, these changes go against the protocol’s specification, but they are only meant to ensure that the server receives all the values it expects.

For my use case, I have already applied a local fix by making these modifications.
There are many tools for compiling .proto files, and some can be configured to force the sending of default values, but not all. This is a consequence of strictly following the protocol.

That’s why modifying the .proto files is necessary in this specific case, but it wouldn’t be necessary if the server strictly adhered to the protocol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enums without a zero value cause serialization issues with modern protobuf libraries

2 participants