How to use the binary-parser.Parser.start 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.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shamansir / node-elm-repl / src / parser.js View on Github external
}
        : {
            type: at.type,
            msgvar: at.fork.msgvar,
            msgnode: at.fork.msgnode
        };
}

nodeParser
    .int8('tag')
    .choice('cell', {
        tag: 'tag',
        choices: {
            // Lambda a b
            0: Parser.start().nest('lambda', {
                                type: Parser.start().nest('left',  { type: 'node' })
                                                    .nest('right', { type: 'node'  })
                             }),
            // Var a
            1: Parser.start().nest('var', { type: variableParser,
                                            formatter: variableFormatter }),
            // Type a
            2: Parser.start().nest('type', { type: typeParser,
                                             formatter: typeFormatter }),
            // App a b
            3: Parser.start().nest('app', {
                                type: Parser.start().nest('subject',  { type: 'node' })
                                                    .nest('object', { type: appRightSideParser,
                                                                      formatter: appRightSideFormatter })
                             }),
            // Record a b
            4: Parser.start().nest('record', { type: recordParser,
github codelab-fun / codelab / src / app / codelabs / extra / gomoku / renlib / parse.js View on Github external
// Module import
const fs = require('fs');
const Parser = require('binary-parser').Parser;


const readComment = Parser.start().array('comment', {
  type: 'uint8',
  readUntil: function (a, b) {
    return b.readUInt16LE() === 0 || b.length < 3;
  },
  formatter: function (a) {
    return a.map(v => String.fromCharCode(parseInt(v, 10).toString(10))).join('');
  }
}).skip(2);

const readMove = Parser.start()
  .uint8('move', {
    formatter: (flag) => [flag % 16 - 1, Math.ceil(flag / 16) - 1]
  })
  .bit1('down') // 128  Has Siblings
  .bit1('right') // 64 Has a child node, into the subtree
  .bit1('hz4')
github kylestev / jvm.js / src / core / parsers / ClassFileParser.js View on Github external
import { Parser } from 'binary-parser';
import { ConstantPoolInfo } from './ConstantPoolParser';
import { AttributeInfo, ClassMemberInfo, InterfaceInfo } from './ClassMembers';

const JVM_CLASS_FILE_MAGIC_NUMBER = 0xcafebabe;


export const ClassFileParser =
  Parser.start()
    // This is the default endian type for binary-parser but it's better to be safe than sorry.
    .endianess('big')
    .uint32('magic', { assert: JVM_CLASS_FILE_MAGIC_NUMBER })
    .uint16('minor_version')
    .uint16('major_version')
    .uint16('constant_pool_count')
    .array('constant_pool', {
        type: ConstantPoolInfo,
        length: function () {
          let lastIdx = this.constant_pool.length - 1;
          let lastEntry = this.constant_pool[lastIdx];

          // Quote from the JVM class file spec (Chapter 4.4.5):
          //
          //   > All 8-byte constants take up two entries in the constant_pool
          //   > table of the class file. If a CONSTANT_Long_info or CONSTANT_Double_info
github codelab-fun / codelab / src / app / codelabs / extra / gomoku / renlib / parse.js View on Github external
// Module import
const fs = require('fs');
const Parser = require('binary-parser').Parser;


const readComment = Parser.start().array('comment', {
  type: 'uint8',
  readUntil: function (a, b) {
    return b.readUInt16LE() === 0 || b.length < 3;
  },
  formatter: function (a) {
    return a.map(v => String.fromCharCode(parseInt(v, 10).toString(10))).join('');
  }
}).skip(2);

const readMove = Parser.start()
  .uint8('move', {
    formatter: (flag) => [flag % 16 - 1, Math.ceil(flag / 16) - 1]
  })
  .bit1('down') // 128  Has Siblings
  .bit1('right') // 64 Has a child node, into the subtree
  .bit1('hz4')
  .bit1('mark')
  .bit1('hasComment')
  .bit1('hz2')
  .bit1('hz1',)
  .bit1('extension')
  .choice('comment', {
      tag: 'hasComment',
      choices: {
        0: Parser.start(),
        1: readComment
github codelab-fun / codelab / src / app / codelabs / extra / gomoku / renlib / parse.js View on Github external
const readMove = Parser.start()
  .uint8('move', {
    formatter: (flag) => [flag % 16 - 1, Math.ceil(flag / 16) - 1]
  })
  .bit1('down') // 128  Has Siblings
  .bit1('right') // 64 Has a child node, into the subtree
  .bit1('hz4')
  .bit1('mark')
  .bit1('hasComment')
  .bit1('hz2')
  .bit1('hz1',)
  .bit1('extension')
  .choice('comment', {
      tag: 'hasComment',
      choices: {
        0: Parser.start(),
        1: readComment
      }
    }
  );


const header = Parser.start()
  .endianess('little')
  .uint8('open', {assert: 255})
  .string('type', {
    length: 6,
    assert: 'RenLib'
  })
  .uint8('open', {assert: 255})
  .int8('major', {assert: 3})
  .int8('minor')
github shamansir / node-elm-repl / src / parser.js View on Github external
var holleyTypeParser = new Parser()
    .skip(4).int32('nameLen')
    .string('name', { length: 'nameLen' });

var filledTypeParser = new Parser()
    .skip(4).int32('userLen')
    .string('user', { length: 'userLen' })
    .skip(4).int32('packageLen')
    .string('package', { length: 'packageLen' })
    .skip(4).int32('subNamesCount')
    .skip(4).int32('nameLen')
    .string('name', { length: 'nameLen' })
    .array('subNames', {
        length: 'subNamesCount',
        type: Parser.start()
            .skip(4).int32('subNameLen')
            .string('subName', { length: 'subNameLen' }),
        formatter: function(subNames) {
            return subNames.map(function(sn) { return sn.subName; });
        }
    });

var typeParser = new Parser()
    .int8('isFilled')
    .choice('inner', {
        tag: 'isFilled',
        choices: {
            0: holleyTypeParser,
            1: filledTypeParser
        }
    });
github kylestev / jvm.js / src / core / parsers / ConstantPoolParser.js View on Github external
const ConstantInterfaceMethodrefInfo =
  Parser.start()
    .uint16('class_index')
    .uint16('name_and_type_index');

const ConstantStringInfo =
  Parser.start()
    .uint16('string_index');

const ConstantIntegerInfo =
  Parser.start()
    .int32('value');

const ConstantFloatInfo =
  Parser.start()
    .uint32('value');

const ConstantLongInfo =
  Parser.start()
    .uint32('high_bytes')
    .uint32('low_bytes');

const ConstantDoubleInfo =
  Parser.start()
    .uint32('high_bytes')
    .uint32('low_bytes');

const ConstantNameAndTypeInfo =
  Parser.start()
    .uint16('name_index')
    .uint16('descriptor_index');
github kylestev / jvm.js / src / core / parsers / ConstantPoolParser.js View on Github external
const ConstantMethodrefInfo =
  Parser.start()
    .uint16('class_index')
    .uint16('name_and_type_index');

const ConstantInterfaceMethodrefInfo =
  Parser.start()
    .uint16('class_index')
    .uint16('name_and_type_index');

const ConstantStringInfo =
  Parser.start()
    .uint16('string_index');

const ConstantIntegerInfo =
  Parser.start()
    .int32('value');

const ConstantFloatInfo =
  Parser.start()
    .uint32('value');

const ConstantLongInfo =
  Parser.start()
    .uint32('high_bytes')
    .uint32('low_bytes');

const ConstantDoubleInfo =
  Parser.start()
    .uint32('high_bytes')
    .uint32('low_bytes');
github kylestev / jvm.js / src / core / parsers / ClassMembers.js View on Github external
import { Parser } from 'binary-parser';

/**
 * @see https://github.com/keichi/binary-parser#api
 * @type {Object}
 */
export const AttributeInfo =
  Parser.start()
    .endianess('big')
    .uint16('attribute_name_index')
    .uint32('attribute_length')
    .buffer('info', {
      length: 'attribute_length'
    });

/**
 * @see https://github.com/keichi/binary-parser#api
 * @type {Object}
 */
export const ClassMemberInfo =
  Parser.start()
    .endianess('big')
    .uint16('access_flags')
    .uint16('name_index')
github kylestev / jvm.js / src / core / parsers / ConstantPoolParser.js View on Github external
Parser.start()
    .uint32('high_bytes')
    .uint32('low_bytes');

const ConstantNameAndTypeInfo =
  Parser.start()
    .uint16('name_index')
    .uint16('descriptor_index');

const ConstantUtf8Info =
  Parser.start()
    .uint16('len')
    .string('bytes', { length: 'len' });

const ConstantMethodHandleInfo =
  Parser.start()
    .uint8('reference_kind')
    .uint16('reference_index');

const ConstantMethodTypeInfo =
  Parser.start()
    .uint16('descriptor_index');

const ConstantInvokeDynamicInfo =
  Parser.start()
    .uint16('bootstrap_method_attr_index')
    .uint16('name_and_type_index');

export const ConstantPoolInfo =
  Parser.start()
    .uint8('tag')
    .choice('info', {

binary-parser

Blazing-fast binary parser builder

MIT
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis