-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from pmuens/patch-2
Update Borsh README
- Loading branch information
Showing
1 changed file
with
12 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
||
Assemblyscript does not have Enums, nor allows to predefine the length 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. |