refactor(rust): enable requests to be messages #8783
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.
This PR adjusts the serialization / deserialization of Ockam messages.
Motivation
The initial motivation was to be able to define
Request<T>
as a type ofMessage
for workers processing messages.Some additional objectives are to:
Encodable / Decodable
interfaces from theSerializable / Deserializable
implementations provided by theserde_bare
libraryRequests
are currently doubly-encoded, once as aVec<u8>
withminicbor
and then serialized withserde_bare
. Fixing this issue will be a one-line (or 2) change after this PR but it is a breaking change, so I left this for later.Changes
The main changes are:
Encodable
andDecodable
.Encodable
andDecodable
for aRequest<T>
provided thatT: Message
.Message
instance (that explains the number of touched files)ask/tell/request/...
methods for both requests and responses.Requests
in workers like theNodeManager
to:Request<Vec<u8>>
(now by the virtue ofRequest<T>
being aMessage
) in order to read theRequestHeader
.Decodable<T>
instance we know the expected type based on the header. Note that this is done without having to know that the request body was encoded usingminicbor
.