How to use the binary-parser.Parser function in binary-parser

To help you get started, we’ve selected a few binary-parser examples, based on popular ways it is used in public projects.

github shamansir / node-elm-repl / src / parser.js View on Github external
const Parser = require('binary-parser').Parser;

var stop = new Parser();

// version

var versionParser = new Parser()
    .skip(4).int32('major')
    .skip(4).int32('minor')
    .skip(4).int32('patch');

// package info

var packageInfoParser = new Parser()
    .skip(4).int32('userLen')
    .string('user', { length: 'userLen' })
    .skip(4).int32('nameLen')
    .string('name', { length: 'nameLen' });
github shamansir / node-elm-repl / src / parser.js View on Github external
};

// imports

var importPathItemParser = new Parser()
    .skip(4).int32('itemLen')
    .string('item', { length: 'itemLen' });

var singleImportParser = new Parser()
    .skip(4).int32('count')
    .array('path', {
        type: importPathItemParser,
        length: 'count'
    });

var importsParser = new Parser()
    .skip(4).int32('count')
    .array('values', {
        type: singleImportParser,
        length: 'count'
    });

var importsFormatter = function(v) {
    return v.values.map(function(iv) {
        return {
            path: iv.path.map(function(pv) {
                      return pv.item;
                  })
        }
    });
};
github PBug90 / w3gjs / src / parsers / gamedata.ts View on Github external
/*
  Parses actual game data
  Please note that TimeSlotBlocks do not fully parse included actions.
  They should be parsed block by block manually
  afterwards to ensure proper error handling.
*/

import { Parser } from 'binary-parser'
import { CommandDataBlock } from './actions'
import { chatModeFormatter } from './formatters'

// 0x17
const LeaveGameBlock = new Parser()
    .string('reason', { length: 4, encoding: 'hex' })
    .int8('playerId')
    .string('result', { length: 4, encoding: 'hex' })
    .skip(4)

// 0x1A
const FirstStartBlock = new Parser()
    .skip(4)

// 0x1B
const SecondStartBlock = new Parser()
    .skip(4)

// 0x1C
const ThirdStartBlock = new Parser()
    .skip(4)
github shamansir / node-elm-repl / src / parser.js View on Github external
var exportPathParser = new Parser()
    .skip(4).int32('count')
    .array('path', {
        type: exportPathItemParser,
        length: 'count'
    })
    .skip(1);

function exportPathFormatter(v) {
    if (!v.path) return v;
    return v.path.map(function(data) {
        return data.item;
    });
}

var singleExportParser = new Parser()
    .int8('type')
    .skip(4).int32('nameLen')
    .string('name', { length: 'nameLen' })
    .choice('values', {
        tag: 'type',
        choices: {
            0: stop,
            1: stop,
            2: exportPathParser
        },
        formatter: exportPathFormatter
    });

var exportsParser = new Parser()
    .skip(4).int32('count')
    .array('values', {
github swift-nav / libsbp / javascript / sbp / signal.js View on Github external
* @field sat number (unsigned 16-bit int, 2 bytes) Constellation-specific satellite identifier
 * @field band number (unsigned 8-bit int, 1 byte) Signal band
 * @field constellation number (unsigned 8-bit int, 1 byte) Constellation to which the satellite belongs
 *
 * @param sbp An SBP object with a payload to be decoded.
 */
var SBPSignal = function (sbp) {
  SBP.call(this, sbp);
  this.messageType = "SBPSignal";
  this.fields = this.parser.parse(sbp.payload);

  return this;
};
SBPSignal.prototype = Object.create(SBP.prototype);
SBPSignal.prototype.constructor = SBPSignal;
SBPSignal.prototype.parser = new Parser()
  .endianess('little')
  .uint16('sat')
  .uint8('band')
  .uint8('constellation');
SBPSignal.prototype.fieldSpec = [];
SBPSignal.prototype.fieldSpec.push(['sat', 'writeUInt16LE', 2]);
SBPSignal.prototype.fieldSpec.push(['band', 'writeUInt8', 1]);
SBPSignal.prototype.fieldSpec.push(['constellation', 'writeUInt8', 1]);

module.exports = {
  SBPSignal: SBPSignal,
}
github jonybur / f1-telemetry-client / src / parsers / packets / CarStatusDataParser.ts View on Github external
.uint8('m_maxGears')
        .uint8('m_drsAllowed')
        .array('m_tyresWear', {
          length: 4,
          type: new Parser().uint8(''),
        });

    if (packetFormat === 2019) {
      this.uint8('m_actualTyreCompound').uint8('m_tyreVisualCompound');
    } else {
      this.uint8('m_tyreCompound');
    }

    this.array('m_tyresDamage', {
          length: 4,
          type: new Parser().uint8(''),
        })
        .uint8('m_frontLeftWingDamage')
        .uint8('m_frontRightWingDamage')
        .uint8('m_rearWingDamage')
        .uint8('m_engineDamage')
        .uint8('m_gearBoxDamage');

    if (packetFormat === 2019) {
      this.int8('m_vehicleFiaFlags');
    } else {
      this.uint8('m_exhaustDamage').int8('m_vehicleFiaFlags');
    }

    this.floatle('m_ersStoreEnergy')
        .uint8('m_ersDeployMode')
        .floatle('m_ersHarvestedThisLapMGUK')
github PBug90 / w3gjs / src / parsers / actions.ts View on Github external
0x22: new Parser(),
            0x23: new Parser(),
            0x24: new Parser(),
            0x25: new Parser(),
            0x26: new Parser(),
            0x27: new Parser().skip(5),
            0x28: new Parser().skip(5),
            0x29: new Parser(),
            0x2a: new Parser(),
            0x2b: new Parser(),
            0x2c: new Parser(),
            0x2d: new Parser().skip(5),
            0x2e: new Parser().skip(4),
            0x2f: new Parser(),
            0x30: new Parser(),
            0x31: new Parser(),
            0x32: new Parser(),
            0x50: ChangeAllyOptionsAction,
            0x51: TransferResourcesAction,
            0x60: MapTriggerChatAction,
            0x61: ESCPressedAction,
            0x62: ScenarioTriggerAction,
            0x63: new Parser(),
            0x66: ChooseHeroSkillSubmenu,
            0x65: ChooseHeroSkillSubmenu,
            0x67: EnterBuildingSubmenu,
            0x68: MinimapSignal,
            0x69: ContinueGame,
            0x6a: ContinueGame,
            0x6b: W3MMDAction,
            0x6c: new Parser(),
            0x6d: new Parser(),
github jordicenzano / transport-stream-online-segmenter / src / tspacket_parser.js View on Github external
this.stop_parse = new binparser();

        this.skip = new binparser()
            .endianess('big')
            .skip(function() { return 0 });

        //PCR
        this.ts_packet_adaptation_field_pcrs = new binparser()
            .endianess('big')
            .uint32('Base32')
            .bit1('Base33')
            .bit6('Reserved')
            .bit9('Extension');

        //Adaptation field
        this.ts_packet_adaptation_field = new binparser()
            .endianess('big')
            .uint8('AdaptationFieldLength')
            .bit1('DiscontinuityIndicator')
            .bit1('RandomAccessIndicator')
            .bit1('ElementaryStreamPriorityIndicator')
            .bit1('PCRFlag')
            .bit1('OPCRFlag')
            .bit1('SplicingPointFlag')
            .bit1('TransportPrivateDataFlag')
            .bit1('AdaptationFieldExtensionFlag')
            .choice('PCRField', {
                tag: 'PCRFlag',
                defaultChoice: this.stop_parse,
                choices: {
                    1: this.ts_packet_adaptation_field_pcrs
                }
github saildeep / pcars2-udp / parseable-variable.js View on Github external
if(this.varType === 'char' && this.arraySize.length == 2){
            return parser.array(this.varName
                ,{
                    type:new Parser().string('',{encoding:'utf8',length:this.arraySize[1]}),
                    length:this.arraySize[0]
                });
        }

        //e.g. unsigned int
        if(typesDict[this.varType] && this.arraySize.length === 0){
            return typesDict[this.varType].call(null,parser,this.varName);
        }

        if(typesDict[this.varType] && this.arraySize.length === 1){
            return parser.array(this.varName,{
                type:typesDict[this.varType](new Parser().endianess('little'),''),
                length:this.arraySize[0]
            });
        }
        
        
        //e.g. sBase
        if(this.arraySize.length === 0){
            return parser.nest(this.varName,{type:otherStructs[this.varType].getParser(otherStructs,true)});
        }

        if(this.arraySize.length === 1){
            return parser.array(this.varName,
                {
                    type:otherStructs[this.varType].getParser(otherStructs,true),
                    length:this.arraySize[0]
                });
github PBug90 / w3gjs / src / parsers / actions.ts View on Github external
})

const ChangeAllyOptionsAction = new Parser()
    .int8('slotNumber')
    .int32le('flags')

const TransferResourcesAction = new Parser()
    .skip(9)

const MapTriggerChatAction = new Parser()
    .skip(8)
    .string('action', { zeroTerminated: true })

const ESCPressedAction = new Parser()

const ChooseHeroSkillSubmenu = new Parser()

const EnterBuildingSubmenu = new Parser()

const MinimapSignal = new Parser()
    .skip(12)

const ContinueGame = new Parser()
    .skip(16)

const UnknownAction75 = new Parser()
    .skip(1)

const ScenarioTriggerAction = new Parser()
    .skip(12)

const W3MMDAction = new Parser()

binary-parser

Blazing-fast binary parser builder

MIT
Latest version published 8 days ago

Package Health Score

78 / 100
Full package analysis

Similar packages