Example usage for io.netty.buffer ByteBuf writeShort

List of usage examples for io.netty.buffer ByteBuf writeShort

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writeShort.

Prototype

public abstract ByteBuf writeShort(int value);

Source Link

Document

Sets the specified 16-bit short integer at the current writerIndex and increases the writerIndex by 2 in this buffer.

Usage

From source file:com.grandhunterman.dnvm.common.Message.java

License:Creative Commons License

private static void writeShort(short s, ByteBuf buf) {
    buf.writeShort(s);
}

From source file:com.heliosapm.ohcrs.core.AbstractDriverCodec.java

License:Apache License

/**
 * Writes the segment prefix which is a short indicating the DBType and a boolean where false is null and true is not-null.
 * @param o The object being written so we can test it for null
 * @param t The DBType of the object being written
 * @param b The buffer to write to//from  w  w  w .  java  2s .  c  o m
 * @return true if the value was not null, false otherwise
 */
@SuppressWarnings("static-method")
protected boolean prefix(final Object o, DBType t, final ByteBuf b) {
    b.writeShort(t.code());
    final boolean notNull = (o == P || o != null);
    b.writeBoolean(notNull);
    return notNull;
}

From source file:com.heliosapm.ohcrs.core.AbstractDriverCodec.java

License:Apache License

/**
 * {@inheritDoc}/*from w w  w  .  ja va2  s.c  o m*/
 * @see com.heliosapm.ohcrs.core.DriverCodec#write(short, io.netty.buffer.ByteBuf)
 */
@Override
public int write(final Short p, final ByteBuf b) throws SQLException {
    prefix(p, DBType.SMALLINT, b);
    b.writeShort(p);
    return b.writerIndex();
}

From source file:com.heliosapm.ohcrs.core.AbstractDriverCodec.java

License:Apache License

/**
 * {@inheritDoc}/*from w ww . j  av a  2s  .  c om*/
 * @see com.heliosapm.ohcrs.core.DriverCodec#write(short, io.netty.buffer.ByteBuf)
 */
@Override
public int write(final short p, final ByteBuf b) throws SQLException {
    prefix(P, DBType.SMALLINT, b);
    b.writeShort(p);
    return b.writerIndex();
}

From source file:com.ibm.crail.namenode.rpc.netty.common.NettyRequest.java

License:Apache License

public int write(ByteBuf buffer) throws IOException {
    buffer.writeLong(cookie); //8
    buffer.writeShort(cmd); //2
    buffer.writeShort(type); //2
    int written = 12;

    nioBuffer.clear();//from   w  w  w .j  a v  a  2  s .  c  o  m
    switch (type) {
    case NameNodeProtocol.REQ_CREATE_FILE:
        written += createFileReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_GET_FILE:
        written += fileReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_SET_FILE:
        written += setFileReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_REMOVE_FILE:
        written += removeReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_RENAME_FILE:
        written += renameFileReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_GET_BLOCK:
        written += getBlockReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_GET_LOCATION:
        written += getLocationReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_SET_BLOCK:
        written += setBlockReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_GET_DATANODE:
        written += getDataNodeReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_DUMP_NAMENODE:
        written += dumpNameNodeReq.write(nioBuffer);
        break;
    case NameNodeProtocol.REQ_PING_NAMENODE:
        written += pingNameNodeReq.write(nioBuffer);
        break;
    }
    /* instead of flip you want to clear it */
    nioBuffer.clear();
    buffer.writeBytes(nioBuffer);
    return written;
}

From source file:com.ibm.crail.namenode.rpc.netty.common.NettyResponse.java

License:Apache License

public int write(ByteBuf buffer) {
    buffer.writeLong(cookie);// w  ww .  j  a v  a 2 s. c o m
    buffer.writeShort(type);
    buffer.writeShort(error);

    int written = 12;
    nioBuffer.clear();
    switch (type) {
    case NameNodeProtocol.RES_VOID:
        written += voidRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_CREATE_FILE:
        written += createFileRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_GET_FILE:
        written += getFileRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_DELETE_FILE:
        written += delFileRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_RENAME_FILE:
        written += renameRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_GET_BLOCK:
        written += getBlockRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_GET_LOCATION:
        written += getLocationRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_GET_DATANODE:
        written += getDataNodeRes.write(nioBuffer);
        break;
    case NameNodeProtocol.RES_PING_NAMENODE:
        written += pingNameNodeRes.write(nioBuffer);
        break;
    }
    /* reset and copy becuase we want to copy the whole capacity of the nio buffer */
    nioBuffer.clear();
    buffer.writeBytes(nioBuffer);
    return written;
}

From source file:com.l2jmobius.commons.network.codecs.LengthFieldBasedFrameEncoder.java

License:Open Source License

@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) {
    final ByteBuf buf = ctx.alloc().buffer(2);
    final short length = (short) (msg.readableBytes() + 2);
    buf.writeShort(buf.order() != ByteOrder.LITTLE_ENDIAN ? Short.reverseBytes(length) : length);
    out.add(buf);// w w  w  .  j ava  2  s  .c o m
    out.add(msg.retain());
}

From source file:com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroupTest.java

License:Apache License

private static DnsRecord newMappedAddressRecord(String name, String ipV4Addr) {
    final ByteBuf content = Unpooled.buffer();
    content.writeZero(10);//  w w w . j a va 2s. c o  m
    content.writeShort(0xFFFF);
    content.writeBytes(NetUtil.createByteArrayFromIpAddressString(ipV4Addr));
    return new DefaultDnsRawRecord(name, AAAA, 60, content);
}

From source file:com.linecorp.armeria.client.endpoint.dns.DnsServiceEndpointGroupTest.java

License:Apache License

private static DnsRecord newSrvRecord(String hostname, int weight, int port, String target) {
    final ByteBuf content = Unpooled.buffer();
    content.writeShort(1); // priority unused
    content.writeShort(weight);//w  w w  .ja  va  2 s.co m
    content.writeShort(port);
    DnsNameEncoder.encodeName(target, content);
    return new DefaultDnsRawRecord(hostname, SRV, 60, content);
}

From source file:com.ltln.modules.openflow.core.protocol.ver10.OFActionTypeSerializerVer10.java

public static void writeTo(ByteBuf bb, OFActionType e) {
    bb.writeShort(toWireValue(e));
}