Description
We currently are converting integers to strings and then writing them as ASCII to the ByteBuffer.
let string = String(integer)
self.writeString(string)
This is b/c the Memcached meta command protocol is text based and commands are send as ASCII strings.
Sending binary data would lead to an error for example: the command ms foo 2
would be incorrectly serialized as ms foo \0\0\0\0\0\0\0\u{2}
if we used writeInteger
.
However, this string conversion is not the most performant solution and could potently slow down our API. we would like to explore more efficient ways of writing the integer as ASCII digits directly to the ByteBuffer, bypassing the string conversion all together.
There are two possible solutions thus far that we are considering.
- We could write everything into a big tuple and then reverse write them into the byte buffer
- We could write everything in reverse into the byte buffer and then just swap the bytes around.
The second options is promising as it Is easier to implement and can also leverage swifts quotientAndRemainder
method to perform the Integer division and modules in one go.