mirror of
https://github.com/fluencelabs/aquavm
synced 2025-07-02 08:01:33 +00:00
feat(interface)!: Use MessagePack for calls (#780)
Top-level structs use multicodec-prefixed MessagePack, the nested structures (arguments, tetraplets) use just ordinary MessagePack. * JS-compatible `CallResults` Binary format implementations like `rmp-serde` do not bother converting keys from strings, unlike `serde_json`. So, we use `CallResults` with string keys, as JS client cannot produce anything else. --------- Co-authored-by: Mike Voronov <michail.vms@gmail.com>
This commit is contained in:
@ -17,7 +17,7 @@ path = "src/lib.rs"
|
||||
[dependencies]
|
||||
marine-rs-sdk = {version = "0.10.2", optional = true }
|
||||
fluence-it-types = { version = "0.4.1", optional = true }
|
||||
air-interpreter-sede = { version = "0.1.0", path = "../interpreter-sede", features = ["json"] }
|
||||
air-interpreter-sede = { version = "0.1.0", path = "../interpreter-sede", features = ["msgpack"] }
|
||||
|
||||
marine-call-parameters = { version = "0.10.3", default-features = false }
|
||||
serde = "1.0.190"
|
||||
|
@ -18,7 +18,8 @@ use air_interpreter_sede::define_simple_representation;
|
||||
use air_interpreter_sede::derive_serialized_type;
|
||||
use air_interpreter_sede::Format;
|
||||
use air_interpreter_sede::FromSerialized;
|
||||
use air_interpreter_sede::JsonFormat;
|
||||
use air_interpreter_sede::MsgPackFormat;
|
||||
use air_interpreter_sede::MsgPackMultiformat;
|
||||
use air_interpreter_sede::Representation;
|
||||
|
||||
use marine_call_parameters::SecurityTetraplet;
|
||||
@ -36,9 +37,9 @@ derive_serialized_type!(SerializedCallArguments);
|
||||
derive_serialized_type!(SerializedTetraplets);
|
||||
derive_serialized_type!(SerializedCallRequests);
|
||||
|
||||
pub type CallArgumentsFormat = JsonFormat;
|
||||
pub type TetrapletsFormat = JsonFormat;
|
||||
pub type CallRequestsFormat = JsonFormat;
|
||||
pub type CallArgumentsFormat = MsgPackFormat;
|
||||
pub type TetrapletsFormat = MsgPackFormat;
|
||||
pub type CallRequestsFormat = MsgPackMultiformat;
|
||||
|
||||
define_simple_representation! {
|
||||
CallArgumentsRepr,
|
||||
@ -74,7 +75,7 @@ impl FromSerialized<Vec<Vec<SecurityTetraplet>>> for TetrapletsRepr {
|
||||
&self,
|
||||
repr: &[u8],
|
||||
) -> Result<Vec<Vec<SecurityTetraplet>>, Self::DeserializeError> {
|
||||
CallArgumentsRepr.get_format().from_slice(repr)
|
||||
Self.get_format().from_slice(repr)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,17 +16,19 @@
|
||||
|
||||
use air_interpreter_sede::define_simple_representation;
|
||||
use air_interpreter_sede::derive_serialized_type;
|
||||
use air_interpreter_sede::JsonFormat;
|
||||
use air_interpreter_sede::MsgPackMultiformat;
|
||||
use air_interpreter_sede::Representation;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde_json::Value as JValue;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub type CallResults = HashMap<u32, CallServiceResult>;
|
||||
/// This is a map from a String to a service result for compatibility with JavaScript.
|
||||
/// Binary format implementations like `rmp-serde` do not convert keys from strings, unlike `serde_json`.
|
||||
pub type CallResults = HashMap<String, CallServiceResult>;
|
||||
pub const CALL_SERVICE_SUCCESS: i32 = 0;
|
||||
|
||||
pub type CallResultsFormat = JsonFormat;
|
||||
pub type CallResultsFormat = MsgPackMultiformat;
|
||||
|
||||
derive_serialized_type!(SerializedCallResults);
|
||||
|
||||
@ -55,6 +57,7 @@ impl CallServiceResult {
|
||||
pub fn ok(result: &JValue) -> Self {
|
||||
Self {
|
||||
ret_code: CALL_SERVICE_SUCCESS,
|
||||
// for compatiblity with JavaScript with binary formats, string IDs are used
|
||||
result: result.to_string(),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user