Pack Booleans #4

Open
opened 2018-01-15 02:41:52 +00:00 by leo60228 · 1 comment
leo60228 commented 2018-01-15 02:41:52 +00:00 (Migrated from github.com)

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'
      }
    }
  }]
});
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. ```js 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 commented 2018-02-07 14:26:10 +00:00 (Migrated from github.com)

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.

Hello @leo60228 , Currently you can implement this yourself on top of this lib, using a Buffer and them extracting the bits: ```js 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 in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: sitegui/js-binary#4
No description provided.