ScorexFoundation / sigmastate-interpreter

ErgoScript compiler and ErgoTree Interpreter implementation for Ergo blockchain
MIT License
62 stars 40 forks source link

Global.serialize function to serialize instance of any type #988

Open kushti opened 3 months ago

kushti commented 3 months ago

Implement Global.serialize function with SAny -> SByteArray signature to serialize an instance of any type.

It is replacing following existing PRs:

https://github.com/ScorexFoundation/sigmastate-interpreter/pull/982 (just started) https://github.com/ScorexFoundation/sigmastate-interpreter/pull/984 (just started) https://github.com/ScorexFoundation/sigmastate-interpreter/issues/974

Header serialization can be found in https://github.com/ScorexFoundation/sigmastate-interpreter/issues/974

Do round-trip tests against Global.deserialize[T] from https://github.com/ScorexFoundation/sigmastate-interpreter/pull/979

aslesarenko commented 3 months ago

It is replacing following existing PRs:

982 (just started) #984 (just started)

@kushti, it may still be useful to have a separate Numeric.toBytes method because generic serialize produces ZigZag encoded bytes for numeric types.

We can call it Numeric.toBigEndianBytes.

This will be consistent with the existing longToByteArray, byteArrayToLong, byteArrayToBigInt, but will work for all numeric types.