MCPcopy Create free account
hub / github.com/F-Stack/f-stack / cbor_content

Function cbor_content

tools/libxo/encoder/cbor/enc_cbor.c:203–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201}
202
203static int
204cbor_content (xo_handle_t *xop, cbor_private_t *cbor, xo_buffer_t *xbp,
205 const char *value)
206{
207 int rc = 0;
208
209 unsigned offset = xo_buf_offset(xbp);
210
211 if (value == NULL || *value == '\0' || xo_streq(value, "true"))
212 cbor_append(xop, cbor, &cbor->c_data, CBOR_TRUE, 0, NULL);
213 else if (xo_streq(value, "false"))
214 cbor_append(xop, cbor, &cbor->c_data, CBOR_FALSE, 0, NULL);
215 else {
216 int negative = 0;
217 if (*value == '-') {
218 value += 1;
219 negative = 1;
220 }
221
222 char *ep;
223 unsigned long long ival;
224 ival = strtoull(value, &ep, 0);
225 if (ival == ULLONG_MAX) /* Sometimes a string is just a string */
226 cbor_append(xop, cbor, xbp, CBOR_STRING, strlen(value), value);
227 else {
228 *xbp->xb_curp = negative ? CBOR_NEGATIVE : CBOR_UNSIGNED;
229 if (negative)
230 ival -= 1; /* Don't waste a negative zero */
231 cbor_encode_uint(xbp, ival, negative ? CBOR_NLIMIT : CBOR_ULIMIT);
232 }
233 }
234
235 if (xo_get_flags(xop) & XOF_PRETTY)
236 cbor_memdump(stdout, "content", xo_buf_data(xbp, offset),
237 xbp->xb_curp - xbp->xb_bufp - offset, "",
238 cbor->c_indent * 2);
239
240 return rc;
241}
242
243static int
244cbor_handler (XO_ENCODER_HANDLER_ARGS)

Callers 1

cbor_handlerFunction · 0.85

Calls 7

xo_buf_offsetFunction · 0.85
xo_streqFunction · 0.85
cbor_appendFunction · 0.85
cbor_encode_uintFunction · 0.85
xo_get_flagsFunction · 0.85
cbor_memdumpFunction · 0.85
xo_buf_dataFunction · 0.85

Tested by

no test coverage detected