[ox/mc] Use VLI encoding for integers

This commit is contained in:
2019-03-17 03:03:21 -05:00
parent 817e3fcef1
commit e0605edb6e
6 changed files with 53 additions and 65 deletions

View File

@@ -65,9 +65,10 @@ Error MetalClawWriter::op(const char*, SerStr val) {
bool fieldSet = false;
if (val.cap()) {
// write the length
if (m_buffIt + sizeof(StringLength) + val.bytes() < m_buffLen) {
*reinterpret_cast<LittleEndian<StringLength>*>(&m_buff[m_buffIt]) = static_cast<StringLength>(val.bytes());
m_buffIt += sizeof(StringLength);
const auto strLen = mc::encodeInteger(val.bytes());
if (m_buffIt + strLen.length + val.bytes() < m_buffLen) {
ox_memcpy(&m_buff[m_buffIt], strLen.data, strLen.length);
m_buffIt += strLen.length;
// write the string
ox_memcpy(&m_buff[m_buffIt], val.c_str(), val.bytes());