in c/src/core/value_dump.c [168:314]
void pn_value_dump_scalar(uint8_t type, pn_bytes_t value, pn_fixed_string_t *output){
if (type_isfixedsize(type)) {
if (type_isspecial(type)) {
pn_value_dump_special(type, output);
} else if (type_issimpleint(type)) {
// Read bits into unsigned sign extended
uint64_t uint;
uint64_t mask;
switch (value.size) {
case 1:
uint = (int8_t)*value.start;
mask = 0xff;
break;
case 2:
uint = (int16_t)pni_read16(value.start);
mask = 0xffff;
break;
case 4:
uint = (int32_t)pni_read32(value.start);
mask = 0xffffffff;
break;
case 8:
uint = pni_read64(value.start);
mask = 0xffffffffffffffff;
break;
case 0:
// We'll get here if there aren't enough bytes left for the value
pn_fixed_string_addf(output, "!!");
return;
default:
// It has to be length 1,2,4 or 8!
pn_fixed_string_addf(output, "!!<WeirdLengthHappened(%zu)>", value.size);
return;
}
if (type_isunsigned_ifsimpleint(type)) {
// mask high sign extended bits if unsigned
uint = uint & mask;
pn_fixed_string_addf(output, "0x%" PRIx64, uint);
} else {
int64_t i = (int64_t)uint;
pn_fixed_string_addf(output, "%" PRIi64, i);
}
} else {
// Check if we didn't have enough bytes for the value
if (value.size==0) {
pn_fixed_string_addf(output, "!!");
return;
}
switch (type) {
case PNE_BOOLEAN:
pn_fixed_string_addf(output, *value.start ? "true" : "false");
break;
case PNE_FLOAT: {
union {uint32_t i; float f;} conv;
conv.i = pni_read32(value.start);
pn_fixed_string_addf(output, "%g", conv.f);
break;
}
case PNE_DOUBLE: {
union {uint64_t i; double f;} conv;
conv.i = pni_read64(value.start);
pn_fixed_string_addf(output, "%g", conv.f);
break;
}
case PNE_UTF32:
break;
case PNE_MS64: {
int64_t timestamp = pni_read64(value.start);
pn_fixed_string_addf(output, "%" PRIi64, timestamp);
break;
}
case PNE_DECIMAL32:
pn_fixed_string_addf(output, "D32(%04" PRIx32 ")", pni_read32(value.start));
break;
case PNE_DECIMAL64:
pn_fixed_string_addf(output, "D64(%08" PRIx64 ")", pni_read64(value.start));
break;
case PNE_DECIMAL128:
pn_fixed_string_addf(
output,
"D128(%08" PRIx64 "%08" PRIx64 ")",
pni_read64(value.start), pni_read64(&value.start[8]));
break;
case PNE_UUID:
pn_fixed_string_addf(
output,
"UUID(%02hhx%02hhx%02hhx%02hhx-"
"%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-"
"%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx)",
value.start[0], value.start[1], value.start[2],value.start[3],
value.start[4], value.start[5],
value.start[6], value.start[7],
value.start[8], value.start[9],
value.start[10], value.start[11], value.start[12], value.start[13], value.start[14], value.start[15]);
break;
default:
pn_fixed_string_addf(output, "!!<UnknownType<0x%02hhx>(", type);
for (size_t i=0; i<value.size; i++) {
pn_fixed_string_addf(output, "%.2x", value.start[i]);
}
pn_fixed_string_addf(output, ")>");
}
}
} else {
// given we're variable size scalar and we've already calculated the length we can simply switch on subtype
// which can only be 0 (binary), 1 (utf8 string) or 3 (symbol) [I wonder what happened to subtype 2!]
const char* prefix = "";
const char* suffix = "";
switch (type & 0xf) {
case 0:
prefix = "b\"";
suffix = "\"";
break;
case 1:
prefix = "\"";
suffix = "\"";
break;
case 3: {
bool quote = false;
if (value.size==0 || !isalpha(value.start[0])) {
quote = true;
} else {
for (size_t i = 1; i < value.size; i++) {
if ( !isalnum(value.start[i]) && value.start[i]!='-' ) {
quote = true;
break;
}
}
}
if (quote) {
prefix = ":\"";
suffix = "\"";
} else {
prefix = ":";
suffix = "";
}
break;
}
default:
prefix = "<?<";
suffix = ">?>";
}
pn_fixed_string_addf(output, "%s", prefix);
pn_fixed_string_quote(output, value.start, value.size);
pn_fixed_string_addf(output, "%s", suffix);
}
}