# as-serde

> Serde-as is a simple (de)serialization framework for AssemblyScript

Latest version **0.3.0** (published 2023-03-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install as-serde
pnpm add as-serde
yarn add as-serde
bun add as-serde
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2023-03-01 |
| First published | 2021-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 26.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | yjhmelody |
| Maintainers | yjhmelody |
| Keywords | assemblyscript, serde, serialize, deserialize, encode, decode, framework |

## Links

- npm: https://www.npmjs.com/package/as-serde
- Repository: https://github.com/ask-lang/serde-as
- Homepage: https://github.com/ask-lang/serde-as#readme
- Issues: https://github.com/ask-lang/serde-as/issues
- npm.io page: https://npm.io/package/as-serde

## Dependencies (2)

- [as-base64](https://npm.io/package/as-base64.md) ^0.2.0
- [as-serde-transform](https://npm.io/package/as-serde-transform.md) ^0.3.0

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2023-03-01
- 0.2.0 — 2022-08-12
- 0.1.2 — 2022-08-12
- 0.1.1 — 2021-07-20
- 0.1.0 — 2021-07-20
- 0.0.18 — 2021-07-19
- 0.0.17 — 2021-07-16
- 0.0.16 — 2021-07-07
- 0.0.15 — 2021-07-05
- 0.0.14 — 2021-07-02
- 0.0.13 — 2021-07-02
- 0.0.12 — 2021-07-02
- 0.0.11 — 2021-07-01
- 0.0.10 — 2021-07-01
- 0.0.9 — 2021-06-29
- … 6 more at https://npm.io/package/as-serde/versions

## README

# as-serde

> A simple (de)serialize library for AssemblyScript.

## Usage

### install

```sh
npm install --save-dev as-serde
```

Update your asconfig to include the transform:

```json
{
  "options": {
    ... // other options here
    "transform": ["as-serde-transform"]
  }
}
```

### APIs

This package defines four abstract classes: `CoreSerializer`/`Serializer`/`CoreDeserializer`/`Deserializer`.

All methods in `CoreSerializer`/`CoreDeserializer` are used by `as-serde-transform`. That is to say, the automatically generated code depends on these classes.

`Serializer`/`Deserializer` just simply expand `CoreSerializer`/`CoreDeserializer`, making it easier for serialization library authors to implement the required functions.

### Decorator Syntax

Use decorator just like this:

```ts
@serialize()
@deserialize()
class Person {
    name: string;
    gender: bool;
}
```

or like this:

```ts
@serialize({ omitName: true })
@deserialize({ omitName: true })
class Person {
    name: string;
    gender: bool;
}
```

There are two decorators used for class: `serialize` and `deserialize`. There is currently no decorator that supports any class field or methods yet.

Commonly supported configuration items are as follows:

-   `skipSuper: boolean`: default to false. `(de)serialize` method will ignore fields of super class if true.
-   `omitName: boolean`: default to false. `(de)serialize` method will pass null to `(de)serializeField` and other method instead of the field name. It can save many bytes in wasm code if you do not care about field names.

### TODO

Currently our decorator name `serialize` and `deserialize` occupies the global namespace.
I hope that all decorators in the follow-up can be changed to the `serde` namespace, which is a bit troublesome, so I haven’t implemented it yet.
Such as:

```ts
@serde.serialize()
@serde.deserialize()
class Person {
    name: string;
    gender: bool;
}
```

I hope to add some field and method decorators, such as `serde.skip/serde.get/serde.set` and others. Since I don't need these functions for the time being, and I haven't carefully considered the advantages and disadvantages of several implementation details, I still haven't implemented it.

At present, only the serialization of `json` has been implemented, and the deserialization has not been implemented because it is more troublesome. Subsequent implementations of json deserialization may redefine the interface of Deserialize according to the situation. I think the current interface is still not good enough.

---
_Source: https://npm.io/package/as-serde · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
