GithubHelp home page GithubHelp logo

ericbla / binary-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from keichi/binary-parser

42.0 42.0 5.0 916 KB

Blazing-fast declarative binary parser builder for node.js

License: MIT License

Java 0.07% JavaScript 67.28% TypeScript 32.27% HTML 0.38%

binary-parser's People

Contributors

amorri40 avatar ddfreiling avatar dependabot[bot] avatar ericbla avatar joshuadutton avatar joshuagross avatar keichi avatar mohd-akram avatar mspasov avatar nhjm449 avatar notbobthebuilder avatar shamansir avatar simran-b avatar waywardmonkeys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

binary-parser's Issues

Great enhancement!

The encoder part was just what I was looking for, keep up the great work. Are you going to merge with the latest changes from origin?

Add an option to set custom string padding char

If a length is set and the given string is shorter than the length, the generated code fills the emptyness with spaces.

I have a use case where the padding needs to be \u0000.

the workaround is that I use the encoder function to fill the padding with my zeroes:

const encodeString = (str) => {
	return str + '\u0000'.repeat(100);
};
...
.string('flash_tel_nr', { stripNull: true, length: 20, trim: true, encoder: encodeString })

Also, an option argument passed to the encoder would be nice.

Little endianess incorrect

let parser = new Parser() .endianess("little") .bit4("a") .bit1("b") .bit1("c") .bit1("d") .bit1("e") .uint16("f") .array("g", { type: "uint8", readUntil: "eof" });

Encoding and then parsing an object using this parser in little endian mode does not result in the same object, but it does in big endian mode.

encode() return type should be Buffer and not any

Documentation says: Encoded result will be returned as a Buffer object.

Parser.encode() is declared as encode(obj: any): any; in binary_parser.d.ts

Parser.encode() return type should be declared as Buffer

String padded with space (0x20) instead of null (0x0) when reencoding

Suppose I have this code

parser.string(name, {
    length: string_size,
    zeroTerminated: false,
    stripNull: true
});

where string_size is some fixed length.
The thing appears to be parsed nicely, but when I try to re-encode, the missing fields are filled with spaces. A temporary workaround I found is

encoder: item => (item+'') + Array(1024).fill("\0").join("") // 1024 being some arbitrary number that's bigger than string_size

since then the string is just capped at its maximum length, and only then my output file is equal to input.

[bug] ReferenceError: SmartBuffer is not defined

Hi,
Many thanks for this super useful package.

I'm using it in my current project but I have one annoying issue, which is that I can't run my Jest based tests with parser based encoding. Here is the error message:

    ReferenceError: SmartBuffer is not defined

      at Parser.compiledEncode (evalmachine.<anonymous>:5:19)
      at Parser.Object.<anonymous>.Parser.encode (node_modules/binary-parser-encoder/lib/binary_parser.js:455:15)
      at input.reduce (src/myfile.js:196:14)
          at Array.reduce (<anonymous>)
      at download (src/myfile.js:193:16)
      at Object.test (src/myfile.test.js:9:12)

EDIT
I slim down my codebase to only a test file:

const { Parser } = require('binary-parser-encoder');

const parser = new Parser()
  .uint32be('data_0');

test('test', () => {
  const a = parser.encode({ data_0: '123' })
    .toString('hex');
  expect(a).toEqual('0000007b');
});

I would appreciate any help.

What is even stranger this test works perfectly in codesandbox https://codesandbox.io/s/m3z1wz265x

Unable to encode uint64

var ipHeader = new Parser()
.uint16("fragment_id")
.uint16("fragment_total")
.uint64("date_time")

var anIpHeader = {
fragment_id: 1,
fragment_total: 1,
datetime: 4744430483355899789,
}

console.log(ipHeader.encode(anIpHeader).toString("hex"));

I am getting error:

internal/buffer.js:598
let lo = Number(value & 0xffffffffn);
^

TypeError: Cannot mix BigInt and other types, use explicit conversions
at writeBigU_Int64BE (internal/buffer.js:598:25)
at Buffer.writeBigUInt64BE (internal/buffer.js:618:10)
at SmartBuffer._writeNumberValue (C:\work\ugves\project\repo-poc\emulator-prs-poc\nodejs-es-to-prs\node-start-es6\node_modules\smart-buffer\src\smartbuffer.ts:1402:10)
at SmartBuffer.writeBigUInt64BE (C:\work\ugves\project\repo-poc\emulator-prs-poc\nodejs-es-to-prs\node-start-es6\node_modules\smart-buffer\src\smartbuffer.ts:576:17)
at Parser.compiledEncode (evalmachine.:11:13)

Please help me how can i fix this issue

appreciate quick support,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.