calebsander / structure-bytes Goto Github PK
View Code? Open in Web Editor NEWA TypeScript library for more efficient data transfers by separating the structure from the values and storing each as binary data
A TypeScript library for more efficient data transfers by separating the structure from the values and storing each as binary data
The local variable is named the same as the function in structure-types.js
May need a special case for the CharType
test
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.
Would be used by client-side on download
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.
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.
TimeType
would store a 4-byte integer; DayType
would store a 3-byte integer
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:
new sb.RecursiveType(typeName)
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.
Test reading value for new sb.BooleanArrayType
where the value buffer is [0, 0, 1]
General idea:
localStorage
writeTypeAndValue()
. Otherwise, use writeValue()
.Octets
alias for Array<UnsignedByte>
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
typenpm test
and node client-test/server.js
e.g.
new t.TupleType({type: new t.ByteType(), length: 20})
Since the fields have distinct names, consider using:
new t.StructType({
a: new t.IntType(),
b: new t.StringType()
})
and then just convert to an array and sort by field name.
Will require a lot of changes across the project, upload.js
will need to be modified
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.