Out_channel -> Uint8array, Uint8array -> In_channel?

I think I am missing something very obvious here.

I am writing serialization / deserialization routines for OCaml values ↔ Uint8array. The reason I am doing this manually is I need to write it in a way I can read/write in Rust also.

Currently, I have code that can write a OCaml value to an Out_channel. I also have code for reading an OCaml value from an In_channel.

The part I’m stuck on: Within js_of_ocaml, how do I do Out_channel → Uint8Array and Uint8Array → In_channel ?

In the first case, I want to take what was written to an Out_channel and convert it to a Uint8Array. In the second case, I want to take an Uint8Array, then construct an In_channel we can read from.