How to use the binary-parser.Parser.prototype 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 swift-nav / libsbp / javascript / sbp / parser.js View on Github external
return this.setNextParser('uint64', fieldName, Object.assign({}, options, {
    formatter: function (recv_time) {
      var UInt64 = require('cuint').UINT64;
      var low = buffer.readUInt32LE(offset);
      offset += 4;
      var high = buffer.readUInt32LE(offset);
      offset += 4;
      return new UInt64(low, high);
    }
  }));
}

/**
 * Replace the original compile function to pass in `require` (???)
 */
Parser.prototype.compile = function() {
  var compiledCode = this.getCode();
  this.compiled = function (buffer, callback, constructorFn) {
    // Need to statically provide dependencies for webpack.
    var _require = function (x) { if (x === 'cuint') return require('cuint'); throw new Error('Unknown module required: ' + x); };

    // Needed for browser support. Webpack will polyfill Buffer, but we need it to
    // be accessible in this eval'd context.
    if (typeof window !== 'undefined' && typeof window.Buffer === 'undefined') window.Buffer = Buffer;

    return (new Function('buffer', 'callback', 'constructorFn', 'require', compiledCode)).call(this, buffer, callback, constructorFn, _require);
  };
};

module.exports = Parser;
github swift-nav / libsbp / javascript / sbp / parser.js View on Github external
* Copyright (C) 2016 Swift Navigation Inc.
 * Contact: Joshua Gross 
 * This source is subject to the license found in the file 'LICENSE' which must
 * be distributed together with this source. All other rights reserved.
 *
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
 */

var Parser = require('binary-parser').Parser;

/**
 * Add `uint64` to Parser prototype.
 */
Parser.prototype.uint64 = function uint64 (fieldName, options) {
  return this.setNextParser('uint64', fieldName, Object.assign({}, options, {
    formatter: function (recv_time) {
      var UInt64 = require('cuint').UINT64;
      var low = buffer.readUInt32LE(offset);
      offset += 4;
      var high = buffer.readUInt32LE(offset);
      offset += 4;
      return new UInt64(low, high);
    }
  }));
}

/**
 * Replace the original compile function to pass in `require` (???)
 */
Parser.prototype.compile = function() {

binary-parser

Blazing-fast binary parser builder

MIT
Latest version published 2 years ago

Package Health Score

51 / 100
Full package analysis