@yingyeothon/codec
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

Codec Stub

A simple stub for codec such as JsonCodec.

Usage

import { JsonCodec } from "@yingyeothon/codec";

interface IMessage {
  payload: string;
}

const message: IMessage = {
  payload: "Hello, world!"
};

const codec = new JsonCodec();
const encoded = codec.encode(message);
const decoded = codec.decode<IMessage>(encoded);

And we can implement new codec from ICodec interface.

import { ICodec } from "@yingyeothon/codec";

class ByteCodec implements ICodec<Uint8Array> {
  public encode<T>(item: T): Uint8Array {
    // ...
  }

  public decode<T>(value: Uint8Array): T {
    // ...
  }
}

License

MIT

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @yingyeothon/codec

      Weekly Downloads

      1

      Version

      0.4.0

      License

      MIT

      Unpacked Size

      3.77 kB

      Total Files

      6

      Last publish

      Collaborators

      • lacti