encodeLen static method
int
encodeLen(
- dynamic buf,
- dynamic offset,
- dynamic len
)
Implementation
static int encodeLen(buf, offset, len) {
if (len <= 0x7f) {
buf[offset] = len;
return 1;
} else if (len <= 0xff) {
buf[offset] = 0x81;
buf[offset + 1] = len;
return 2;
} else if (len <= 0xffff) {
buf[offset] = 0x82;
buf[offset + 1] = len >> 8;
buf[offset + 2] = len;
return 3;
} else if (len <= 0xffffff) {
buf[offset] = 0x83;
buf[offset + 1] = len >> 16;
buf[offset + 2] = len >> 8;
buf[offset + 3] = len;
return 4;
} else {
throw Exception("Length too long (> 4 bytes)");
}
}