Exemplo n.º 1
0
 public Buffer encodeToWire() {
   int length = 1024; // TODO make this configurable
   Buffer buffer = Buffer.buffer(length);
   buffer.appendInt(0);
   buffer.appendByte(WIRE_PROTOCOL_VERSION);
   byte systemCodecID = messageCodec.systemCodecID();
   buffer.appendByte(systemCodecID);
   if (systemCodecID == -1) {
     // User codec
     writeString(buffer, messageCodec.name());
   }
   buffer.appendByte(send ? (byte) 0 : (byte) 1);
   writeString(buffer, address);
   if (replyAddress != null) {
     writeString(buffer, replyAddress);
   } else {
     buffer.appendInt(0);
   }
   buffer.appendInt(sender.port);
   writeString(buffer, sender.host);
   encodeHeaders(buffer);
   writeBody(buffer);
   buffer.setInt(0, buffer.length() - 4);
   return buffer;
 }
 @Override
 public void encodeToWire(Buffer buffer, String entries) {
   byte[] encoded = entries.getBytes(CharsetUtil.UTF_8);
   buffer.appendInt(encoded.length);
   Buffer buff = Buffer.buffer(encoded);
   buffer.appendBuffer(buff);
 }
Exemplo n.º 3
0
 private void encodeHeaders(Buffer buffer) {
   if (headers != null && !headers.isEmpty()) {
     int headersLengthPos = buffer.length();
     buffer.appendInt(0);
     buffer.appendInt(headers.size());
     List<Map.Entry<String, String>> entries = headers.entries();
     for (Map.Entry<String, String> entry : entries) {
       writeString(buffer, entry.getKey());
       writeString(buffer, entry.getValue());
     }
     int headersEndPos = buffer.length();
     buffer.setInt(headersLengthPos, headersEndPos - headersLengthPos);
   } else {
     buffer.appendInt(4);
   }
 }
Exemplo n.º 4
0
 @Override
 protected void writeBody(Buffer buff) {
   if (body == null) {
     buff.appendByte((byte) 0);
   } else {
     buff.appendByte((byte) 1);
     buff.appendInt(body);
   }
 }
Exemplo n.º 5
0
 @Override
 public Buffer writeToBuffer() {
   String encoded = encode();
   byte[] bytes = encoded.getBytes();
   Buffer buffer = Buffer.buffer(bytes.length + 4);
   buffer.appendInt(bytes.length);
   buffer.appendBytes(bytes);
   return buffer;
 }
Exemplo n.º 6
0
 @Override
 public void encodeToWire(Buffer buffer, MyPOJO myPOJO) {
   byte[] bytes = myPOJO.getStr().getBytes(CharsetUtil.UTF_8);
   buffer.appendInt(bytes.length);
   buffer.appendBytes(bytes);
 }
Exemplo n.º 7
0
 private void writeString(Buffer buff, String str) {
   byte[] strBytes = str.getBytes(CharsetUtil.UTF_8);
   buff.appendInt(strBytes.length);
   buff.appendBytes(strBytes);
 }