ClickHouse-Encoder
view release on metacpan or search on metacpan
OUTPUT:
RETVAL
# Unpack one varint from a byte string starting at the given offset.
# Returns (value, new_offset). Croaks on truncated input or a varint
# wider than 64 bits.
void
unpack_varint(bytes, offset)
SV *bytes
UV offset
PPCODE:
{
STRLEN len;
const unsigned char *p = (const unsigned char *)SvPVbyte(bytes, len);
UV v = tcp_read_varint(aTHX_ p, (UV)len, &offset);
EXTEND(SP, 2);
PUSHs(sv_2mortal(newSVuv(v)));
PUSHs(sv_2mortal(newSVuv(offset)));
}
# Pack a length-prefixed string (varint length + UTF-8 bytes). The
OUTPUT:
RETVAL
# Unpack a length-prefixed string at the given offset. Returns (string,
# new_offset). String bytes are returned without decoding (caller
# decides UTF-8 vs binary).
void
unpack_string(bytes, offset)
SV *bytes
UV offset
PPCODE:
{
STRLEN buf_len;
const unsigned char *p = (const unsigned char *)SvPVbyte(bytes, buf_len);
UV slen = tcp_read_varint(aTHX_ p, (UV)buf_len, &offset);
/* Subtraction form: addition (offset + slen) can wrap UV_MAX when
* slen is attacker-controlled via a crafted varint. tcp_read_varint
* guarantees offset <= buf_len on return, so buf_len - offset is
* safe. */
if (slen > (UV)buf_len - offset)
croak("string: truncated at offset %lu (need %lu)",
( run in 0.457 second using v1.01-cache-2.11-cpan-71847e10f99 )