static inline int tns_render_bool(void *val, tns_outbuf *outbuf) { if(val == Py_True) { return tns_outbuf_rputs(outbuf, "true", 4); } else { return tns_outbuf_rputs(outbuf, "false", 5); } }
static inline int tns_render_bool(void *val, tns_outbuf *outbuf) { tns_value_t *t = (tns_value_t *)val; assert(t->type == tns_tag_bool && "Value is not a bool."); if(t->value.bool) { return tns_outbuf_rputs(outbuf, "true", 4); } else { return tns_outbuf_rputs(outbuf, "false", 5);
static inline int tns_render_number(void *val, tns_outbuf *outbuf) { tns_value_t *t = (tns_value_t *)val; char out[120] = {0}; assert(t->type == tns_tag_number && "Value is not a number."); int rc = snprintf(out, 119, "%ld", t->value.number); check(rc != -1 && rc <= 119, "Failed to generate number."); out[119] = '\0'; // safety since snprintf might not do this return tns_outbuf_rputs(outbuf, out, rc); error: return -1; }
static inline int tns_render_string(void *val, tns_outbuf *outbuf) { return tns_outbuf_rputs(outbuf, PyString_AS_STRING(val), PyString_GET_SIZE(val)); }
// Functions for parsing and rendering primitive datatypes. static inline int tns_render_string(void *val, tns_outbuf *outbuf) { tns_value_t *t = (tns_value_t *)val; assert(t->type == tns_tag_string && "Value is not a string."); return tns_outbuf_rputs(outbuf, bdata(t->value.string), blength(t->value.string)); }