serde-fressian = "0.1.0"

Fressian is a self-describing binary serialization format developed for clojure.

wasm⥪fressian⥭cljs

When compiled for WebAssembly, serde-fressian can be used to convey rich values to and from clojurescript.

serde-fressian has 2 companion projects:

A WIP

Usage

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 = vec!["some".tostring(), "strings".to_string()];

let bytes: Vec = ser::to_vec(&data).unwrap();

// this is strongly typed deserialization let readdata: Vec = de::fromvec(&bytes).unwrap();

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 = vec!["some".tostring(), "strings".to_string()];

let bytes: Vec = ser::to_vec(&data).unwrap();

// 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))

```

Wasm API

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

[no_mangle]

pub extern "C" fn echo(ptr: *mut u8, len: usize) -> *mut u8 { // read a value from javascript let val: Result = wasm::from_ptr(ptr, len);

// 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)

} ```

About Fressian

Fressian was designed by Stuart Halloway and the good people of Cognitect. There is a clojure wrapper here. There is a design talk here.