Open winksaville opened 1 year ago
I've now got fn get_id_str_from_buf
:
https://github.com/winksaville/exper_inter_process_channel/blob/0eb7a71ae3c48e359e4aefc129ed87aca557d7fc/msg_serde_json/src/lib.rs#L6-L25
And use it in msg1
:
https://github.com/winksaville/exper_inter_process_channel/blob/0eb7a71ae3c48e359e4aefc129ed87aca557d7fc/msg1/src/lib.rs#L49-L53
and msg_serded_macro
:
https://github.com/winksaville/exper_inter_process_channel/blob/0eb7a71ae3c48e359e4aefc129ed87aca557d7fc/msg_serde_macro/src/lib.rs#L43-L46
to validate a msg is being deserialized properly.
I've also added fn get_msg_id_from_boxed_msg_any
:
https://github.com/winksaville/exper_inter_process_channel/blob/0eb7a71ae3c48e359e4aefc129ed87aca557d7fc/msg_header/src/lib.rs#L33-L38
and it can be used to get a MsgId
from BoxedMsgAny
and then use a hashmap to convert a BoxedMsgAny
directly to a serialized format using a HashMap<<MsgId>, ToSerdeJsonBuf>
such as I've done here:
https://github.com/winksaville/exper_inter_process_channel/blob/0eb7a71ae3c48e359e4aefc129ed87aca557d7fc/src/main.rs#L208-L216
I've stumbled across a critical issue, the serialization output of two different messages can be identical.
This happened to me when I
serde
Msg1 and then copied/pasted the code to test Msg2 and didn't change the type fromserde_json::from_str::<Msg1>
to<Msg2>
. Because the serialization of Msg1 and Msg2 are identical deserialization works just fine. But the rust TypeId is Msg1 while the MsgHeader::id field is the MSG2_ID value.See the
test_identical_json
which shows thatserde_json::from_str
succeeds when it would be preferable that it fail.I searched for how to validate during serde::from_string and issue serde issue 939 may help. Of course there may be better solutions too :)
The
--nocapture
output indicates this "should fail":