use of org.jboss.netty.buffer.ChannelBuffer in project pinpoint by naver.
the class ControlHandshakeResponsePacket method readBuffer.
public static ControlHandshakeResponsePacket readBuffer(short packetType, ChannelBuffer buffer) {
assert packetType == PacketType.CONTROL_HANDSHAKE_RESPONSE;
if (buffer.readableBytes() < 8) {
buffer.resetReaderIndex();
return null;
}
final int messageId = buffer.readInt();
final ChannelBuffer payload = PayloadPacket.readPayload(buffer);
if (payload == null) {
return null;
}
final ControlHandshakeResponsePacket helloPacket = new ControlHandshakeResponsePacket(payload.array());
helloPacket.setRequestId(messageId);
return helloPacket;
}
use of org.jboss.netty.buffer.ChannelBuffer in project pinpoint by naver.
the class PayloadPacket method appendPayload.
public static ChannelBuffer appendPayload(final ChannelBuffer header, final byte[] payload) {
if (payload == null) {
// this is also payload header
header.writeInt(-1);
return header;
} else {
header.writeInt(payload.length);
ChannelBuffer payloadWrap = ChannelBuffers.wrappedBuffer(payload);
return ChannelBuffers.wrappedBuffer(true, header, payloadWrap);
}
}
use of org.jboss.netty.buffer.ChannelBuffer in project pinpoint by naver.
the class PingPacket method toBuffer.
@Override
public ChannelBuffer toBuffer() {
if (pingId == -1) {
return ChannelBuffers.wrappedBuffer(PING_BYTE);
} else {
// 2 + 4 + 1 + 1
ChannelBuffer buffer = ChannelBuffers.buffer(8);
buffer.writeShort(PacketType.CONTROL_PING);
buffer.writeInt(pingId);
buffer.writeByte(stateVersion);
buffer.writeByte(stateCode);
return buffer;
}
}
use of org.jboss.netty.buffer.ChannelBuffer in project pinpoint by naver.
the class RequestPacket method readBuffer.
public static RequestPacket readBuffer(short packetType, ChannelBuffer buffer) {
assert packetType == PacketType.APPLICATION_REQUEST;
if (buffer.readableBytes() < 8) {
buffer.resetReaderIndex();
return null;
}
final int messageId = buffer.readInt();
final ChannelBuffer payload = PayloadPacket.readPayload(buffer);
if (payload == null) {
return null;
}
final RequestPacket requestPacket = new RequestPacket(payload.array());
requestPacket.setRequestId(messageId);
return requestPacket;
}
use of org.jboss.netty.buffer.ChannelBuffer in project pinpoint by naver.
the class ResponsePacket method toBuffer.
@Override
public ChannelBuffer toBuffer() {
ChannelBuffer header = ChannelBuffers.buffer(2 + 4 + 4);
header.writeShort(PacketType.APPLICATION_RESPONSE);
header.writeInt(requestId);
return PayloadPacket.appendPayload(header, payload);
}
Aggregations