gballet / zig-rlp

A zig implementation of RLP
The Unlicense
7 stars 2 forks source link

Optionally allow clients to specify allocation strategy #16

Open jsign opened 8 months ago

jsign commented 8 months ago

This issue is mostly to trigger some discussion about the behavior of the library with the passed rlp bytes.

For example, whenever deserializing a slice of u8 it subslice the original rlp bytes as a reference in the []u8 field.

What this means is that the caller should be aware that the passed rlp bytes lifetime is tied now to the deserialized object lifetime. Today, this is the default (and only) behavior (which we should at least try to document in the API method).

I'd say that in the future it might be nice to take a similar approach as done in std.json, where the caller can provide std.json.AllocWhen as an "options" parameter when calling the decode API, and choose if wants to avoid copies or always make copies.