Skip to content

int24 and uint24 support #93

Open
Open

Description

@South-Paw

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 👍

Activity

  1. keichi commented on Mar 23, 2019

    @keichi
    Owner

    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;
      }
    });
  2. South-Paw commented on Mar 24, 2019

    @South-Paw
    Author

    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!! ❤️ 👍

  3. self-assigned this
    on Jun 3, 2019
  4. South-Paw commented on Oct 12, 2019

    @South-Paw
    Author

    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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions