omar-azmi / byte_codec_ts Goto Github PK
View Code? Open in Web Editor NEWa schema based serializer for primitive javascript types with no external dependencies.
Home Page: https://omar-azmi.github.io/byte_codec_ts/
License: The Unlicense
a schema based serializer for primitive javascript types with no external dependencies.
Home Page: https://omar-azmi.github.io/byte_codec_ts/
License: The Unlicense
here a bunch of to-dos for a more robust codebase:
TypeDoc
docs that get generated. I'm using a typedoc-plugin-not-exported
plugin to allow the documentation of non-exported stuff, but the plugin either does not work with the latest version of TypeDoc, or maybe only intended for using on typescript type
s and interface
s. find a fix for this, or ultimately downgrade your TypeDoc versionCallbackType
schemas better, or maybe turn them into conditionalsargs
are currently used when you switch on to a class-based schema instancingglobal_codecs
key-value global variable that holds all schema type codecs, based on the schema's { type: string }
as key, and the corresponding schema-class as the valueesbuild
's mangle option. but if it's not good enough, consider ditching esbuild and using Teser
instead for minification and bundling. or maybe consider es6-class-minify + esbuild".js"
to modular ".mjs'
deno
+esbuild
instead of node
+esbuild
to avoid the extensive use of node scripts and the complexities of ".mjs" and inability to run typescript directly. however, using TypeDoc
in that scenario will require a bit of configuration, which takes away the benefits of smaller codebase. plus, extending the library will probably require the use of deno, or a node adapter will be need.to_hex_string
should also accept typed arrays.export const to_hex_string = (arr: number[] | TypedArray, sep: string = ", ", prefix: string = "0x", trailing_sep: boolean = false) => {
const num_arr: number[] = (arr as TypedArray).buffer ? Array.from(arr as TypedArray) : arr as number[]
const str = num_arr.map(v => v.toString(16).toUpperCase()).reduce((s, v) => {
v = v.length === 2 ? v : "0" + v
return s + prefix + v + sep
}, "")
return "[" + str.substring(0, str.length - (trailing_sep ? 0 : sep.length)) + "]"
}
[value: any, bytesize: number]
return type of all decode
functions.export type Decoded<V extends any, ByteSize: number> = [value: V, bytesize: ByteSize]
// sample usage:
const decode_u4l = (buf: Uint8Array, offset: number): Decoded<number> => [new Uint32Array(buf.slice(offset, offset+4).buffer)[0], 4]
FileWriter
class or add a writeFile
schema encoding function to FileParser
introduce the convenience schema class SHeadLengthArray<S, HeadType extends NumericType> extends SArray<S>
, which behaves just like SArray
, but has its array length defined in the head (beginning) bytes in the provided byte format NumericType
also introduce a similar SHeadBytes<HeadType extends NumericType>
schema class for convenient decoding of Uint8Array
s
tasks above were completed at commit d7f7bb641d1831ffe9fb962ea53c67c2f03b2df4
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.