You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While investigating go-f3 and lotus implementations I have stumbled upon the generated code that checks certain fields for length. That's specified as e.g. cborgen:"maxlen=1000000000.
Going forward it might be nice to have sort of library that'd wrap cbor ser/de and be able to read attributes.
Another thing is that for structs we currently need to implement custom ser/de as follows:
implSerializeforPowerEntry{fnserialize<S>(&self,serializer:S) -> Result<S::Ok,S::Error>whereS: serde::Serializer,{if !self.pub_key.is_valid(){returnErr(serde::ser::Error::custom("Byte array in field pub_key is too long",));}(&self.id,&self.power,&self.pub_key).serialize(serializer)}}impl<'de>Deserialize<'de>forPowerEntry{fndeserialize<D>(deserializer:D) -> Result<Self,D::Error>whereD: serde::Deserializer<'de>,{let(id, power, pub_key) = Deserialize::deserialize(deserializer)?;Ok(Self{
id,
power,
pub_key,})}}
What this does:
Implements said length constraints.
Converts a struct into a tuple in order to serialize
Converts a tuple into a struct in order to deserialize.
If those could be automated - that'd save a lot of boilerplate. Field ordering is easy - just serialize in that same order they are defined. If any of the struct fields need to be transient - have an attribute to ignore them for cbor ser/de.
The text was updated successfully, but these errors were encountered:
While investigating
go-f3
andlotus
implementations I have stumbled upon the generated code that checks certain fields for length. That's specified as e.g.cborgen:"maxlen=1000000000
.Some examples:
Going forward it might be nice to have sort of library that'd wrap cbor ser/de and be able to read attributes.
Another thing is that for structs we currently need to implement custom ser/de as follows:
What this does:
If those could be automated - that'd save a lot of boilerplate. Field ordering is easy - just serialize in that same order they are defined. If any of the struct fields need to be transient - have an attribute to ignore them for cbor ser/de.
The text was updated successfully, but these errors were encountered: