Skip to content

dao-xyz/borsh-ts

 
 

Repository files navigation

borsh-ts monorepo

Project license Project license NPM @dao-xyz/borsh NPM @dao-xyz/borsh-rpc

Two packages:

  • @dao-xyz/borsh — Core Borsh serializer with decorators.
  • @dao-xyz/borsh-rpc — Lightweight RPC over Borsh.

This root README gives a quick taste. Full documentation lives in each subpackage README.

Package: @dao-xyz/borsh

import { deserialize, field, serialize } from "@dao-xyz/borsh";

class User {
	@field({ type: "u32" })
	id: number;
	@field({ type: "string" })
	name: string;

	constructor(init: User) {
		this.id = init.id;
		this.name = init.name;
	}
}

const bytes = serialize(new User({ id: 1, name: "alice" }));
const u = deserialize(bytes, User);

Full docs: ./packages/borsh/README.md

EXPERIMENTAL: Package: @dao-xyz/borsh-rpc

import { field } from "@dao-xyz/borsh";
import {
	LoopbackPair,
	bindService,
	createProxyFromService,
	method,
	service,
} from "@dao-xyz/borsh-rpc";

class Payload {
	@field({ type: "u8" })
	x = 0;
}

@service()
class API {
	@method({ args: "u32", returns: "u32" })
	addOne(n: number) {
		return n + 1;
	}
}

const loop = new LoopbackPair();
const unsub = bindService(API, loop.a);
const client = createProxyFromService(API, loop.b);
await client.addOne(41); // 42
unsub();

Full docs: ./packages/rpc/README.md

Development

yarn install
yarn build
yarn workspaces:test

License

Apache-2.0 and MIT. See LICENSE files.

About

⚡️fast TypeScript implementation of Borsh serialization format

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT.txt

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%