-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do we want to use serde_json::Value in the public API? #43
Comments
For most of the packages in VirTEE we have been placing any serde related dependencies behind a feature flag. I am definitely open to either of these ideas. Let me look into this a bit deeper. It might make sense to allow various methods of passing the extra_params based upon the use-case. |
@mkulke I think it would be fine to have Another observation is that there are two parts that will consume the messages. The version of |
if we use a serialization type as a data-type on the public structure, it will force consumers to pull in serde, serde_json, and serde_derive into their projects, which might be unacceptable in certain situations (restricted environments like fw or a limited set of allowed dependencies). another nuisance could be version mismatch on a consuming crate if you have to use a pinned version and there are incompatibilities in the patch version.
maybe the ergonomic improvements between raw bytes and untyped json aren't so big either, in both cases you have to serialize/deserialize: let extra_params_json= json!({
"extra": "data",
});
request.extra_params = extra_params_json;
...vs
#[repr(C)]
struct ExtraParams {
"extra": String,
}
let extra_params = ExtraParams { extra: "data".into() };
request.extra_params = bincode::serialize(&extra_params).unwrap();
..and
let extra_params = serde_json::from_value::<ExtraParams>(request.extra_params).unwrap()
...vs
let extra_params: ExtraParams = bincode::deserialize(&request.extra_params).unwrap(); |
@mkulke Yea, actually the change does not import any new crates like About dependency version conflict, the version is |
I think the problem is putting a serialization type on the public api, not using serde in the project (although it should behind a feature flag, imo). We know how to work around this, the issues I'm referencing do not appear in unrestricted high-level code (like trustee) where you can just bump your dependencies freely, it's more about restricted low-level projects (like coconut svsm). If that's not a problem scope for kbs-types, we can close this issue. cc @larrydewey |
Might be off of the topic -- in |
kbs-types/src/lib.rs
Line 49 in ec9b1b4
I guess the idea is to allow arbitrary, untyped json-like data on the extra_params field. I'm not sure that using the type of a serialization library on a public API is a good idea, since this will introduce a transitive dependency on serde_json and consumers might have to deal with version mismatches or having to perform extra conversion when using a different serialization library.
Alternatives would be to provie some sort of flexible tree structure, which doesn't have to be full json, or just type extra_params as
Vec<u8>
, since processors of extra_params have to perform a parsing step anyway, also with serde_json::Value.The text was updated successfully, but these errors were encountered: