Help serializing dart classes created by Rinf #314
Replies: 3 comments
-
Hi Mike :) By default, Protobuf generation with If it's for logging purposes, you can simply use these macros to convert them into string or similar: debug_print!("{number_input:#?}");
let string_message = format!("{number_input:#?}"); ...where |
Beta Was this translation helpful? Give feedback.
-
I want to reload the state of the app when it reopened. To be clear this
would be on the dart side not the rust side. The app state I am trying to
restore is generated randomly by rust and used in dart. I want to cache
this response from rust but the rinf generated dart class is very hard to
extend. As a feature "thought experiment": I would want to just be able to
tag Protobuf message with "// [RINF: Serializable ]" and have the framework
do the lifting. This is a very strong use case. If anyone could give
guidance doing the serialization in dart that would be great. I am trying
to avoid writing dartside lib\messages folder generated by rinf as these
files are generated and the method to serialize would be lost every time I
ran "rinf message".
Mike
…On Sun, Apr 14, 2024 at 2:30 AM Donghyun Kim ***@***.***> wrote:
Hi Mike :)
By default, Protobuf generation with rinf message doesn't include
JSON-related methods in the message structs. May I ask you why you need to
convert messages into JSON? Are you doing something like REST API requests?
If it's for logging purposes, you can simply use these macros to convert
them into string or similar:
debug_print!("{number_input:?}");let string_message = format("{number_input:?}");
...where number_input is a struct generated by Protobuf.
—
Reply to this email directly, view it on GitHub
<#314 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIGSF53P62YMAP3CKRT63LY5JEC7AVCNFSM6AAAAABGF5NML6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TCMBYGMYDK>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Sorry I'm late, I've been busy during the whole weekdays. So you want to save the application state by serializing those Protobuf messages on the Dart side. Does it really need to be JSON? You can easily serialize the message into bytes( // Serialize
var bytes = MyMessage().writeToBuffer(); // Generated by Protobuf
// Save this binary data to disk, ect...
// Deserialize
// Load the binary data from disk, etc...
var myMessage = MyMessage.fromBuffer(bytes); |
Beta Was this translation helpful? Give feedback.
-
I am trying to serialize and cache the results of [RINF:RUST-SIGNAL] class that was generated by the protobuf message def. There is no toJson method on the generated class. I am new to flutter and rinf. I tried looking at extension methods for the generated class. As I am not supposed to modify theses generated class what would be best to add toJson / serialization method? Any help suggestions
Mike
Beta Was this translation helpful? Give feedback.
All reactions