bincode: introduce a bincode_state struct

laumann
Sep 8, 2022, 7:46 PM
4RYULBDDDIVSJTIOTBBSQAWMSN6ZBZEFJ6UR7P6ECEXEXTGPMUOAC

Dependencies

  • [2] VXGUQZIV bincode: rework so functions advance pointer
  • [3] WMFNGOYT change: reduce printed noise, rework some code
  • [4] RIWSVVAS change: decompress the 'contents' with zstd_seekable
  • [5] VKLGQREY change: add base32 decode, initial deconstruction of hashed
  • [6] Y26WT3ZF change: decode message, description and timestamp
  • [7] OBKF6SII change: decompress the hashed section too
  • [*] Q7TKZCJP Add initial support for reading the offsets from a (fixed) change

Change contents

  • edit in change.c at line 166
    [3.1172][3.619:632]()
    uint8_t *p;
  • edit in change.c at line 172
    [3.648]
    [3.2591]
    struct bincode_state binstat;
  • replacement in change.c at line 199
    [3.650][3.650:696]()
    p = buf;
    dump_buf("hashed", p, hashed_len);
    [3.650]
    [3.696]
    binstat.avail = hashed_len;
    binstat.buf = buf;
    dump_buf("hashed", buf, hashed_len);
  • replacement in change.c at line 203
    [3.697][2.22:60]()
    hashed.version = bincode_getu64(&p);
    [3.697]
    [3.734]
    hashed.version = bincode_getu64(&binstat);
  • replacement in change.c at line 206
    [3.803][2.61:88]()
    len = bincode_getu64(&p);
    [3.803]
    [3.853]
    len = bincode_getu64(&binstat);
  • replacement in change.c at line 208
    [3.854][2.89:139]()
    hashed.header.message = bincode_getstr(&p, len);
    [3.854]
    [3.914]
    hashed.header.message = bincode_getstr(&binstat, len);
  • replacement in change.c at line 216
    [3.1130][3.1130:1143](),[3.1143][2.140:223]()
    if (*p++) {
    len = bincode_getu64(&p);
    hashed.header.description = bincode_getstr(&p, len);
    [3.1130]
    [3.1262]
    if (bincode_getu8(&binstat)) {
    len = bincode_getu64(&binstat);
    hashed.header.description = bincode_getstr(&binstat, len);
  • replacement in change.c at line 223
    [3.1368][2.224:251]()
    len = bincode_getu64(&p);
    [3.1368]
    [3.1399]
    len = bincode_getu64(&binstat);
  • replacement in change.c at line 227
    [3.1520][2.252:304]()
    hashed.header.timestamp = bincode_getstr(&p, len);
    [3.1520]
    [3.1583]
    hashed.header.timestamp = bincode_getstr(&binstat, len);
  • edit in bincode.h at line 12
    [3.1994]
    [3.1994]
    */
    /**
    * This approach could simplify signatures a bit (in the sense of changing to a
    * single pointer again). It would also allow adding some bounds checking that
    * we aren't trying to read more data than available in the buffer. Maybe a case
    * for "if (unlikely(s->len - s->count < sizeof(type)))" ?
  • edit in bincode.h at line 20
    [3.1998]
    [3.1998]
    struct bincode_state {
    size_t avail; /* bytes still available */
    uint8_t *buf;
    };
  • replacement in bincode.h at line 31
    [3.2156][2.305:416]()
    uint16_t bincode_getu16(uint8_t **);
    uint32_t bincode_getu32(uint8_t **);
    uint64_t bincode_getu64(uint8_t **);
    [3.2156]
    [3.2264]
    uint8_t bincode_getu8(struct bincode_state *);
    uint16_t bincode_getu16(struct bincode_state *);
    uint32_t bincode_getu32(struct bincode_state *);
    uint64_t bincode_getu64(struct bincode_state *);
  • replacement in bincode.h at line 44
    [3.2502][2.417:459]()
    char *bincode_getstr(uint8_t **, size_t);
    [3.2502]
    [3.2543]
    char *bincode_getstr(struct bincode_state *, size_t);
  • edit in bincode.c at line 7
    [3.2855]
    [3.2855]
    uint8_t
    bincode_getu8(struct bincode_state *s)
    {
    uint8_t ret;
  • edit in bincode.c at line 13
    [3.2856]
    [3.2856]
    ret = s->buf[0];
  • edit in bincode.c at line 15
    [3.2857]
    [3.2857]
    s->avail -= sizeof(uint8_t);
    return ret;
    }
  • replacement in bincode.c at line 20
    [3.2866][2.460:489]()
    bincode_getu16(uint8_t **bp)
    [3.2866]
    [3.2893]
    bincode_getu16(struct bincode_state *s)
  • replacement in bincode.c at line 25
    [2.519][2.519:530]()
    b = *bp;
    [2.519]
    [2.530]
    b = s->buf;
  • replacement in bincode.c at line 28
    [2.576][2.576:602]()
    *bp += sizeof(uint16_t);
    [2.576]
    [2.602]
    s->avail -= sizeof(uint16_t);
  • replacement in bincode.c at line 33
    [3.2953][2.616:645]()
    bincode_getu32(uint8_t **bp)
    [3.2953]
    [3.2980]
    bincode_getu32(struct bincode_state *s)
  • replacement in bincode.c at line 38
    [2.675][2.675:686]()
    b = *bp;
    [2.675]
    [2.686]
    b = s->buf;
  • replacement in bincode.c at line 44
    [2.716][2.716:742]()
    *bp += sizeof(uint32_t);
    [2.716]
    [2.742]
    s->avail -= sizeof(uint32_t);
  • replacement in bincode.c at line 49
    [3.3092][2.756:785]()
    bincode_getu64(uint8_t **bp)
    [3.3092]
    [3.3119]
    bincode_getu64(struct bincode_state *s)
  • replacement in bincode.c at line 54
    [2.815][2.815:825]()
    b = *bp;
    [2.815]
    [2.825]
    b = s->buf;
  • replacement in bincode.c at line 64
    [2.855][2.855:881]()
    *bp += sizeof(uint64_t);
    [2.855]
    [2.881]
    s->avail -= sizeof(uint64_t);
  • replacement in bincode.c at line 69
    [3.3329][2.895:935]()
    bincode_getstr(uint8_t **b, size_t len)
    [3.3329]
    [3.3368]
    bincode_getstr(struct bincode_state *s, size_t len)
  • edit in bincode.c at line 72
    [3.3382]
    [3.3382]
    uint8_t *b;
  • edit in bincode.c at line 74
    [3.3383]
    [3.3383]
    b = s->buf;
  • replacement in bincode.c at line 76
    [3.3408][2.936:959]()
    memcpy(str, *b, len);
    [3.3408]
    [3.3430]
    memcpy(str, b, len);
  • replacement in bincode.c at line 78
    [3.3448][2.960:972]()
    *b += len;
    [3.3448]
    [3.3448]
    s->avail -= len;