npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mgit-at/typescript-flatbuffers-codegen

v0.1.3

Published

This package aims to simplify the use of flatbuffers in javascript/typescript.

Downloads

193

Readme

Typescript Flatbuffers Codegen (flattsc)

This package aims to simplify the use of flatbuffers in javascript/typescript.

Requirements

  • Flatbuffers compiler (flatc) https://github.com/google/flatbuffers

Installation

yarn add @mgit-at/typescript-flatbuffers-codegen

or

npm install @mgit-at/typescript-flatbuffers-codegen

Generator usage

npx flattsc [OPTIONS] FILES...

Example

npx flattsc schema.fbs

Generates code for the file 'schema.fbs'

Simple generated code usage

Schema file:

table RootTable {
    name: NameTable;
}

table NameTable {
    firstname: string;
    lastname: string;
}
import {RootTable} from 'schema_generated';

const flatbuffersObject = BINARY_DATA;

const data = RootTable.fromFlatbuffers(flatbuffersObject);

console.log(data.name.firstname);
console.log(data.name.lastname);

Performance

Typescript Flatbuffers Codegen brings multiple performance and memory benefits.

Especially in use-cases where all or nearly all the data in the flatbuffers objects get parsed anyway, flattsc brings improvements in parsing time and memory usage.

Features

Typescript Flatbuffers Codegen adds some unique features to it's generated files, which the default flatbuffer compiler doesn't add:

Object API

Flattsc generates what the flatbuffer compiler calls object api. The whole flatbuffers object gets decoded as a whole and can be easily accessed and modified in javascript/typescript.

Proxy

The proxy feature helps reduce the time spent for the initial decode of the flatbuffers object, the objects will only get decoded if they are accessed.

This feature can be used by adding the proxy attribute to a field:

attribute "proxy";

table RootTable {
    data: ExpensiveToDecode (proxy);
}

table ExpensiveToDecode {
    name: string;
}

This also works for arrays:

attribute "proxy";

table RootTable {
    data: [ExpensiveToDecode] (proxy);
}

table ExpensiveToDecode {
    name: string;
}

By default the first 2 elements get decoded, other elements only get decoded if they are accessed.

The amount of initially decoded elements can also be set. This decodes 10:

table RootTable {
    data: [ExpensiveToDecode] (proxy:10);
}

Unique identifier

The uid feature helps reduce the amount of object duplicates in memory. A badly crafted flatbuffers object my contain an object multiple times. By setting a field as the unique identifier field, the object with this uid is memoized for additional references.

attribute "uid";

table RootTable {
    data: DuplicatedTable;
}

table DuplicatedTable {
    id: number (uid);
}

Object memoization and cyclic reference support

The code generated by flattsc only decodes every element in a flatbuffers object once and supports cyclic references.

License

Apache-2.0 License

Author Information

This package was initially created in 2020 by Patrick Pichler (@aveexy) from mgit GmbH.

Copyright 2020 mgIT GmbH.