private EzyByteBuffer mergeBytes(byte[] bytes) { int capacity = buffer.remaining() + bytes.Length; EzyByteBuffer merge = EzyByteBuffer.allocate(capacity); merge.put(buffer); merge.put(bytes); merge.flip(); return(merge); }
public byte[] convert(EzyMessage message) { EzyByteBuffer buffer = newByteBuffer(message); writeHeader(buffer, message); writeSize(buffer, message); writeContent(buffer, message); byte[] answer = new byte[buffer.position()]; buffer.flip(); buffer.get(answer); return(answer); }
protected void sendHandshakeRequest() { int tokenSize = sessionToken.Length; int messageSize = 0; messageSize += 8; // sessionIdSize messageSize += 2; // tokenLengthSize messageSize += tokenSize; // messageSize EzyByteBuffer buffer = EzyByteBuffer.allocate(1 + 2 + messageSize); byte header = 0; header |= 1 << 5; buffer.put(header); buffer.putShort((short)messageSize); buffer.putLong(sessionId); buffer.putShort((short)tokenSize); buffer.put(EzyStrings.getBytes(sessionToken)); buffer.flip(); byte[] bytes = buffer.getRemainBytes(); datagramChannel.Send(bytes, bytes.Length); }