-
Notifications
You must be signed in to change notification settings - Fork 286
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
Cannot (de)serialize objects with optional fields #112
Comments
One option is a method dedicated to pattern matching and dispatching, used like: sedes_options = (BlockDetails, ShortBlockDetails)
try:
rlp_obj, sedes_idx = rlp.dispatch_decode(encoded, sedes=sedes_options)
except rlp.AmbiguousDispatchError:
# multiple sedes were capable of decoding the rlp, so no way to know which one is correct
except rlp.MissingDispatchError:
# None of the sedes could decode the rlp
assert sedes_index in (0, 1) # identifies which serializer was used where I think the logic of: "these two serializers are actually for the same thing and we should merge them" should not be in pyrlp. It's easy enough to wrap the above example to create that effect. |
Oof, looks like we need to support serializing structures that are sometimes lists and sometimes byte-strings, so this becomes relevant again. (see https://ethereum-magicians.org/t/eip-2718-typed-transaction-envelope/4355/59?u=carver ) Looking into options now... |
Actually, this is pretty straightforward to just implement by hand, and I'm not sure the generalized solution would have added much value here. Maybe just a new page in the docs. See a WIP example here: ethereum/py-evm#1980 Note how |
Parity uses a custom
BlockDetails
object with a very weird last field.is_finalized
is a boolean field with the following representation:True
is represented as a True boolean field:len(BlockDetails) == 5
False
is represented as nothing:len(BlockDetails) == 4
Presumably they wanted to save a little space in the database by simply not saving this field.
I don't think it's possible to create a subclass of
rlp.Serializable
which handles this use-case.The text was updated successfully, but these errors were encountered: