Beispiel #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;
 }
Beispiel #2
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);
   }
 }