hi there, and thanks for your time
the general idea is I have a xdr service contract defined in .x files and im trying to create utils for its data encode/decode.
now in detail:
i have generated .rs file from .x xdr declaration (rust-xdr/xdrgen at master · jsgf/rust-xdr · GitHub)
this .rs file contains multiple struct definitions and each of them has encode/decode implementations.
the common structure of data is this:
struct Message {
// … some other fields
data: Vec<u8> // which you have to decode with Response
}
struct Response {
// … some other fields
payload: Option<Vec<u8>> // which you have to decode with Detail
}
struct Detail {
// … some other fields
payload: Option<Vec<u8>> // here is where common shape ends and you have to decode this field
// with different structs, for example ArbitraryStruct
}
struct ArbitraryStruct {
// use this struct implementation to decode/encode Detail.payload
}
the problem here is that each of ArbitraryStruct
's are of different shape, and some of these structs contain fields on different levels of nesting that should be also encoded/decoded, for example
struct OtherStruct {
// you use this struct implementation to decode/encode Detail.payload
macAddr: Option<mac>
}
and the mac definition is this (which also has encode/decode implementations)
pub struct mac(pub [u8; 6i64 as usize]);
there are about 3 or 4 of these additional structs like mac
so far i came up with straightforward implementation of a general function that will encode/decode up until message.response.detail and detail.payload will be encoded/decoded with a closure that will be passed to this general function, but that does not solve macAddr
problem and overall the solution seems not "Rust-y"
any guidance will be much appreciated!