Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
Add setup- and usage instructions.
  • Loading branch information
pmuens authored Mar 2, 2022
1 parent f0370bf commit 4593663
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions borsh/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
# Borsh-as

**borsh-as** is an assemblyscript implementation of the [borsh](borsh.io) serializer.
**borsh-as** is an assemblyscript implementation of the [borsh](https://borsh.io) serializer.

## How to use it

Install the package via `yarn add @serial-as/borsh` and add the `--transform @serial-as/transform` flag to your `asc` command.

```ts
import { Borsh } from '@serial-as/borsh'
import { BorshSerializer, BorshDeserializer } from '@serial-as/borsh'

@serializable
class Pair{
x: i32 = 0,
y: i32 = 0
}

let pair:Pair = {x:1, y:2}
let pair: Pair = {x:1, y:2}

// serialized is the u8 buffer [0, 0, 0, 1, 0, 0, 0, 2]
let serialized:ArrayBuffer = Borsh.serialize(object)
// `serialized` is the u8 buffer [0, 0, 0, 1, 0, 0, 0, 2]
let serialized: ArrayBuffer = BorshSerializer.encode(object)

// decoded is the Pair = {x:1, y:2}
let decoded:Pair = Borsh.deserialize<Pair>(serialized)
// `decoded` is the Pair = {x:1, y:2}
let decoded: Pair = BorshDeserializer.decode<Pair>(serialized)
```

## Limitations

Assemblyscript does not have Enums, nor allows to predefine the lenght of an array. Because of this, Borsh-as has the following limitations:

- Does **not** deserialize Enums.
- Does **not** deserialize fixed-size arrays.
- Does **not** deserialize fixed-size arrays.

0 comments on commit 4593663

Please sign in to comment.