Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

int24 and uint24 support #93

Open
South-Paw opened this issue Mar 23, 2019 · 3 comments
Open

int24 and uint24 support #93

South-Paw opened this issue Mar 23, 2019 · 3 comments
Assignees

Comments

@South-Paw
Copy link

Is it possible for the package to add support for .int24() and .uint24()?

Since you can't sequence more than 4 bytes using .bit24() I'm in a bit of a pickle with a buffer I'd like to decode.

  • Why no uint24? #83 is similar on 'why no unit24 support'
  • ccsds #90 as an issue with sequencing bits, but also looks like they could use a .int24()

If this isn't possible, can someone direct me to a package that is similar to this but supports int24()?

Thanks 👍

@keichi
Copy link
Owner

keichi commented Mar 23, 2019

I will add support for int24() and uint24(). Can you use the following workaround for now?

var parser = new Parser().array("uint24", {
  type: "uint8",
  length: 3,
  formatter: function(arr) {
    return arr[2] << 16 | arr[1] << 8 | arr[0];
  }
});

var parser = new Parser().array("int24", {
  type: "uint8",
  length: 3,
  formatter: function(arr) {
    var val = arr[2] << 16 | arr[1] << 8 | arr[0];

    return (val > 0x7fffff) ? 0xff000000 | val : val;
  }
});

@South-Paw
Copy link
Author

South-Paw commented Mar 24, 2019

Aha! I had a feeling there'd be a way to work around it but just didn't know how to even start doing it with the library as this sort of thing isn't really my forte or area of expertise.

@keichi you're awesome, will use this till its in the package - thanks heaps!! ❤️ 👍

@keichi keichi self-assigned this Jun 3, 2019
@South-Paw
Copy link
Author

South-Paw commented Oct 12, 2019

Hi @keichi, just come across this again and wondering if the int24 and uint24 will be added to the package sometime soon?

Looks like I also have a use case for int24be and uint24be now as the workarounds you provided don't seem to work for one of my requirements - I can only get the correct expected value out of the buffer if I use the following:

// <Buffer f9 59 a6 1a 57 c8 0f d3 00 48 01 a9>

let a = buffer.readIntBE(0, 3);
let b = buffer.readIntBE(3, 3);

console.log({ a, b }); // { a: -435802, b: 1726408 }

I assume it doesn't work because these are big-edian int values? Is there another way to work around this using the library? In the mean time I'm just creating two objects and merging them before returning from my helper function 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants