19void put_i64(
DetSb *b, int64_t v)
26 uint64_t u = neg ? (uint64_t)(-(v + 1)) + 1 : (uint64_t)v;
29 tmp[n++] = (char)(
'0' + (
int)(u % 10));
36 for (
int i = 0; i < n; i++)
37 out[k++] = tmp[n - 1 - i];
42const char *NS =
" xmlns=\"urn:ieee:std:2030.5:ns\"";
43const char *DECL =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
46size_t detws_sep2_device_capability(uint32_t poll_rate,
const char *edev_list_href,
const char *derp_list_href,
47 char *out,
size_t cap)
49 DetSb b = {out, cap, 0, out !=
nullptr && cap > 0};
54 put_i64(&b, poll_rate);
66size_t detws_sep2_end_device(uint64_t sfdi,
const char *lfdi,
const char *href,
char *out,
size_t cap)
68 DetSb b = {out, cap, 0, out !=
nullptr && cap > 0};
75 put_i64(&b, (int64_t)sfdi);
82size_t detws_sep2_der_control(
const char *mrid, uint32_t start, uint32_t duration, int32_t opmod_target_w,
char *out,
85 DetSb b = {out, cap, 0, out !=
nullptr && cap > 0};
94 put_i64(&b, duration);
95 det_sb_put(&b,
"</duration></interval><DERControlBase><opModFixedW>");
96 put_i64(&b, opmod_target_w);
97 det_sb_put(&b,
"</opModFixedW></DERControlBase></DERControl>");
IEEE 2030.5 (Smart Energy Profile 2.0) resource codec (DETWS_ENABLE_SEP2).
Bounded no-heap string builder that fails closed on overflow (one shared copy).
size_t det_sb_finish(DetSb *b)
NUL-terminate and return the built length, or 0 if the build overflowed.
void det_sb_put(DetSb *b, const char *s)
Append NUL-terminated s; leaves the buffer untouched and clears ok if it would not fit.
void det_sb_xml(DetSb *b, const char *s)
Append s XML-escaped (& < > "); a NULL s appends nothing.
Bump-append target; ok latches false once an append would overflow cap.