void pni_inspect_atom()

in c/src/core/codec.c [113:259]


void pni_inspect_atom(pn_atom_t *atom, pn_fixed_string_t *str)
{
  switch (atom->type) {
  case PN_NULL:
    pn_fixed_string_addf(str, "null");
    return;
  case PN_BOOL:
    pn_fixed_string_addf(str, atom->u.as_bool ? "true" : "false");
    return;
  case PN_UBYTE:
    pn_fixed_string_addf(str, "%" PRIu8, atom->u.as_ubyte);
    return;
  case PN_BYTE:
    pn_fixed_string_addf(str, "%" PRIi8, atom->u.as_byte);
    return;
  case PN_USHORT:
    pn_fixed_string_addf(str, "%" PRIu16, atom->u.as_ushort);
    return;
  case PN_SHORT:
    pn_fixed_string_addf(str, "%" PRIi16, atom->u.as_short);
    return;
  case PN_UINT:
    pn_fixed_string_addf(str, "%" PRIu32, atom->u.as_uint);
    return;
  case PN_INT:
    pn_fixed_string_addf(str, "%" PRIi32, atom->u.as_int);
    return;
  case PN_CHAR:
    pn_fixed_string_addf(str, "%c",  atom->u.as_char);
    return;
  case PN_ULONG:
    pn_fixed_string_addf(str, "%" PRIu64, atom->u.as_ulong);
    return;
  case PN_LONG:
    pn_fixed_string_addf(str, "%" PRIi64, atom->u.as_long);
    return;
  case PN_TIMESTAMP:
    pn_fixed_string_addf(str, "%" PRIi64, atom->u.as_timestamp);
    return;
  case PN_FLOAT:
    pn_fixed_string_addf(str, "%g", atom->u.as_float);
    return;
  case PN_DOUBLE:
    pn_fixed_string_addf(str, "%g", atom->u.as_double);
    return;
  case PN_DECIMAL32:
    pn_fixed_string_addf(str, "D32(%" PRIu32 ")", atom->u.as_decimal32);
    return;
  case PN_DECIMAL64:
    pn_fixed_string_addf(str, "D64(%" PRIu64 ")", atom->u.as_decimal64);
    return;
  case PN_DECIMAL128:
    pn_fixed_string_addf(str, "D128(%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
                          "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
                          "%02hhx%02hhx)",
                          atom->u.as_decimal128.bytes[0],
                          atom->u.as_decimal128.bytes[1],
                          atom->u.as_decimal128.bytes[2],
                          atom->u.as_decimal128.bytes[3],
                          atom->u.as_decimal128.bytes[4],
                          atom->u.as_decimal128.bytes[5],
                          atom->u.as_decimal128.bytes[6],
                          atom->u.as_decimal128.bytes[7],
                          atom->u.as_decimal128.bytes[8],
                          atom->u.as_decimal128.bytes[9],
                          atom->u.as_decimal128.bytes[10],
                          atom->u.as_decimal128.bytes[11],
                          atom->u.as_decimal128.bytes[12],
                          atom->u.as_decimal128.bytes[13],
                          atom->u.as_decimal128.bytes[14],
                          atom->u.as_decimal128.bytes[15]);
    return;
  case PN_UUID:
    pn_fixed_string_addf(str, "UUID(%02hhx%02hhx%02hhx%02hhx-"
                          "%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-"
                          "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx)",
                          atom->u.as_uuid.bytes[0],
                          atom->u.as_uuid.bytes[1],
                          atom->u.as_uuid.bytes[2],
                          atom->u.as_uuid.bytes[3],
                          atom->u.as_uuid.bytes[4],
                          atom->u.as_uuid.bytes[5],
                          atom->u.as_uuid.bytes[6],
                          atom->u.as_uuid.bytes[7],
                          atom->u.as_uuid.bytes[8],
                          atom->u.as_uuid.bytes[9],
                          atom->u.as_uuid.bytes[10],
                          atom->u.as_uuid.bytes[11],
                          atom->u.as_uuid.bytes[12],
                          atom->u.as_uuid.bytes[13],
                          atom->u.as_uuid.bytes[14],
                          atom->u.as_uuid.bytes[15]);
    return;
  case PN_BINARY:
  case PN_STRING:
  case PN_SYMBOL:
    {
      const char *pfx;
      pn_bytes_t bin = atom->u.as_bytes;
      bool quote;
      switch (atom->type) {
      case PN_BINARY:
        pfx = "b";
        quote = true;
        break;
      case PN_STRING:
        pfx = "";
        quote = true;
        break;
      case PN_SYMBOL:
        pfx = ":";
        quote = false;
        for (unsigned i = 0; i < bin.size; i++) {
          if (!isalpha(bin.start[i])) {
            quote = true;
            break;
          }
        }
        break;
      default:
        assert(false);
        return;
      }

      pn_fixed_string_addf(str, "%s", pfx);
      if (quote) pn_fixed_string_addf(str, "\"");
      pn_fixed_string_quote(str, bin.start, bin.size);
      if (quote) pn_fixed_string_addf(str, "\"");
      return;
    }
  case PN_LIST:
    pn_fixed_string_addf(str, "<list>");
    return;
  case PN_MAP:
    pn_fixed_string_addf(str, "<map>");
    return;
  case PN_ARRAY:
    pn_fixed_string_addf(str, "<array>");
    return;
  case PN_DESCRIBED:
    pn_fixed_string_addf(str, "<described>");
    return;
  default:
    pn_fixed_string_addf(str, "<undefined: %i>", atom->type);
    return;
  }
}