- printf("\t%c%c:", key[0], key[1]);
- if (type == 'A') { printf("A:%c", *s); ++s; }
- else if (type == 'C') { printf("i:%u", *s); ++s; }
- else if (type == 'c') { printf("i:%d", *s); ++s; }
- else if (type == 'S') { printf("i:%u", *(uint16_t*)s); s += 2; }
- else if (type == 's') { printf("i:%d", *(int16_t*)s); s += 2; }
- else if (type == 'I') { printf("i:%u", *(uint32_t*)s); s += 4; }
- else if (type == 'i') { printf("i:%d", *(int32_t*)s); s += 4; }
- else if (type == 'f') { printf("f:%g", *(float*)s); s += 4; }
- else if (type == 'Z' || type == 'H') { printf("%c:", type); while (*s) putchar(*s++); ++s; }
+ kputc('\t', &str); kputsn((char*)key, 2, &str); kputc(':', &str);
+ if (type == 'A') { kputsn("A:", 2, &str); kputc(*s, &str); ++s; }
+ else if (type == 'C') { kputsn("i:", 2, &str); kputw(*s, &str); ++s; }
+ else if (type == 'c') { kputsn("i:", 2, &str); kputw(*(int8_t*)s, &str); ++s; }
+ else if (type == 'S') { kputsn("i:", 2, &str); kputw(*(uint16_t*)s, &str); s += 2; }
+ else if (type == 's') { kputsn("i:", 2, &str); kputw(*(int16_t*)s, &str); s += 2; }
+ else if (type == 'I') { kputsn("i:", 2, &str); kputuw(*(uint32_t*)s, &str); s += 4; }
+ else if (type == 'i') { kputsn("i:", 2, &str); kputw(*(int32_t*)s, &str); s += 4; }
+ else if (type == 'f') { ksprintf(&str, "f:%g", *(float*)s); s += 4; }
+ else if (type == 'd') { ksprintf(&str, "d:%lg", *(double*)s); s += 8; }
+ else if (type == 'Z' || type == 'H') { kputc(type, &str); kputc(':', &str); while (*s) kputc(*s++, &str); ++s; }
+ else if (type == 'B') {
+ uint8_t sub_type = *(s++);
+ int32_t n;
+ memcpy(&n, s, 4);
+ s += 4; // no point to the start of the array
+ kputc(type, &str); kputc(':', &str); kputc(sub_type, &str); // write the typing
+ for (i = 0; i < n; ++i) {
+ kputc(',', &str);
+ if ('c' == sub_type || 'c' == sub_type) { kputw(*(int8_t*)s, &str); ++s; }
+ else if ('C' == sub_type) { kputw(*(uint8_t*)s, &str); ++s; }
+ else if ('s' == sub_type) { kputw(*(int16_t*)s, &str); s += 2; }
+ else if ('S' == sub_type) { kputw(*(uint16_t*)s, &str); s += 2; }
+ else if ('i' == sub_type) { kputw(*(int32_t*)s, &str); s += 4; }
+ else if ('I' == sub_type) { kputuw(*(uint32_t*)s, &str); s += 4; }
+ else if ('f' == sub_type) { ksprintf(&str, "%g", *(float*)s); s += 4; }
+ }
+ }