Use Vec<u8>
as middle man to deserialize various types
#483
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While developing #474, we wanted an easy way to convert the old
ChannelActorState
struct to a newChannelActorState
struct (if the newer struct only adds a few fields with default value or removes a few obsolete fields). We triedserde_json
which does not work because json can't serialize binary data natively.We then tried cbor. To our surprise, current code can't even deserialize the serialized result of a
ChannelActorState
. This is shown in the commit 6f9d1bffdb5a7b41cbc127835c194cb44c37dcb4. The testtest_serde_channel_actor_state_ciborium
will fail with errorSemantic(None, "invalid type: byte array, expected a borrowed byte array")
(see github actions log).After some investigation, I found we need to deserialize the data to
Vec<u8>
instead of&[u8]
. I don't know why bincode deserializtion succeeded. But there are many similar issues on github (e.g. jonasbb/serde_with#372 (comment) and serde-rs/json#530 ). With the change in commit 99298012ef362ccfd0c9fa8832196cb09daad29e, I can successfully deserialize data with cbor.I have tried the patch in this PR to successfully convert from one
ChannelActorState
to anotherChannelActorState
with some additionalOption
fields (code: chengyukang:refactor-migration-with-crate...contrun:fiber:refactor-migration-with-crate). I didn't add the simpler approach to #474 because we need to back port this PR to fiber v0.2.0, v0.2.1 and v0.3.0-rc1. There is also one field in v0.3.0-rc1local_tlc_info
which has no default value.