jrhea commented on a change in pull request #24: Move to hobbits 3 with binary
messages
URL: https://github.com/apache/incubator-tuweni/pull/24#discussion_r301699955
##########
File path: hobbits/src/main/kotlin/org/apache/tuweni/hobbits/Message.kt
##########
@@ -88,21 +71,41 @@ class Message(
* @return the bytes of the message
*/
fun toBytes(): Bytes {
- val requestLine = "$protocol $version $command ${headers.size()}
${body.size()}\n"
- return Bytes.concatenate(Bytes.wrap(requestLine.toByteArray()), headers,
body)
+ val buffer = ByteBuffer.allocate(PREAMBLE.size + java.lang.Integer.BYTES *
3 + 1)
+ buffer.put(PREAMBLE)
+ buffer.putInt(version)
+ buffer.put(protocol.code)
+ buffer.putInt(headers.size())
+ buffer.putInt(body.size())
+
+ return Bytes.concatenate(Bytes.wrap(buffer.array()), headers, body)
}
/**
* Provides the size of the message
* @return the size of the message
*/
fun size(): Int {
- return protocol.length + 5 + version.length + command.length +
headers.size().toString().length +
- body.size().toString().length + headers.size() + body.size()
+ return PREAMBLE.size + java.lang.Integer.BYTES * 3 + 1 + headers.size() +
body.size()
Review comment:
just use: MESSAGE_HEADER_LENGTH instead of PREAMBLE.size +
java.lang.Integer.BYTES * 3 + 1
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]