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

Pack Booleans #4

Open
leo60228 opened this issue Jan 15, 2018 · 1 comment
Open

Pack Booleans #4

leo60228 opened this issue Jan 15, 2018 · 1 comment

Comments

@leo60228
Copy link

With this type, it packs the buttons compound type into 10 bytes instead of the preferable 2 bytes, or even 1.25 (though this would probably be much slower). Could you change this? I didn't see any plans for backwards-compatibility in the spec.

const Format = new Type({
  version: 'uint',
  frames: [{
    buttons: {
      A: 'boolean',
      B: 'boolean',
      X: 'boolean',
      Y: 'boolean',
      L: 'boolean',
      R: 'boolean',
      ZL: 'boolean',
      ZR: 'boolean',
      plus: 'boolean',
      minus: 'boolean',
    },
    sticks: {
      L: {
        x: 'uint',
        y: 'uint'
      },
      R: {
        x: 'uint',
        y: 'uint'
      }
    }
  }]
});
@sitegui
Copy link
Owner

sitegui commented Feb 7, 2018

Hello @leo60228 ,

Currently you can implement this yourself on top of this lib, using a Buffer and them extracting the bits:

function getBit(buffer, n) {
  return buffer[n>>3] >> (n & 0x7) & 1
}

We could implement a 'bit' type in the future that could group multiple fields into a single byte, but this isn't straight forward as it seems at first.

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