18void put_u(
pc_sb *b, uint32_t v)
24 tmp[n++] = (char)(
'0' + (
int)(v % 10));
28 for (
int i = 0; i < n; i++)
30 out[i] = tmp[n - 1 - i];
37size_t pc_utmc_request(
const char *object_id,
char *out,
size_t cap)
39 pc_sb b = {out, cap, 0, out !=
nullptr && cap > 0};
40 pc_sb_put(&b,
"<?xml version=\"1.0\"?><UTMCRequest><object id=\"");
46size_t pc_utmc_response(
const char *object_id,
const char *value, uint8_t quality,
const char *timestamp,
char *out,
49 pc_sb b2 = {out, cap, 0, out !=
nullptr && cap > 0};
50 pc_sb_put(&b2,
"<?xml version=\"1.0\"?><UTMCResponse><object id=\"");
62size_t pc_utmc_parse_request(
const char *xml,
size_t len,
char *out,
size_t cap)
64 if (!xml || !out || cap == 0)
69 const char *key =
"id=\"";
71 for (
size_t i = 0; i + kl < len; i++)
73 if (memcmp(xml + i, key, kl) != 0)
79 while (j < len && xml[j] !=
'"')
Bounded no-heap string builder that fails closed on overflow (one shared copy).
size_t pc_sb_finish(pc_sb *b)
NUL-terminate and return the built length, or 0 if the build overflowed.
void pc_sb_xml(pc_sb *b, const char *s)
Append s XML-escaped (& < > "); a NULL s appends nothing.
void pc_sb_put(pc_sb *b, const char *s)
Append NUL-terminated s; leaves the buffer untouched and clears ok if it would not fit.
Bump-append target; ok latches false once an append would overflow cap.
UTMC (Urban Traffic Management and Control) common-database codec (PC_ENABLE_UTMC).