BufferRef COBSEncode(const BufferRef& buffer) { size_t maxEncodedSize = buffer->getSize() + ceil(static_cast<float>(buffer->getSize()) / 254) + 1; BufferRef encodeBuffer = Buffer::create(maxEncodedSize); size_t encodedSize = COBSEncode(reinterpret_cast<const uint8_t*>(buffer->getData()), buffer->getSize(), reinterpret_cast<uint8_t*>(encodeBuffer->getData())); encodeBuffer->resize(encodedSize); return encodeBuffer; }
BufferRef SLIPEncode(const BufferRef& buffer) { size_t maxEncodedSize = 2 * buffer->getSize() + 2; BufferRef encodeBuffer = Buffer::create(maxEncodedSize); size_t encodedSize = SLIPEncode(reinterpret_cast<const uint8_t*>(buffer->getData()), buffer->getSize(), reinterpret_cast<uint8_t*>(encodeBuffer->getData())); encodeBuffer->resize(encodedSize); return encodeBuffer; }
BufferRef COBSDecode(const BufferRef& buffer) { size_t maxDecodedSize = buffer->getSize() - 1; BufferRef decodeBuffer = Buffer::create(maxDecodedSize); size_t decodedSize = COBSDecode(reinterpret_cast<const uint8_t*>(buffer->getData()), buffer->getSize(), reinterpret_cast<uint8_t*>(decodeBuffer->getData())); decodeBuffer->resize(decodedSize); return decodeBuffer; }
BufferRef SLIPDecode(const BufferRef& buffer) { // should not assume double-ENDed variant size_t maxDecodedSize = buffer->getSize() - 1; BufferRef decodeBuffer = Buffer::create(maxDecodedSize); size_t decodedSize = SLIPDecode(reinterpret_cast<const uint8_t*>(buffer->getData()), buffer->getSize(), reinterpret_cast<uint8_t*>(decodeBuffer->getData())); decodeBuffer->resize(decodedSize); return decodeBuffer; }