# (Non-protocol-specific) binary serialization library?

**URL:** <https://discuss.ocaml.org/t/non-protocol-specific-binary-serialization-library/2768>\
**Category:** Learning\
**Created:** [October 24, 2018, 6:37pm UTC](https://discuss.ocaml.org/t/non-protocol-specific-binary-serialization-library/2768 "2018-10-24T18:37:32Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![BrendanLong](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/brendanlong/32/522_2.png) [@BrendanLong](https://discuss.ocaml.org/u/BrendanLong)\
**Post date:** [October 24, 2018, 6:37pm UTC](https://discuss.ocaml.org/t/non-protocol-specific-binary-serialization-library/2768/1 "2018-10-24T18:37:33Z")

</div>

I’ve been working on several libraries that need to send and receive packets in specific binary formats ([PGX](https://github.com/arenadotio/pgx), [TDS](https://github.com/brendanlong/ocaml-tds)). Right now they both have extremely-low-level code to convert ints to bytes with the right endianness, but it seems excessively low level to put in every library I write that deals with a binary protocol.

I know there are a bunch of libraries for parsing text, or for working with defined protocols like msgpack, but is there anything for arbitrary binary encoding? I’m thinking something like [struct](https://docs.python.org/3/library/struct.html) in Python, although I’m not married to that particular implementation.

(As a side note: Another reason I’d like something like this is that all of my current implementations handle one byte at a time, and it would be nice if we could do this more efficiently).

---

_[View the full topic](https://discuss.ocaml.org/t/non-protocol-specific-binary-serialization-library/2768)._
