You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using sbe-tools to generate java code, the encoders and decoders implement toString() that returns a human-readable representation of all the fields of the message. For example:
Having a human-readable representation makes debugging much, much easier, as you can print the SBE messages and check what exactly you're sending/receiving.
When generating rust, currently there's nothing like the java's toString(). The encoders and decoders derive Debug, but it prints just the name of the struct and the buffer, which is not that useful.
Could we implement Display using the exactly same format as Java for both encoders and decoders?
The text was updated successfully, but these errors were encountered:
My first try was to implement Display for all decoders. However, as some nested decoders need to receive self as value, it's not possible to print their fields with just &self as is the signature of Display.
Thus, I created another trait with a method that does the same thing, returns a human readable representation of the decoders and its fields, but which receives self as value. As the client will probably keep using self, the method also returns it.
The trait is defined as:
/// Returns a human-readable string representation of the SBE message./// This trait works like `ToString`, but it takes `self` as value/// to be compatible with the generated decoders.pubtraitSbeToString:Sized{/// Returns a human-readable string along with the consumed `self`.fnsbe_to_string(self) -> SbeResult<(Self,String)>;}
The returned String has the same syntax (as far as I compared) as generated by the Java decoders' toString(). For example:
I changed the rust generator code to implement SbeToString for all decoders, so decoders with fields which also requires decoders, like composite ones, may just call sbe_to_string for each of them.
Here is the PR with the changes. The PR is not ready, as it's missing tests and some docs. But I preferred to have some feedback earlier, before commiting more time to it.
Please let me know your thoughts about this proposal and/or suggestions.
marciorasf
changed the title
[Rust] Implement Display for encoders and decoders
[Rust] Implement a to_string like method to generate a human-readable representation of decoder's fields
Mar 27, 2025
When using sbe-tools to generate java code, the encoders and decoders implement
toString()
that returns a human-readable representation of all the fields of the message. For example:Having a human-readable representation makes debugging much, much easier, as you can print the SBE messages and check what exactly you're sending/receiving.
When generating rust, currently there's nothing like the java's
toString()
. The encoders and decoders deriveDebug
, but it prints just the name of the struct and the buffer, which is not that useful.Could we implement
Display
using the exactly same format as Java for both encoders and decoders?The text was updated successfully, but these errors were encountered: