I am serializing data, which can be an integer, an object (list) with other nested objects, and try to make a choice as to which approach to use. The first two are to recursively create byte vectors and copy them in the calling functions to a larger one byte vector; the second is to use some kind of stream that I could write. In the end, despite the choice, I could use the resulting binary array in any further processing that might happen, for example. d. I would compress the output and send it over the network or just write some parts of it to a file.
I would like to remain functional enough (or fully), but implementing a fast serializer. I use Racket , although any other implementation of the Scheme will also perform.
Thank.
UPDATE:
The following are examples that I added after I found a solution so that users could save time looking for ways to write data:]
write-byteand write-bytesespecially useful when you need to write octets.
> (bytes? (with-output-to-bytes (lambda () (write-byte 42))))
#t
> (bytevector? (with-output-to-bytes (lambda () (write-byte 42))))
#t
> (bytevector->u8-list (with-output-to-bytes (lambda () (write-byte 42))))
{42}
> (bytes->list (with-output-to-bytes (lambda () (write-byte 42) (write-bytes (integer->integer-bytes
(42 1 1 202 117)
source
share