change: decode message, description and timestamp
Dependencies
- [2]
WMFNGOYTchange: reduce printed noise, rework some code - [3]
Q7TKZCJPAdd initial support for reading the offsets from a (fixed) change - [4]
3NA345CNAdd zstd_seekable + many headers - [5]
B3XLVPNCAdd ani.c and initial Makefile - [6]
FB67XX5Eadd argument parsing setup - [7]
X36ICMJNInitial import for blake3 - [8]
VKLGQREYchange: add base32 decode, initial deconstruction of hashed - [9]
3OHR6ZPHmake: prettify output - [*]
PEUS54XQ - [*]
RIWSVVASchange: decompress the 'contents' with zstd_seekable - [*]
OBKF6SIIchange: decompress the hashed section too
Change contents
- file addition: scaffold.h[11.1]
#ifndef SCAFFOLD_H#define SCAFFOLD_H/* Various scaffolding functions around stdlib functions */void *xmalloc(size_t size);#endif - file addition: scaffold.c[11.1]
#include <stdio.h>#include <stdlib.h>#include "scaffold.h"/*** Expand to support varargs like a regular printf*/void die(const char *msg){fprintf(stderr, msg);exit(57);}void *xmalloc(size_t size){void *ret;ret = malloc(size);if (!ret)die("Unable to allocate memory");return ret;} - replacement in change.h at line 39
void *authors; /* something... */void *authors; /* a "key"="value" collection */ - edit in change.c at line 10
#include "scaffold.h" - edit in change.c at line 15[3.711][13.0]
#include "bincode.h" - edit in change.c at line 165[13.1172][3.872]
uint8_t *p; - edit in change.c at line 171
uint64_t len; - replacement in change.c at line 197
/* TODO Decode into 'struct hashed' */p = buf;dump_buf("hashed", p, hashed_len);hashed.version = bincode_getu64(p);printf("version = %lu\n", hashed.version);p += sizeof(uint64_t);len = bincode_getu64(p);p += sizeof(uint64_t);hashed.header.message = bincode_getstr(p, len);p += len;printf("message = '%s'\n", hashed.header.message);/*** Description! This is like the commit "body", and is optional, so we* have a byte indicating its presence, '0' = None, '1' =* Some(description)*/if (*p++) {len = bincode_getu64(p);p += sizeof(uint64_t);hashed.header.description = bincode_getstr(p, len);p += len;printf("description = '%s'\n", hashed.header.description);} elseprintf("description = (none)\n");len = bincode_getu64(p);p += sizeof(uint64_t); - edit in change.c at line 230[3.1400][13.1373]
if (len != 30)printf("warning: timestamp field has unexpected length %lu (expected 30)\n", len);hashed.header.timestamp = bincode_getstr(p, len);p += len;printf("timestamp = '%s'\n", hashed.header.timestamp); - file addition: bincode.h[11.1]
#ifndef BINCODE_H#define BINCODE_H/** Requires: <stdint.h> *//*** Definitions for the bincode encode/decode routines.** Generally, the idea here is that you open a file, get a file descriptor and* use the encode/decode routines to get components read from the fd and and* decoded as the type you want.*//*** Some notes regarding the bincode format:** Enum types: The order of the variants matter, as the encoding indicates the* variant with a u32.*/uint16_t bincode_getu16(uint8_t *);uint32_t bincode_getu32(uint8_t *);uint64_t bincode_getu64(uint8_t *);/*** Allocate and return a string of the given length.** The memory allocated shall be the given length plus one, to hold the* terminating zero.** Returns the allocated string. The caller is responsible for deallocating.*/char *bincode_getstr(uint8_t *, size_t);/* void bincode_putu16(uint8_t *, uint16_t); *//* void bincode_putu32(uint8_t *, uint32_t); *//* void bincode_putu64(uint8_t *, uint64_t); */#endif - file addition: bincode.c[11.1]
#include <stdint.h>#include <stddef.h>#include <stdlib.h>#include <string.h>#include "scaffold.h"#include "bincode.h"uint16_tbincode_getu16(uint8_t *b){return (uint16_t)b[1] << 8 | (uint16_t)b[0];}uint32_tbincode_getu32(uint8_t *b){return (uint32_t)b[3] << 24| (uint32_t)b[2] << 16| (uint32_t)b[1] << 8| (uint32_t)b[0];}uint64_tbincode_getu64(uint8_t *b){return (uint64_t)b[7] << 56| (uint64_t)b[6] << 48| (uint64_t)b[5] << 40| (uint64_t)b[4] << 32| (uint64_t)b[3] << 24| (uint64_t)b[2] << 16| (uint64_t)b[1] << 8| (uint64_t)b[0];}char *bincode_getstr(uint8_t *b, size_t len){char *str;str = xmalloc(len + 1);memcpy(str, b, len);str[len] = '\0';return str;} - edit in Makefile at line 24
OBJS += bincode.oOBJS += scaffold.o - replacement in Makefile at line 33
@printf "LD\t%s\n" $@@printf " LD\t%s\n" $@