Browse Source

Packet encoding optimization

master
Nikita 11 years ago
parent
commit
f8b6f38db5
  1. 9
      src/main/java/com/corundumstudio/socketio/parser/Encoder.java

9
src/main/java/com/corundumstudio/socketio/parser/Encoder.java

@ -69,7 +69,7 @@ public class Encoder {
ByteBuf packetBuffer = allocateBuffer(allocator); ByteBuf packetBuffer = allocateBuffer(allocator);
try { try {
int len = encodePacket(packet, packetBuffer);
int len = encodePacketWithLength(packet, packetBuffer);
byte[] lenBytes = toChars(len); byte[] lenBytes = toChars(len);
buffer.writeBytes(Packet.DELIMITER_BYTES); buffer.writeBytes(Packet.DELIMITER_BYTES);
@ -157,7 +157,7 @@ public class Encoder {
return buf; return buf;
} }
public int encodePacket(Packet packet, ByteBuf buffer) throws IOException {
public void encodePacket(Packet packet, ByteBuf buffer) throws IOException {
ByteBufOutputStream out = new ByteBufOutputStream(buffer); ByteBufOutputStream out = new ByteBufOutputStream(buffer);
int start = buffer.writerIndex(); int start = buffer.writerIndex();
int type = packet.getType().getValue(); int type = packet.getType().getValue();
@ -244,6 +244,11 @@ public class Encoder {
} }
break; break;
} }
}
public int encodePacketWithLength(Packet packet, ByteBuf buffer) throws IOException {
int start = buffer.writerIndex();
encodePacket(packet, buffer);
return charsScanner.getLength(buffer, start); return charsScanner.getLength(buffer, start);
} }

Loading…
Cancel
Save