I need to create a Bytebuffer like object in Ruby. Here is my example in JAVA
int ADD_BYTES_FOR_MSG_LENGTH = 4;
Integer messageBodySize = new Integer(messageBody.getBytes().length);
byte[] messageHeader = ByteBuffer.allocate(ADD_BYTES_FOR_MSG_LENGTH).putInt(messageBodySize).array();
messageToSend = new byte[messageHeader.length + messageBodySize];
System.arraycopy(messageHeader, 0, messageToSend, 0, messageHeader.length);
System.arraycopy(messageBody.getBytes(), 0, messageToSend, messageHeader.length, messageBodySize);
I create a message starting with 4 bytes where is located size of the message body part, and then the actual message. I have no idea how to do this in Ruby, so please help.