Skip to content

Commit

Permalink
add support for inheritance and string variants
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-pousette committed Jun 17, 2022
1 parent e944512 commit 2de7021
Show file tree
Hide file tree
Showing 5 changed files with 549 additions and 230 deletions.
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![NPM version](https://img.shields.io/npm/v/@dao-xyz/borsh.svg?style=flat-square)](https://npmjs.com/@dao-xyz/borsh)
[![Size on NPM](https://img.shields.io/bundlephobia/minzip/@dao-xyz/borsh.svg?style=flat-square)](https://npmjs.com/@dao-xyz/borsh)

**Borsh TS** is *unofficial* implementation of the [Borsh] binary serialization format for TypeScript projects. The motivation behind this library is to provide more convinient methods using **field and class decorators.**
**Borsh TS** is a Typescript implementation of the [Borsh] binary serialization format for TypeScript projects. The motivation behind this library is to provide more convinient methods using **field and class decorators.**

Borsh stands for _Binary Object Representation Serializer for Hashing_. It is meant to be used in security-critical projects as it prioritizes consistency,
safety, speed, and comes with a strict specification.
Expand Down Expand Up @@ -123,6 +123,18 @@ class TestStruct {
}

```
Variants can be 'number', 'number[]' (represents nested Rust Enums) or 'string' (not part of the Borsh specification). i.e.

```typescript
@variant(0)
class ClazzA
...
@variant([0,1])
class ClazzB
...
@variant("clazz c")
class ClazzC
```


**Nested Schema generation for structs**
Expand Down Expand Up @@ -230,7 +242,27 @@ validate([TestStruct])
```

## Inheritance
Schema generation with class inheritance is not supported (yet)
Schema generation is supported if deserialization is deterministic
e.g.
```typescript
class A {
@field({type: 'number'})
a: number
}

@variant(0)
class B1 extends A{
@field({type: 'number'})
b1: number
}

@variant(1)
class B2 extends A{
@field({type: 'number'})
b2: number
}

```


## Type Mappings
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@dao-xyz/borsh",
"version": "2.0.7",
"version": "2.1.0",
"readme": "README.md",
"homepage": "https://github.com/dao-xyz/borsh-ts#README",
"description": "Binary Object Representation Serializer for Hashing",
"description": "Binary Object Representation Serializer for Hashing simplified with decorators",
"author": "dao.xyz",
"license": "Apache-2.0",
"type": "module",
Expand Down
Loading

0 comments on commit 2de7021

Please sign in to comment.