Java Code Examples for io.netty.buffer.ByteBuf.setShort()

The following are Jave code examples for showing how to use setShort() of the io.netty.buffer.ByteBuf class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: proteus-java   File: ProteusMetadata.java   Source Code and License Vote up 6 votes
public static int encode(ByteBuf byteBuf, int namespaceId, int serviceId, int methodId, ByteBuf metadata) {
    int offset = 0;

    byteBuf.setShort(offset, 1);
    offset += VERSION_SIZE;

    byteBuf.setInt(offset, namespaceId);
    offset += NAMESPACE_ID_SIZE;

    byteBuf.setInt(offset, serviceId);
    offset += SERVICE_ID_SIZE;

    byteBuf.setInt(offset, methodId);
    offset += METHOD_ID_SIZE;

    int metadataLength = metadata.readableBytes();
    byteBuf.setInt(offset, metadataLength);
    offset += METADATA_LENGTH_SIZE;

    byteBuf.setBytes(offset, metadata);
    offset += metadataLength;

    byteBuf.writerIndex(offset);

    return offset;
}
 
Example 2
Project: sstable-adaptor   File: CBUtil.java   Source Code and License Vote up 5 votes
public static void writeString(String str, ByteBuf cb)
{
    int writerIndex = cb.writerIndex();
    cb.writeShort(0);
    int lengthBytes = ByteBufUtil.writeUtf8(cb, str);
    cb.setShort(writerIndex, lengthBytes);
}
 
Example 3
Project: Limitart   File: AbstractBinaryEncoder.java   Source Code and License Vote up 4 votes
@Override
public void afterWriteBody(ByteBuf buf) {
	// 重设消息长度
	buf.setShort(0, buf.readableBytes() - Short.BYTES);
}