List of usage examples for io.netty.buffer ByteBuf writeShort
public abstract ByteBuf writeShort(int value);
From source file:org.apache.cassandra.transport.CBUtil.java
License:Apache License
public static void writeBytesMap(Map<String, ByteBuffer> m, ByteBuf cb) { cb.writeShort(m.size()); for (Map.Entry<String, ByteBuffer> entry : m.entrySet()) { writeString(entry.getKey(), cb); writeValue(entry.getValue(), cb); }/*from w ww. j a v a 2s . co m*/ }
From source file:org.apache.cassandra.transport.DataType.java
License:Apache License
public void writeValue(Object value, ByteBuf cb, int version) { // Serialize as CUSTOM if client on the other side's version is < required for type if (version < protocolVersion) { CBUtil.writeString(value.toString(), cb); return;/*from w w w. j av a 2 s. c om*/ } switch (this) { case CUSTOM: assert value instanceof String; CBUtil.writeString((String) value, cb); break; case LIST: codec.writeOne(DataType.fromType((AbstractType) value, version), cb, version); break; case SET: codec.writeOne(DataType.fromType((AbstractType) value, version), cb, version); break; case MAP: List<AbstractType> l = (List<AbstractType>) value; codec.writeOne(DataType.fromType(l.get(0), version), cb, version); codec.writeOne(DataType.fromType(l.get(1), version), cb, version); break; case UDT: UserType udt = (UserType) value; CBUtil.writeString(udt.keyspace, cb); CBUtil.writeString(UTF8Type.instance.compose(udt.name), cb); cb.writeShort(udt.size()); for (int i = 0; i < udt.size(); i++) { CBUtil.writeString(UTF8Type.instance.compose(udt.fieldName(i)), cb); codec.writeOne(DataType.fromType(udt.fieldType(i), version), cb, version); } break; case TUPLE: TupleType tt = (TupleType) value; cb.writeShort(tt.size()); for (int i = 0; i < tt.size(); i++) codec.writeOne(DataType.fromType(tt.type(i), version), cb, version); break; } }
From source file:org.apache.cassandra.transport.OptionCodec.java
License:Apache License
public ByteBuf encode(Map<T, Object> options, int version) { int optLength = 2; for (Map.Entry<T, Object> entry : options.entrySet()) optLength += 2 + entry.getKey().serializedValueSize(entry.getValue(), version); ByteBuf cb = Unpooled.buffer(optLength); cb.writeShort(options.size()); for (Map.Entry<T, Object> entry : options.entrySet()) { T opt = entry.getKey();//from ww w . j a v a 2 s . co m cb.writeShort(opt.getId(version)); opt.writeValue(entry.getValue(), cb, version); } return cb; }
From source file:org.apache.cassandra.transport.OptionCodec.java
License:Apache License
public void writeOne(Pair<T, Object> option, ByteBuf dest, int version) { T opt = option.left;// ww w . j ava2 s.c om Object obj = option.right; dest.writeShort(opt.getId(version)); opt.writeValue(obj, dest, version); }
From source file:org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutputHelper.java
License:Apache License
private static void requestWriteBlock(Channel channel, Enum<?> storageType, OpWriteBlockProto.Builder writeBlockProtoBuilder) throws IOException { OpWriteBlockProto proto = STORAGE_TYPE_SETTER.set(writeBlockProtoBuilder, storageType).build(); int protoLen = proto.getSerializedSize(); ByteBuf buffer = channel.alloc().buffer(3 + CodedOutputStream.computeRawVarint32Size(protoLen) + protoLen); buffer.writeShort(DataTransferProtocol.DATA_TRANSFER_VERSION); buffer.writeByte(Op.WRITE_BLOCK.code); proto.writeDelimitedTo(new ByteBufOutputStream(buffer)); channel.writeAndFlush(buffer);//from www .j a va 2 s. c om }
From source file:org.apache.hadoop.hbase.util.FanOutOneBlockAsyncDFSOutputHelper.java
License:Apache License
private static void requestWriteBlock(Channel channel, Enum<?> storageType, OpWriteBlockProto.Builder writeBlockProtoBuilder) throws IOException { // TODO: SASL negotiation. should be done using a netty Handler. OpWriteBlockProto proto = STORAGE_TYPE_SETTER.set(writeBlockProtoBuilder, storageType).build(); int protoLen = proto.getSerializedSize(); ByteBuf buffer = channel.alloc().buffer(3 + CodedOutputStream.computeRawVarint32Size(protoLen) + protoLen); buffer.writeShort(DataTransferProtocol.DATA_TRANSFER_VERSION); buffer.writeByte(Op.WRITE_BLOCK.code); proto.writeDelimitedTo(new ByteBufOutputStream(buffer)); channel.writeAndFlush(buffer);/*ww w . j a va 2 s. c o m*/ }
From source file:org.beaconmc.network.socket.pipeline.PacketLegacy.java
License:Open Source License
private ByteBuf toArray(String pingstring) { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeByte(255);/*ww w. ja v a2 s. c om*/ char[] chars = pingstring.toCharArray(); byteBuf.writeShort(chars.length); for (char charpart : chars) { byteBuf.writeChar(charpart); } return byteBuf; }
From source file:org.bgp4j.netty.protocol.BadMessageLengthNotificationPacket.java
License:Apache License
@Override protected void encodeAdditionalPayload(ByteBuf buffer) { buffer.writeShort(getLength()); }
From source file:org.bgp4j.netty.protocol.BGPv4Packet.java
License:Apache License
/** * build a binary representation of the protocol packet * /*from w w w .j av a2 s.c om*/ * @param buffer The buffer to store the binary packet representation into */ public void encodePacket(ByteBuf buffer) { for (int i = 0; i < BGPv4Constants.BGP_PACKET_MARKER_LENGTH; i++) buffer.writeByte(0xff); int headerHeaderIndex = buffer.writerIndex(); buffer.writeShort(BGPv4Constants.BGP_PACKET_HEADER_LENGTH); buffer.writeByte(getType()); encodePayload(buffer); buffer.setShort(headerHeaderIndex, BGPv4Constants.BGP_PACKET_HEADER_LENGTH + (buffer.writerIndex() - headerHeaderIndex) - 3); }
From source file:org.bgp4j.netty.protocol.MaximumNumberOfPrefixesReachedNotificationPacket.java
License:Apache License
@Override protected void encodeAdditionalPayload(ByteBuf buffer) { if (this.addressFamily != null) { buffer.writeShort(addressFamily.toCode()); buffer.writeByte(subsequentAddressFamily.toCode()); buffer.writeInt(prefixUpperBound); }/* ww w. j a v a 2 s .c o m*/ }