https://github.com/dao-xyz/borsh-ts
⚡️fast TypeScript implementation of Borsh serialization format
https://github.com/dao-xyz/borsh-ts
borsh borsh-js near solana
Last synced: 10 months ago
JSON representation
⚡️fast TypeScript implementation of Borsh serialization format
- Host: GitHub
- URL: https://github.com/dao-xyz/borsh-ts
- Owner: dao-xyz
- License: apache-2.0
- Fork: true (near/borsh-js)
- Created: 2021-11-07T09:23:05.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-05-19T11:34:49.000Z (about 2 years ago)
- Last Synced: 2025-01-18T01:20:58.549Z (over 1 year ago)
- Topics: borsh, borsh-js, near, solana
- Language: TypeScript
- Homepage:
- Size: 360 KB
- Stars: 42
- Watchers: 1
- Forks: 4
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
- awesome - dao-xyz/borsh-ts - ⚡️fast TypeScript implementation of Borsh serialization format (TypeScript)
README
## borsh-ts monorepo
[](https://opensource.org/licenses/Apache-2.0)
[](https://opensource.org/licenses/MIT)
[](https://npmjs.com/@dao-xyz/borsh)
[](https://npmjs.com/@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
```ts
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](./packages/borsh/README.md)
## EXPERIMENTAL: Package: @dao-xyz/borsh-rpc
```ts
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](./packages/rpc/README.md)
## Development
```bash
yarn install
yarn build
yarn workspaces:test
```
## License
Apache-2.0 and MIT. See LICENSE files.