Skip to content

Repository files navigation

serde_v8vs

serde support for V8's ValueSerializer format (used by Node.js/Deno's Serialization API) so you can easily send data between Rust & JS without resorting to JSON or non-native encoders/decoders.

Compatibility

Supports format versions 13-16 (Node.js v8.x+ and any Deno version that supports ValueSerializer). Serialization outputs version 15 (Node.js v18+) by default, but this can be configured.

⚠️ This crate does not support host objects, which Node.js/Deno's default serialize function (backed by DefaultSerializer) uses to serialize typed arrays. When serializing in JS, you must create a blank serializer:

// ❌ - won't work with `serde_v8vs`
import { serialize } from 'node:v8';
const bytes = serialize(new Uint8Array([ 1, 2, 3 ]));
// ✅ - will work everywhere
import { Serializer } from 'node:v8';

function compatSerialize(value: any): Uint8Array {
	const serializer = new Serializer();
	serializer.writeHeader();
	serializer.writeValue(value);
	return serializer.releaseBuffer();
}

const bytes = compatSerialize(new Uint8Array([ 1, 2, 3 ]));

Supported external types

  • serde_bytes
  • jiff
    • Supports jiff::Timestamp, requires Cargo feature
    • v0.2: features = [ "jiff-0_2" ]
  • chrono
    • Supports chrono::DateTime<Utc>, requires Cargo feature
    • v0.4: features = [ "chrono-0_4" ]

About

Serde support for V8's `ValueSerializer` format

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages