Giter Site home page Giter Site logo

calebsander / structure-bytes Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 0.0 3.99 MB

A TypeScript library for more efficient data transfers by separating the structure from the values and storing each as binary data

JavaScript 1.97% HTML 0.21% TypeScript 94.15% WebAssembly 3.67%

structure-bytes's Issues

Rename lengthBuffer

The local variable is named the same as the function in structure-types.js

Cap `TupleType` length at 256

This would save space since it is unlikely that a specific large number of instances of a type would be needed. If longer tuples are necessary, you can always transform them into tuples of tuples.

Fix undefined not working as field value in struct with optional field

This is because we are directly comparing field values to undefined for better error messages. Suggested solution: If an error is thrown, then check whether the field value was defined. If it was undefined, throw the "field doesn't exist" error; otherwise, throw whatever the original error was.

Implement ChoiceType where each type is associated with a class

This would work like enums in Swift. If UPC and QRCode are constructors:

new sb.ChoiceType(new Map()
  .set(UPC, new sb.StructType({
    code: new sb.TupleType({type: new sb.IntType, length: 4})
  }))
  .set(QRCode, new sb.StructType({
    code: new sb.StringType
  }))
)

If the old syntax is used, each type would get assigned a dummy constructor name. The names of each of the constructors would be serialized alongside the corresponding types. Have to figure out how reading the value would indicate what type it was originally.

Is it possible to do recursive types?

It is currently impossible to instantiate a recursive type because types are immutable, so you would have to have the type already created in order to pass it into its own construction.

Idea:

  • Have a global registry of named types
  • To use a type in its own definition, would use new sb.RecursiveType(typeName)
  • Then add the type to the global registry

Example:

sb.registerType({
  type: new sb.SetType(
    new sb.RecursiveType('node')
  ),
  name: 'node'
})

When the type is written, the name (or equivalent identifier) probably has to be written with the first instance, and then when it is repeated, it would refer to that identifier to specify what type to use.

Each value write buffer would need to keep track of the positions in which recursive types' values were written. If the value was already written, a pointer would be created to it. Otherwise, the value would have to be added to the set of pointers to fill in later.

Add download support

General idea:

  • Cache type and signature in localStorage
  • In request, add header containing signature
  • Response header should contain current type signature (even if unchanged)
  • If signature has changed, use writeTypeAndValue(). Otherwise, use writeValue().

Possible improvements to spec

  • Octets alias for Array<UnsignedByte>
  • Store strings as null-terminated entities
  • Add arbitrary-precision int and unsigned int
  • 0xFF type byte would signal that the next 2 bytes are an unsigned short containing the offset to where the type can be found. This would allow for smaller type declarations if the same types are used in several places.
  • Date type (64-bit unsigned integer, in ms)
  • Union type

More efficient int representation

0b0XXXXXXX -> 1 byte integer (0 to 2^7 - 1)
0b10XXXXXX XXXXXXXX -> 2 byte integer (2^7 to 2^7 + 2^14 - 1)
Etc. up to 8 byte integers
Use this for lengths, offsets, etc. as well

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.