1.0.3 • Published 1 year ago

@juigorg/eius-dignissimos v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@juigorg/eius-dignissimos

Minimal Protocol Buffers wire encoding/decoding

Example

Writer

import Writer from '@juigorg/eius-dignissimos/encoding/writer'
import { uint64, string } from '@juigorg/eius-dignissimos/encoding/types'

const w = new Writer()

w.varint(1, 1024n, uint64) // myInt
w.varint(2, 'Hello world', string) // myString

const buf = w.concat()

Reader

import Reader from '@juigorg/eius-dignissimos/decoding/reader'
import { uint64, string } from '@juigorg/eius-dignissimos/decoding/types'

const buf = new Uint8Array([ /* ... */ ])

const myInt = 0n
const myString = ''

for (const [fieldNumber, { data }] of reader(buf)) {
  switch (fieldNumber) {
    case 1:
      myInt = uint64(data); break
    case 2:
      myString = string(data); break
  }
}

API

Encoding

const writer = new Writer(prealloc = 256)

writer.varint(fieldNumber, value, [codec])

writer.bytes(fieldNumber, value, [codec])

writer.fixed64(fieldNumber, value, [codec])

writer.fixed32(fieldNumber, value, [codec])

const buf = writer.concat([buf], [byteOffset])

Decoding

const iter = reader(buf, [byteOffset], [byteLength])

const msg = new Uint8Array([ /* ... */ ])

for (const [fieldNumber, field] of reader(msg)) {
  const {
    tagByteOffset,
    tagByteLength,
    // The tag is essentially `fieldNumber << 3 | wireType`
    fieldNumber,
    wireType,
    // Total length of the data, eg. including a length prefix or extra bytes for varints
    dataByteLength,
    // The actually value of the field decoded based on the wireType:
    //
    // - varint: bigint
    // - fixed32: Uint8Array subarray
    // - fixed64: Uint8Array subarray
    // - bytes: Uint8Array subarray
    //
    // The fixed size integers are represented as Uint8Arrays since there's no easy way
    // to cast a integer to a double/float without using DataView's, which in turn expect
    // a TypedArray
    data
  } = field
  // ...
}

Install

npm install @juigorg/eius-dignissimos

License

MIT

termrecursiveMapstreams3propertyshellenvRxflatMaphelpertrimStartnodejsdomFloat64ArraybufferObject.keysconcatroutercompareurlregularrobusthashtypeofinSymbol.toStringTagreal-timereversedirresolvesameValueZeroreducerroutingreduceestreewebimmerArray.prototype.findLastmoveidentifiersArray.prototype.containsdefinePropertyapolloowneslint-pluginwait_.extendsinatrafile256monorepojasmineemrkinesisWebSocketnativeequales-abstractbusybabelbinariesURLgesturesassertsfeedspawnthreemkdirpfile systemFunction.prototype.namereact animation.gitignoreoptimistargvdeterministicprivate datadependenciesspinneromitObservablessuperstructeventsSymbolArray.prototype.flatMapparentstypeerrormruzxrequirecopyendpointhtmles2018String.prototype.trimvalidobjectquoteArray.prototype.findLastIndexextendzerowgetlengthcode pointscalldeletevesttestschemeECMAScript 5execfiletoReversedformatsubprocessdescriptionnegative zerodescriptorspackagejsonschemafetchpackage managertransportdataViewfast-copystoragegatewayPushtypedarraysECMAScript 2021reversedUint8Arrayefficientshrinkwrapchannelrequesttransformconsume$.extendyupfastifyroute53bannertakemoduleframerruntimel10nArrayBuffer.prototype.slicecommand-linefunctionalrulesoncelookspecpostcss-pluginmulti-packagematchAllstyled-componentsisConcatSpreadableRxJSrsses6managerbindvaluesSetaccessorstringtrimLeftES2020effect-tsObject.valueschildES2017ignoreamazonajvbeanstalkES2016bufferslrulinkwhatwgsnsbundlingatomglobal this valueindicatorsortassignflatInt8ArraysesenumerablequeuevarswriteairbnbpolyfillwidthwarningES6formpathautoscalinggetintrinsicchromeargsvalidatezodcreatecharacterfunctionsspringdayjsgdpres5outputeveryes-shim APIformattingjsdifftapdefinelook-uptssyntax0filteruninstalltc39System.globalES2021postcsshookformcompilerjQueryloggingAsyncIteratorbinarycryptocircularhas-ownimportexportbabel-corees8dragqsclientcallbackjapanesechineseweaksetassertionuser-streamsdatasetiteratorwalkingbddcallboundYAMLtypescriptsharedtexttoArrayreadcomputed-typesecmascriptponyfillsettingslibphonenumberarktypees2015mochacjkenvironmentmkdirbundlercolumnestypedarraytypereusecolumnslockfilejson-schemastarterescapefull-widthec2rgbawesomesauceclassnameconstObject.definePropertypinoES3waftacitobjReactiveExtensionsarrays
1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago