List of usage examples for io.netty.buffer ByteBuf writeShort
public abstract ByteBuf writeShort(int value);
From source file:org.inspirenxe.server.network.codec.play.JoinGameCodec.java
License:MIT License
@Override public ByteBuf encode(ByteBuf buf, JoinGameMessage message) throws IOException { buf.writeInt(message.getPlayerId()); short gameMode = (short) message.getGameMode().value(); if (message.isHardcore()) { gameMode |= 8;//from w w w . j a va 2 s . c om } buf.writeShort(gameMode); buf.writeByte(message.getDimension().value()); buf.writeShort(message.getDifficulty().value()); buf.writeShort(message.getMaxPlayers()); ByteBufUtils.writeUTF8(buf, message.getLevelType().name()); return buf; }
From source file:org.iotivity.cloud.base.protocols.coap.CoapEncoder.java
License:Open Source License
private void calcShimHeader(CoapMessage coapMessage, ByteBuf byteBuf, long length) { if (length < 13) { byteBuf.writeByte(((int) length & 0x0F) << 4 | (coapMessage.getTokenLength() & 0x0F)); } else if (length < 269) { byteBuf.writeShort( (13 & 0x0F) << 12 | (coapMessage.getTokenLength() & 0x0F) << 8 | (((int) length - 13) & 0xFF)); } else if (length < 65805) { byteBuf.writeByte((14 & 0x0F) << 4 | (coapMessage.getTokenLength() & 0x0F)); byteBuf.writeShort(((int) length - 269) & 0xFFFF); } else if (length < 4294967294L) { byteBuf.writeByte((15 & 0x0F) << 4 | (coapMessage.getTokenLength() & 0x0F)); byte[] size = new byte[4]; long payload = length - 65805; for (int i = 3; i > -1; i--) { size[i] = (byte) (payload & 0xFF); payload >>= 8;/*from w ww .j a va 2s .co m*/ } byteBuf.writeBytes(size); } else { throw new IllegalArgumentException("Length must be less than 4GB " + length); } }
From source file:org.jfxvnc.net.rfb.codec.encoder.PixelFormatEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, PixelFormat pf, ByteBuf out) throws Exception { out.writeByte(ClientEventType.SET_PIXEL_FORMAT); out.writeZero(3); // padding out.writeByte(pf.getBitPerPixel());//from www .j av a 2 s . co m out.writeByte(pf.getDepth()); out.writeBoolean(pf.isBigEndian()); out.writeBoolean(pf.isTrueColor()); out.writeShort(pf.getRedMax()); out.writeShort(pf.getGreenMax()); out.writeShort(pf.getBlueMax()); out.writeByte(pf.getRedShift()); out.writeByte(pf.getGreenShift()); out.writeByte(pf.getBlueShift()); out.writeZero(3); // padding ctx.pipeline().remove(this); }
From source file:org.jfxvnc.net.rfb.codec.encoder.PointerEventEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, PointerEvent msg, ByteBuf out) throws Exception { ByteBuf buf = ctx.alloc().buffer(6); try {/*from www . jav a2s. com*/ buf.writeByte(ClientEventType.POINTER_EVENT); buf.writeByte(msg.getButtonMask()); buf.writeShort(msg.getxPos()); buf.writeShort(msg.getyPos()); out.writeBytes(buf); } finally { buf.release(); } }
From source file:org.jfxvnc.net.rfb.codec.encoder.PreferedEncodingEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, PreferedEncoding enc, ByteBuf out) throws Exception { out.writeByte(ClientEventType.SET_ENCODINGS); out.writeZero(1); // padding out.writeShort(enc.getEncodings().length); Arrays.stream(enc.getEncodings()).forEach(e -> out.writeInt(e.getType())); ctx.pipeline().remove(this); }
From source file:org.jfxvnc.net.rfb.codec.ProtocolHandler.java
License:Apache License
public void sendFramebufferUpdateRequest(ChannelHandlerContext ctx, boolean incremental, int x, int y, int w, int h) {//from w w w.ja va 2 s. co m ByteBuf buf = ctx.alloc().buffer(10); buf.writeByte(ClientEventType.FRAMEBUFFER_UPDATE_REQUEST); buf.writeByte(incremental ? 1 : 0); buf.writeShort(x); buf.writeShort(y); buf.writeShort(w); buf.writeShort(h); ctx.writeAndFlush(buf); }
From source file:org.jmqtt.core.codec.ConnectEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext chc, ConnectPacket message, ByteBuf out) { ByteBuf staticHeaderBuff = chc.alloc().buffer(12); ByteBuf buff = chc.alloc().buffer(); ByteBuf variableHeaderBuff = chc.alloc().buffer(12); try {//from w w w .j av a 2 s . co m staticHeaderBuff.writeBytes(MqttUtils.encodeString("MQIsdp")); //version staticHeaderBuff.writeByte(0x03); //connection flags and Strings byte connectionFlags = 0; if (message.isCleanSession()) { connectionFlags |= 0x02; } if (message.isWillFlag()) { connectionFlags |= 0x04; } connectionFlags |= ((message.getWillQos() & 0x03) << 3); if (message.isWillRetain()) { connectionFlags |= 0x020; } if (message.isPasswordFlag()) { connectionFlags |= 0x040; } if (message.isUserFlag()) { connectionFlags |= 0x080; } staticHeaderBuff.writeByte(connectionFlags); //Keep alive timer staticHeaderBuff.writeShort(message.getKeepAlive()); //Variable part if (message.getClientId() != null) { variableHeaderBuff.writeBytes(MqttUtils.encodeString(message.getClientId())); if (message.isWillFlag()) { variableHeaderBuff.writeBytes(MqttUtils.encodeString(message.getWillTopic())); variableHeaderBuff.writeBytes(MqttUtils.encodeFixedLengthContent(message.getWillMessage())); } if (message.isUserFlag() && message.getUsername() != null) { variableHeaderBuff.writeBytes(MqttUtils.encodeString(message.getUsername())); if (message.isPasswordFlag() && message.getPassword() != null) { variableHeaderBuff.writeBytes(MqttUtils.encodeFixedLengthContent(message.getPassword())); } } } int variableHeaderSize = variableHeaderBuff.readableBytes(); buff.writeByte(AbstractPacket.CONNECT << 4); buff.writeBytes(MqttUtils.encodeRemainingLength(12 + variableHeaderSize)); buff.writeBytes(staticHeaderBuff).writeBytes(variableHeaderBuff); out.writeBytes(buff); } finally { staticHeaderBuff.release(); buff.release(); variableHeaderBuff.release(); } }
From source file:org.jmqtt.core.codec.PubAckEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext chc, PubAckPacket msg, ByteBuf out) { ByteBuf buff = chc.alloc().buffer(4); try {//w ww. j av a2 s . c o m buff.writeByte(AbstractPacket.PUBACK << 4); buff.writeBytes(MqttUtils.encodeRemainingLength(2)); buff.writeShort(msg.getPacketId()); out.writeBytes(buff); } finally { buff.release(); } }
From source file:org.jmqtt.core.codec.PubCompEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext chc, PubCompPacket msg, ByteBuf out) { out.writeByte(AbstractPacket.PUBCOMP << 4); out.writeBytes(MqttUtils.encodeRemainingLength(2)); out.writeShort(msg.getPacketId()); }