core :: Writer :: write_msgpack_ext
typ
and bytes
in the shortest possible MessagePack ext formatRequire: bytes.length <= 0xFFFF_FFFF
var writer = new BytesWriter
writer.write_msgpack_ext(0x0A, b"\x0B\x0C\x0D")
assert writer.bytes == b"\xC7\x03\x0A\x0B\x0C\x0D"
# Write an application-specific extension for `typ` and `bytes` in the shortest possible MessagePack _ext_ format
#
# Require: `bytes.length <= 0xFFFF_FFFF`
#
# ~~~
# var writer = new BytesWriter
# writer.write_msgpack_ext(0x0A, b"\x0B\x0C\x0D")
# assert writer.bytes == b"\xC7\x03\x0A\x0B\x0C\x0D"
# ~~~
fun write_msgpack_ext(typ: Int, bytes: Bytes)
do
var len = bytes.length
if len == 1 then
write_msgpack_fixext1 typ
write_byte bytes.first
else if len == 2 then
write_msgpack_fixext2 typ
write_bytes bytes
else if len == 4 then
write_msgpack_fixext4 typ
write_bytes bytes
else if len == 8 then
write_msgpack_fixext8 typ
write_bytes bytes
else if len == 16 then
write_msgpack_fixext16 typ
write_bytes bytes
else if len <= 0xFF then
write_msgpack_ext8(typ, len)
write_bytes bytes
else if len <= 0xFFFF then
write_msgpack_ext16(typ, len)
write_bytes bytes
else if len <= 0xFFFF_FFFF then
write_msgpack_ext32(typ, len)
write_bytes bytes
else
abort
end
end
lib/msgpack/write.nit:407,2--446,4