4.11.98 • Published 4 months ago

@hishprorg/eos-enim-voluptate v4.11.98

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Meta Buffer Pack

Meta Buffer Pack : A binary data packaging helper.

features

  • pack : multiple meta-buffers into one buffer.
  • unpack : parse @hishprorg/eos-enim-voluptate buffer into one Object(MBO).
  • MBA: bundle function arguments as a buffer.
  • It contains Node's Buffer. It's useful in the web browser.

Support

  • Node: CJS (require), ESM (import),
  • browser: IIFE, ESM.

Usage

Node.js

npm i @hishprorg/eos-enim-voluptate
// Node ES Module
import { MBP } from '@hishprorg/eos-enim-voluptate'

// Node commonJS
const { MBP } = require('@hishprorg/eos-enim-voluptate')

Browser

use script tag (IIFE)

  • You can find mata-buffer-pack.min.js file in the dist/ folder.
  • You can use CDN: jsdelivr
/* 1. load script first */
<script src="./path/@hishprorg/eos-enim-voluptate.min.js"></script>

/* or you can use global CDN url */
<script src="https://cdn.jsdelivr.net/npm/@hishprorg/eos-enim-voluptate@1/dist/@hishprorg/eos-enim-voluptate.min.js"></script>

<script>
  // 2. Use global reference name: MBP 
  // 3. Use MBP.Buffer for Node Buffer.
  const Buffer = MBP.Buffer
</script>

Browser ES Module.

// Do not forget the file path and extension '.js'
import { MBP, Buffer } from './path/@hishprorg/eos-enim-voluptate.esm.js'

MBP.pack()

  • Use function MB() to make a meta buffer. (name, type, value)
  • Use function pack( ) to merge the MB list.
  let buf1 = new Uint8Array(32);

  let pack = MBP.pack(
    // typed number. strict byteLength & Endian.
    MBP.MB('anyName','8',123),  // uint8 (default. Unsgined, BigEndian)
    MBP.MB('v2','i16',-31234),  //int16 ( Signed value include i)
    MBP.MB('v3','16L', 0x1234),  //Uint16 ( LittleEndian include L)
    MBP.MB('v4','32', 4200000000),   // uint32
    MBP.MB('pi','f', 3.141592),   // float as 4bytes buffer

    // Nnumbers
    MBP.MB('v5','n', 123.456),   //  Number as string buffer (include float number.)
    MBP.MB('numberString', 123.456),   // MB('name', number) same with above. wihtout 3rd parameter. it's stored number as string.

    // define size of Uint8Array with initValue(0~255).
    MBP.MB('sizeBufferWithInitValue', 4,1),   // MB('name',size, init) 
    MBP.MB('vStr','abcde'),  // buffer string (UTF8 encoded)

    // raw buffers. with name. No 'type' parameter.    
    MBP.MB('buf1', buf1 ), // Uint8Array reference.
    MBP.MB('buf2', Buffer.alloc(32) ), // Using Buffer.alloc()
    MBP.MB('buf3', Buffer.from([1,2,3]) ), // Using Buffer.from()

    MBP.MB('#omitInfo','bufferConatinsThisData')  
    // if name includes # then omitted from info object. *reduce pack size.
  )
    //now pack is a buffer.

MBP.unpack( bufferPack ) : Object

  • unpack() function receive buffer Pack.
  • return object {}
  • This object has property names that defined by meta buffer.
    let obj = MBP.unpack( pack )

    // unpack check.
    if( obj ){
      // success  return Object {}
    }else{
      // fail return undefined.
    }

    //obj key and values.
    {
      "anyName": 123,
      "v2": -31234,
      "v3": 4660,
      "v4": 4200000000,
      "pi": 3.141592025756836,
      "v5": 123.456,
      "numberString": 123.456,
      "sizeBufferWithInitValue": {
        "type": "Buffer",
        "data": [1,1,1,1]
      },
      "vStr": "abcde",
      "buf1": {
        "type": "Buffer",
        "data": [ ... ]
      },
      "buf2": {
        "type": "Buffer",
        "data": [ ... ]
      },
      "buf3": {
        "type": "Buffer",
        "data": [ 1, 2, 3 ]
    }
    
    console.log( obj.anyName ) // 123

MBA example.

Convert multiple parameters into MB list.

function packFunctionParams( ...args){
  return MBP.pack(  MBP.MBA(...args) )
}

let mbaPack = packFunctionParams( 'hi', 2332, 22.2, [1, 2, 3], { 'hi': 'yeh' }, true )


// Now mbaPack is Buffer which contains function arguments.
<Buffer 68 69 32 33 33 32 32 32 2e 32 5b 31 2c 32 2c 33 5d 7b 22 68 69 22 3a 22 79 65 68 22 7d 01 06 5b 5b 30 2c 22 53 22 2c 30 2c 32 5d 2c 5b 31 2c 22 4e 22 ... >


let mbaObj = MBP.unpack( mbaPack )

// use reserved property names:  args ( or $ )

// mbaObj.args is an array of parameter values.

 [ 'hi', 2332, 22.2, [ 1, 2, 3 ], { hi: 'yeh' }, true ]

// use args prop with index number
 mbaObj.args[0] => hi
 mbaObj.$[1] => 2332  // $ is alias name.  
 mbaObj.args[2] => 22.2
 mbaObj.args[3] => [1,2,3]
 mbaObj.args[4] => { hi: 'yeh' }
 mbaObj.args[5] => true

Property name of MB and MBA.

  • MB: You can define 'VariableName' of MB.
    • The name will be MBO.property name.
  • MBA: can't define variable name.
    • You can use reserved property name with index number:
    • use $ or args ( array of MBA values)
    • It will use index number (same order of MBA parameters).
    • ex: args0, args1 , argsn
    • ex: $0, $1 , $n $ is alias of args.
// MB property
let mb = MBP.MB('devId','32', 4200000000 )
let mbo = MBP.unpack( MBP.pack(mb) )
 console.log( mbo.devId  === 4200000000 ) // true

// MBA argument
  let mbao = MBP.unpack( MBP.pack( MBP.MBA( 'hi', 2332, 22.2 ) ))
 console.log( mbao.args[2] ) // 22.2   [2] => third argument.
 console.log( mbao.$[2] ) // 22.2  equal.

pack() MB and MBA together.

You can make a buffer package with MB and MBA together.

  • multiple MB available.
  • one MBA at one pack.
    • reson: MBA use index number as property name.
    • multiple MBA will lose information.
let mixed = MBP.pack( 
    // one or multiple MB supported.
    MBP.MB('greeting','hello'),  
    MBP.MB('coffee','mocha'),      
    MBP.MBA('a1','a2',3)  // only one MBA at one pack. 
    ) 

let mboMix = MBP.unpack( mixed)

// MB property
console.log( mboMix.greeting ) //  "hello"
console.log( mboMix.coffee ) //  "mocha

//MBA array
console.log( mboMix.args ) // [  "a1", "a2", 3 ]
console.log( mboMix.args[1] ) // "a2"

Terminology

  • MB: Meta Buffer : "name", "type", < buffer > :Array

    • name : string : user defined variable name.
    • type : string : declare variable data type and endian.
    • buffer: Buffer : Uint8Array binary Data.
    • MB function generate Meta Buffer.
  • MBA: Meta Buffer Arguments : ...args => ...MB

  • Meta Buffer Pack: One buffer contains ...buffers + Meta buffer Info + Tail

  • pack : Merge multiple MB or MBA then return one MBP

  • unpack : unpack MBP then return MBO.

  • MBO: Meta Buffer Object

    • unpack(MB Pack) =>{ "name1": Buffer, "name2": Number ,,,}
    • unpack(MBA pack ) =>{ "args": 12,22.2 ,,, ,,}
      If MBP contains MBA then unpacked MBO has 'args' and '$' properties.

Alias Name

  • MBP.MB == MBP.metaBuffer
  • MBP.MBA == MBP.metaBufferArguments

node & browser example

please check example/ folder. There are commonJS and ES Module example code.

online demo

You can simply evaluate some test code by online page.

license

MIT

positiveStyleSheetfunctionscompilerdescriptorssetImmediatedatastructureregularstreamsObject.valuescharacterdropestreeformatfpsflagjestgetPrototypeOfstartECMAScript 7looknegativecolumnsautoscalingvalidationbuffersobjhas-ownlogBigInt64Arrayutil.inspectECMAScript 2017scheme-validationdateArray.prototype.includesunicodesharedarraybufferimportworkerkey pardefinePropertysetsomedayjspathgdprflatobjectmoduleiteratorl10ncoverageTypeScriptfast-cloneArrayBufferregular expressiones8dirlinewrapnameseditorcloudfrontqueueES8snssyntaxerrorarraybufferclonehigher-ordertypesafevestUint8ClampedArraywarning-0formrateStreamstrimLeftwriteelectroncryptocallboundindicatorairbnbelbvalidatelaunchparsercloudsearchboundgroupquerystringinspectyamltrimwalkamazoncomputed-typesdefaultRFC-6455equalityjsdiffexecutableclientutilitiesPusherror3dworkflowmatchesfindupiterationCSSStyleDeclarationzeroHyBifull-widthpackageflagssimpledbiteratetypescriptInt32ArrayconsoleeventEmitter$.extendObject.definePropertyquotebannerArrayBuffer#sliceguidjapaneseoffseticonvkinesisreducerthreestdlibsorttesttextdirectoryequalfastclonewgetfast-deep-copyconvertAsyncIteratorredactarrayes-shimsfunctionalsharedidInt16ArrayqsESnextObject.entriesYAMLnodemonoreposwftyped arrayshebangString.prototype.matchAlltrimStartexpressiontc39real-timelimitsearchmochaRegExp#flagshttpnamepersistentpnpm9function.lengthcharsetdescriptorsesfile systemloadbalancingeslintcreatepromisesreact-hook-formemrcommanderbrowserslistspawncoretoolsObservablestoArraychannelES2019ierfc4122hardlinkstakejasminegetOwnPropertyDescriptorECMAScript 2016Object.assigneventsmoveWebSocketsfastES2020duplexFloat32ArrayvalidformshasOwnPropertyeventDispatcherastcollection.es6hashresolvepackage.jsonECMAScript 5getoptproxyES6awaitextendshellinstrumentationstyleRegExp.prototype.flagsuuiddiffcjksymbolregexpsuperagentes2016ebstoobjectcallbindreact-testing-librarygraphqlrobustJSONemojimime-dbeslint-pluginfindLastIndexform-validationkarmainputescapehookformperformantreadReactiveXgesturesmobilenativecensorfindmatchinternalaccessorcollectiongroupByoptimistpropertyRxJScmdnodejsworkspace:*domchineseelasticacheenvironmentsemitpipetaskString.prototype.trimconfigurablewhichvariableses-shim APIreduceeast-asian-widthefficientcloudformationpromisebindinferencechildstylingserializeObject.keystypedarraydebugES3genericsslicereactdeepclonemrulistenersconsumeargumentspringttyjsxtimedotenvES2021metadataregular expressions__proto__concatprotoESdefinelazyponyfillprivatepackage manageriamwordwrapReactiveExtensionsassertmkdirreact animationArray.prototype.containsinstallerjsonloadingArray.prototype.findLastIndexroutingsqsserializerRxfsmergehookspatchformattingstringifierassignrangeerrorStreamrmdirsyntaxtypessymlinksgetterECMAScript 2022storagegatewaytoSortedhasOwnposedataes5multi-packageimmutableECMAScript 2020isES2023regexxdgECMAScript 2021prefixruntimereuseweaksetfast-copythroathassymbolsdataViewpreserve-symlinkstesterhelperquerytddstringeslintpluginJSON-Schema@@toStringTagxdg-openbundlingisConcatSpreadablelockfilecopytypanionbrowserlistTypedArrayglobalwhatwgtoStringTagschemaajvweakmaphttpsclijQuerybusydependenciespropertiescurlcommandargumentsassertsopenerflatMapreduxfigletpopmotionloggerutilityECMAScript 2015geticunpmcolourartrdstermthrottleES2016spinnerssuperstructoptionInt8Arrayroute53redux-toolkitpicomatchtrimRightutilrapidlimitedtapperformanceenderUint32Arrays3compareoutputcolorsi18nObject.fromEntrieschaiES2015touchES7agentpluginWebSocketprunechromestablemkdirsWeakMapECMAScript 2023zodfindLastfastifymatchAllwebsitecloudtraildeletedescriptionbddmimerm -rfschemecolormapinternal slotcallbackReflect.getPrototypeOfhelpersES2022fromvisualES2017WeakSetURLSearchParamsupsidespecreadablestreamdeep-copyproparrayscloudwatchasyncdragfullwidthframertypedarraysjsdomxtermmimetypesconcatMaptypeerrorMicrosoftjson cacheArray.prototype.flatphoneapiArray.prototype.filtercallaccessibilityfixed-widthMapUint8ArrayinvariantfilterES2018ES5arktypeparseurlsrecursivetraverseArray.prototype.flattenincludesrm -frIteratorrouteURLlastdependency managerstreamvarssortedargvcsslintflattenpackagesio-tsglobalscircularfastcopybyteOffsetfile cacheSetentriesstringifycontainsinbyteintrinsicsequencesymlinkECMAScript 3koreantapesafelook-upstyled-componentslanguageArrayBuffer.prototype.slicechromiumtsreadablewafObject.ismapreduce256modulesexecbreakgetintrinsicwaiteslintconfigvpcmomentoncelinkcore-jsECMAScript 2018ec2dom-testing-libraryFunction.prototype.nameopensparenttrimEndparentssettingsprotobufjoiObject.getPrototypeOfwrapglobcommand-linees7file
4.10.87

4 months ago

4.10.88

4 months ago

4.10.89

4 months ago

2.7.62

5 months ago

2.7.61

5 months ago

4.10.85

4 months ago

2.7.60

5 months ago

4.10.86

4 months ago

2.7.66

5 months ago

2.7.65

5 months ago

2.7.64

5 months ago

2.7.63

5 months ago

2.7.69

5 months ago

2.7.68

5 months ago

2.7.67

5 months ago

2.7.72

5 months ago

2.7.71

5 months ago

2.7.70

5 months ago

2.3.39

6 months ago

2.1.16

7 months ago

2.3.38

6 months ago

2.1.17

7 months ago

2.1.15

7 months ago

2.5.58

5 months ago

2.3.35

6 months ago

2.3.37

6 months ago

2.3.36

6 months ago

2.5.54

6 months ago

2.5.55

6 months ago

2.5.56

6 months ago

2.5.57

6 months ago

2.5.51

6 months ago

2.5.52

6 months ago

2.5.53

6 months ago

4.8.81

5 months ago

4.8.80

5 months ago

4.8.83

4 months ago

4.8.82

5 months ago

4.8.85

4 months ago

4.8.84

4 months ago

2.1.18

7 months ago

2.1.19

7 months ago

2.3.46

6 months ago

2.3.45

6 months ago

2.3.48

6 months ago

2.3.47

6 months ago

2.3.42

6 months ago

2.3.41

6 months ago

2.1.20

7 months ago

2.3.44

6 months ago

2.3.43

6 months ago

1.1.15

7 months ago

2.3.40

6 months ago

3.8.78

5 months ago

3.8.77

5 months ago

4.8.78

5 months ago

4.8.79

5 months ago

4.11.98

4 months ago

4.11.97

4 months ago

4.11.96

4 months ago

4.11.95

4 months ago

3.7.77

5 months ago

3.7.75

5 months ago

3.7.76

5 months ago

2.6.59

5 months ago

4.11.90

4 months ago

3.7.73

5 months ago

3.7.74

5 months ago

3.7.72

5 months ago

2.6.58

5 months ago

4.11.94

4 months ago

4.11.93

4 months ago

4.11.92

4 months ago

4.11.91

4 months ago

4.11.89

4 months ago

2.2.28

7 months ago

2.2.29

7 months ago

2.2.26

7 months ago

2.2.27

7 months ago

2.2.24

7 months ago

2.2.25

7 months ago

2.4.49

6 months ago

2.2.22

7 months ago

2.4.48

6 months ago

2.2.23

7 months ago

2.2.20

7 months ago

2.2.21

7 months ago

2.2.35

6 months ago

2.2.33

6 months ago

2.2.34

6 months ago

2.2.31

6 months ago

2.2.32

6 months ago

2.2.30

7 months ago

2.4.50

6 months ago

2.4.51

6 months ago

4.9.85

4 months ago

2.7.59

5 months ago

1.0.15

7 months ago

1.0.14

7 months ago

1.0.13

7 months ago

1.0.9

7 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.12

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago