List of usage examples for io.netty.buffer ByteBuf writeShort
public abstract ByteBuf writeShort(int value);
From source file:com.digitalpetri.modbus.codec.ModbusResponseEncoder.java
License:Apache License
private ByteBuf encodeMaskWriteRegister(MaskWriteRegisterResponse response, ByteBuf buffer) { buffer.writeByte(response.getFunctionCode().getCode()); buffer.writeShort(response.getAddress()); buffer.writeShort(response.getAndMask()); buffer.writeShort(response.getOrMask()); return buffer; }
From source file:com.digitalpetri.modbus.examples.slave.SlaveExample.java
License:Apache License
public void start() throws ExecutionException, InterruptedException { slave.setRequestHandler(new ServiceRequestHandler() { @Override// ww w .j a v a 2 s .c om public void onReadHoldingRegisters( ServiceRequest<ReadHoldingRegistersRequest, ReadHoldingRegistersResponse> service) { ReadHoldingRegistersRequest request = service.getRequest(); ByteBuf registers = PooledByteBufAllocator.DEFAULT.buffer(request.getQuantity()); for (int i = 0; i < request.getQuantity(); i++) { registers.writeShort(i); } service.sendResponse(new ReadHoldingRegistersResponse(registers)); ReferenceCountUtil.release(request); } }); slave.bind("localhost", 50200).get(); }
From source file:com.digitalpetri.opcua.stack.core.channel.ChunkEncoder.java
License:Apache License
private void writePadding(int cipherTextBlockSize, int paddingSize, ByteBuf buffer) { if (cipherTextBlockSize > 256) { buffer.writeShort(paddingSize); } else {// ww w. j av a 2s. com buffer.writeByte(paddingSize); } for (int i = 0; i < paddingSize; i++) { buffer.writeByte(paddingSize); } if (cipherTextBlockSize > 256) { // Replace the last byte with the MSB of the 2-byte padding length int paddingLengthMSB = paddingSize >> 8; buffer.writerIndex(buffer.writerIndex() - 1); buffer.writeByte(paddingLengthMSB); } }
From source file:com.flowpowered.examples.networking.TestProtocol.java
License:MIT License
@Override public ByteBuf writeHeader(ByteBuf header, CodecRegistration codec, ByteBuf data) { header.writeShort(codec.getOpcode()); header.writeInt(data.writerIndex()); return header; }
From source file:com.flowpowered.examples.networking.TestSecondProtocol.java
License:MIT License
@Override public ByteBuf writeHeader(ByteBuf header, Codec.CodecRegistration codec, ByteBuf data) { header.writeShort(codec.getOpcode()); header.writeInt(data.writerIndex()); return header; }
From source file:com.friz.network.utility.BufferUtils.java
License:Open Source License
/** * Puts a 6 byte integer into the buffer. * @param buf The channel buffer//from w w w .ja va 2 s. c o m * @param value The value to be added. */ public static void put6ByteInteger(ByteBuf buf, long value) { buf.writeShort((int) (value >> 32)); buf.writeInt((int) (value)); }
From source file:com.friz.owari.network.codec.HandshakeEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, HandshakeEvent msg, ByteBuf out) throws Exception { if (!out.isWritable()) return;//from w w w.jav a 2 s . c om out.writeShort(msg.getStatus()); }
From source file:com.github.jrialland.ajpclient.impl.ForwardImpl.java
License:Apache License
protected static void sendRequest(final Channel channel, final ForwardRequest request) throws IOException { // start by writing message payload, header will be appended afterwards final ByteArrayOutputStream baos = new ByteArrayOutputStream(MAX_MESSAGE_SIZE); final DataOutputStream tmp = new DataOutputStream(baos); // request type tmp.writeByte(PREFIX_FORWARD_REQUEST); // payload//from www .j ava 2s .c o m tmp.writeByte(request.getMethod().getCode()); writeString(request.getProtocol(), tmp); writeString(request.getRequestUri(), tmp); writeString(request.getRemoteAddress(), tmp); writeString(request.getRemoteHost(), tmp); writeString(request.getServerName(), tmp); tmp.writeShort(request.getServerPort()); tmp.writeBoolean(request.isSsl()); tmp.writeShort(request.getHeaders().size()); // headers for (final Header header : request.getHeaders()) { final Integer code = RequestHeader.getKeyCode(header.getKey()); if (code == null) { writeString(header.getKey(), tmp); } else { tmp.writeShort(code); } writeString(header.getValue(), tmp); } // attributes for (final Entry<Attribute, String> attr : request.getAttributes().entrySet()) { tmp.writeByte(attr.getKey().getCode()); writeString(attr.getValue(), tmp); } // request terminator tmp.write(REQUEST_TERMINATOR); tmp.flush(); // now prepare the whole message final byte[] data = baos.toByteArray(); if (data.length + 4 > MAX_MESSAGE_SIZE) { throw new IllegalArgumentException("Message size is larger than " + MAX_MESSAGE_SIZE + " bytes."); } final ByteBuf buf = Buffers.makeBuffer(4 + data.length); buf.writeBytes(CLIENT_MAGIC); buf.writeShort(data.length); buf.writeBytes(data); channel.writeAndFlush(buf); getLog().debug( "Sent : FORWARDREQUEST (" + PREFIX_FORWARD_REQUEST + "), payload size = " + data.length + " bytes"); final InputStream requestBody = request.getRequestBody(); if (requestBody != null) { sendChunk(true, requestBody, MAX_SEND_CHUNK_SIZE, channel); } }
From source file:com.github.milenkovicm.kafka.protocol.Convert.java
License:Apache License
public static void encodeShort(int integer, ByteBuf buf) { buf.writeShort(integer); }
From source file:com.github.mrstampy.pprspray.core.streamer.util.MediaStreamerUtils.java
License:Open Source License
/** * Write header.// w w w. j av a 2 s. c o m * * @param buf * the buf * @param type * the type * @param headerLength * the header length * @param messageHash * the message hash * @param mediaHash * the media hash * @param sequence * the sequence * @param ackRequired * the ack required */ public static void writeHeader(ByteBuf buf, MediaStreamType type, int headerLength, int messageHash, int mediaHash, long sequence, boolean ackRequired) { buf.writeBytes(type.ordinalBytes()); buf.writeShort(headerLength); buf.writeInt(messageHash); buf.writeInt(mediaHash); buf.writeLong(sequence); buf.writeBoolean(ackRequired); }