ssbc / bipf

Binary json codec optimized for in-place access
MIT License
48 stars 9 forks source link

Test vector #31

Open tschudin opened 2 years ago

tschudin commented 2 years ago

returning the favor to @arj03 and providing a test vector for BIPF:

f50418666f6f8c02127fff0a800a810aff0a000a010a7f12800012007f1a0080000e002179656168061862616695014046726564686f6c6d4305413da6832fbc3f186261722868656c6c6f1862617a06

which should turn, in Python speak, into {'foo': [-129, -128, -127, -1, 0, 1, 127, 128, 32512, 32768, False, b'yeah', None], 'baf': {'Fredholm': 0.1101000100000001}, 'bar': 'hello', 'baz': None}

does this compute?

This is the memory view (key val pairs) when iterating:

> 18666f6f 8c02127fff0a800a810aff0a000a010a7f12800012007f1a0080000e00217965616806
  > 0 127fff
  > 1 0a80
  > 2 0a81
  > 3 0aff
  > 4 0a00
  > 5 0a01
  > 6 0a7f
  > 7 128000
  > 8 12007f
  > 9 1a008000
  > 10 0e00
  > 11 2179656168
  > 12 06
> 18626166 95014046726564686f6c6d4305413da6832fbc3f
  > 4046726564686f6c6d 4305413da6832fbc3f
> 18626172 2868656c6c6f
> 1862617a 06
staltz commented 2 years ago

@tschudin this is what I get in JS:

const bipf = require('bipf')

const tv = Buffer.from([
  0xf5, 0x04, 0x18, 0x66, 0x6f, 0x6f, 0x8c, 0x02, 0x12, 0x7f, 0xff, 0x0a, 0x80,
  0x0a, 0x81, 0x0a, 0xff, 0x0a, 0x00, 0x0a, 0x01, 0x0a, 0x7f, 0x12, 0x80, 0x00,
  0x12, 0x00, 0x7f, 0x1a, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x21, 0x79, 0x65, 0x61,
  0x68, 0x06, 0x18, 0x62, 0x61, 0x66, 0x95, 0x01, 0x40, 0x46, 0x72, 0x65, 0x64,
  0x68, 0x6f, 0x6c, 0x6d, 0x43, 0x05, 0x41, 0x3d, 0xa6, 0x83, 0x2f, 0xbc, 0x3f,
  0x18, 0x62, 0x61, 0x72, 0x28, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x18, 0x62, 0x61,
  0x7a, 0x06,
])

console.log(bipf.decode(tv))
/*

{
  foo: [
    -2146762881,
    176228992,
    184486529,
    167774975,
    167840256,
    310315521,
    8393343,
    1179776,
    1736448,
    234913792,
    false,
    <Buffer 79 65 61 68>,
    null
  ],
  baf: { Fredholm: 0.1101000100000001 },
  bar: 'hello',
  baz: null
}

*/
tschudin commented 2 years ago

@staltz thanks for testing! Happy to see that it's quite close. Re the integer values, I guess this relates to the comment in your code: //TODO: encode in minimum bytes

arj03 commented 2 years ago

That should probably be it @tschudin. There is a tradeoff between speed and space, but I do agree that minimal encoding of integers and doubles should be explored. More information here: https://github.com/ssbc/bipf/issues/2

I have started https://github.com/ssbc/bipf-spec that includes some fixtures.