serde-fressian = "0.1.1"
![Latest Version]Fressian is a self-describing binary serialization format developed for clojure.
When compiled for WebAssembly, serde-fressian can be used to convey rich values to and from clojurescript.
serde-fressian tries to follow the standard serde conventions. Deserializers can accept readers, vecs, and slices. Serializers at this time however only support writing to vecs.
```rust use serdefressian::ser; use serdefressian::de;
let writedata: Vec
let bytes: Vec
// this is strongly typed deserialization
let readdata: Vec
asserteq!(writedata,read_data) ```
If you know ahead of time what the bytes are going to contain, you can use strongly typed deserialization to extract your values. This is less flexible but is very fast. If you are unsure of the content, serde_fressian::value::Value
is an enum encompassing all fressian types and will deserialize values as they are described.
```rust use serdefressian::ser; use serdefressian::de; use serde_fressian::value::{Value};
let writedata: Vec
let bytes: Vec
// this is weakly typed deserialization let readdata: Value = de::fromvec(&bytes).unwrap();
// Value::LIST(vec![Value::STRING("some".tostring()),Value::STRING("strings".tostring())]) asserteq!(readdata, Value::from(write_data))
```
The serde_fressian::wasm
module is designed to interop with fress.wasm
```rust use serdefressian::error::{Error as FressError}; use serdefressian::value::{self, Value}; use serde_fressian::wasm::{self};
// called by javascript with ptr to written bytes
pub extern "C" fn echo(ptr: *mut u8, len: usize) -> *mut u8
{
// read a value from javascript
let val: Result
// from_ptr borrows, Value copies. So must own and free bytes separately
wasm::fress_dealloc(ptr, len);
//serializes the result, hands ownership of resulting bytes over to js
wasm::to_js(val)
} ```
For my own sanity, most documentation will be over at fress
Fressian was designed by Stuart Halloway and the good people of Cognitect. There is a clojure wrapper here. There is a design talk here.