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:   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);

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


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