List of usage examples for io.netty.buffer ByteBuf readInt
public abstract int readInt();
From source file:com.builtbroken.icbm.content.launcher.controller.remote.display.TileSiloInterfaceClient.java
protected void readConnectorSet(ByteBuf buf) { //Do we have data if (buf.readBoolean()) { //Number of controllers we are about to read int controllers = buf.readInt(); if (controllers > 0) { this.controllers = new String[controllers]; this.controllerData = new Pos[controllers][]; for (int c = 0; c < controllers; c++) { String name = ByteBufUtils.readUTF8String(buf); name = (name.isEmpty() || name.equals("--")) ? "c" + c : name; this.controllers[c] = name; readCommandSiloConnector(c, buf); }//from w ww . j av a2 s . c o m } else { //TODO show error saying no connection is provided } } }
From source file:com.builtbroken.icbm.content.launcher.launcher.standard.StandardMissileCrafting.java
@Override public StandardMissileCrafting readBytes(ByteBuf buf) { clear();/*w w w. j av a 2 s . c om*/ addRods(buf.readInt()); addPlates(buf.readInt()); ItemStack stack = ByteBufUtils.readItemStack(buf); if (stack.getItem() instanceof IModuleItem) { warhead = stack; } stack = ByteBufUtils.readItemStack(buf); if (stack.getItem() instanceof IModuleItem) { rocketComputer = stack; } stack = ByteBufUtils.readItemStack(buf); if (stack.getItem() instanceof IModuleItem) { rocketEngine = stack; } return this; }
From source file:com.builtbroken.icbm.content.rail.EntityMissileCart.java
@Override public void readSpawnData(ByteBuf additionalData) { super.readSpawnData(additionalData); setType(MissileCartTypes.values()[additionalData.readInt()]); if (additionalData.readBoolean()) { setCargo(ByteBufUtils.readItemStack(additionalData)); } else {//from ww w . j a v a 2 s . co m setCargo(null); } markBoundsInvalid(); }
From source file:com.builtbroken.mc.framework.access.global.gui.GuiAccessSystem.java
@Override public boolean read(ByteBuf buf, int id, EntityPlayer player, PacketType type) { //Read profile list if (id == 0) { int n = buf.readInt(); profileIDs = new String[n]; profileNames = new String[n]; for (int i = 0; i < n; i++) { profileNames[i] = ByteBufUtils.readUTF8String(buf); profileIDs[i] = ByteBufUtils.readUTF8String(buf); buf.readBoolean();/*from w ww.ja va 2 s. c o m*/ } if (currentProfile != null) { profileToLoad = currentProfile.getID(); } reloadProfileList(); return true; } //Read profile else if (id == 1) { if (currentProfile == null) { currentProfile = GlobalAccessSystem.createFromSave(null, ByteBufUtils.readTag(buf)); } else { currentProfile.load(ByteBufUtils.readTag(buf)); } reloadGroupList(); return true; } else if (id == 5) { errorMessage = ByteBufUtils.readUTF8String(buf); return true; } return false; }
From source file:com.builtbroken.mc.framework.access.global.packets.PacketAccessGui.java
@Override public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { super.decodeInto(ctx, buffer); id = buffer.readInt(); }
From source file:com.builtbroken.paw.content.battery.TileNodeBattery.java
@Override public void readDescPacket(ByteBuf buf) { super.readDescPacket(buf); getEnergyBuffer(ForgeDirection.UNKNOWN).setEnergyStored(buf.readInt()); int prev = textureIndex; textureIndex = (int) Math .floor(((float) buffer.getEnergyStored() / (float) buffer.getMaxBufferSize()) * 15); //TODO add a json data file to the texture file to get max number of states, potentially use animation file if (textureIndex != prev) { world().unwrap().markBlockRangeForRenderUpdate(xi(), yi(), zi(), xi(), yi(), zi()); }//from ww w .ja va2 s. c o m }
From source file:com.builtbroken.radio.content.message.TileMessage.java
@Override public boolean read(ByteBuf buf, int id, EntityPlayer player, PacketType type) { if (world().isRemote && id == 2) { chatLog.clear();// ww w .j a v a 2s. c o m int size = buf.readInt(); for (int i = 0; i < size; i++) { chatLog.add(ByteBufUtils.readUTF8String(buf)); } return true; } else if (!world().isRemote && id == 3) { sendChatMessage(player, ByteBufUtils.readUTF8String(buf)); return true; } return false; }
From source file:com.cloudera.livy.client.local.rpc.KryoMessageCodec.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() < 4) { return;/*from ww w .j a va2 s. c o m*/ } in.markReaderIndex(); int msgSize = in.readInt(); checkSize(msgSize); if (in.readableBytes() < msgSize) { // Incomplete message in buffer. in.resetReaderIndex(); return; } try { ByteBuffer nioBuffer = maybeDecrypt(in.nioBuffer(in.readerIndex(), msgSize)); Object msg = serializer.deserialize(nioBuffer); LOG.debug("Decoded message of type {} ({} bytes)", msg != null ? msg.getClass().getName() : msg, msgSize); out.add(msg); } finally { in.skipBytes(msgSize); } }
From source file:com.cloudhopper.smpp.transcoder.DefaultPduTranscoder.java
License:Apache License
protected Pdu doDecode(int commandLength, ByteBuf buffer) throws UnrecoverablePduException, RecoverablePduException { // skip the length field because we already parsed it buffer.skipBytes(SmppConstants.PDU_INT_LENGTH); // read the remaining portion of the PDU header int commandId = buffer.readInt(); int commandStatus = buffer.readInt(); int sequenceNumber = buffer.readInt(); // this is a major issue if the sequence number is invalid SequenceNumber.assertValid(sequenceNumber); Pdu pdu = null;// w w w.j a v a 2 s . co m // any command id with its 31st bit set to true is a response if (PduUtil.isRequestCommandId(commandId)) { if (commandId == SmppConstants.CMD_ID_ENQUIRE_LINK) { pdu = new EnquireLink(); } else if (commandId == SmppConstants.CMD_ID_DELIVER_SM) { pdu = new DeliverSm(); } else if (commandId == SmppConstants.CMD_ID_SUBMIT_SM) { pdu = new SubmitSm(); } else if (commandId == SmppConstants.CMD_ID_DATA_SM) { pdu = new DataSm(); } else if (commandId == SmppConstants.CMD_ID_CANCEL_SM) { pdu = new CancelSm(); } else if (commandId == SmppConstants.CMD_ID_QUERY_SM) { pdu = new QuerySm(); } else if (commandId == SmppConstants.CMD_ID_BIND_TRANSCEIVER) { pdu = new BindTransceiver(); } else if (commandId == SmppConstants.CMD_ID_BIND_TRANSMITTER) { pdu = new BindTransmitter(); } else if (commandId == SmppConstants.CMD_ID_BIND_RECEIVER) { pdu = new BindReceiver(); } else if (commandId == SmppConstants.CMD_ID_UNBIND) { pdu = new Unbind(); } else { pdu = new PartialPdu(commandId); } } else { if (commandId == SmppConstants.CMD_ID_SUBMIT_SM_RESP) { pdu = new SubmitSmResp(); } else if (commandId == SmppConstants.CMD_ID_DELIVER_SM_RESP) { pdu = new DeliverSmResp(); } else if (commandId == SmppConstants.CMD_ID_DATA_SM_RESP) { pdu = new DataSmResp(); } else if (commandId == SmppConstants.CMD_ID_CANCEL_SM_RESP) { pdu = new CancelSmResp(); } else if (commandId == SmppConstants.CMD_ID_QUERY_SM_RESP) { pdu = new QuerySmResp(); } else if (commandId == SmppConstants.CMD_ID_ENQUIRE_LINK_RESP) { pdu = new EnquireLinkResp(); } else if (commandId == SmppConstants.CMD_ID_BIND_TRANSCEIVER_RESP) { pdu = new BindTransceiverResp(); } else if (commandId == SmppConstants.CMD_ID_BIND_RECEIVER_RESP) { pdu = new BindReceiverResp(); } else if (commandId == SmppConstants.CMD_ID_BIND_TRANSMITTER_RESP) { pdu = new BindTransmitterResp(); } else if (commandId == SmppConstants.CMD_ID_UNBIND_RESP) { pdu = new UnbindResp(); } else if (commandId == SmppConstants.CMD_ID_GENERIC_NACK) { pdu = new GenericNack(); } else { pdu = new PartialPduResp(commandId); } } // set pdu header values pdu.setCommandLength(commandLength); pdu.setCommandStatus(commandStatus); pdu.setSequenceNumber(sequenceNumber); // check if we need to throw an exception if (pdu instanceof PartialPdu) { throw new UnknownCommandIdException(pdu, "Unsupported or unknown PDU request commandId [0x" + HexUtil.toHexString(commandId) + "]"); } else if (pdu instanceof PartialPduResp) { throw new UnknownCommandIdException(pdu, "Unsupported or unknown PDU response commandId [0x" + HexUtil.toHexString(commandId) + "]"); } // see if we can map the command status into a message if (pdu instanceof PduResponse) { PduResponse response = (PduResponse) pdu; response.setResultMessage(context.lookupResultMessage(commandStatus)); } try { // parse pdu body parameters (may throw exception) pdu.readBody(buffer); // parse pdu optional parameters (may throw exception) pdu.readOptionalParameters(buffer, context); } catch (RecoverablePduException e) { // check if we should add the partial pdu to the exception if (e.getPartialPdu() == null) { e.setPartialPdu(pdu); } // rethrow it throw e; } return pdu; }
From source file:com.couchbase.client.core.endpoint.dcp.DCPHandler.java
License:Apache License
/** * Handles incoming stream of DCP messages. *///from w w w.j a v a 2 s . c o m private void handleDCPRequest(final ChannelHandlerContext ctx, final FullBinaryMemcacheResponse msg) { DCPRequest request = null; int flags = 0; long bySeqno = 0; long revSeqno = 0; switch (msg.getOpcode()) { case OP_SNAPSHOT_MARKER: long startSequenceNumber = 0; long endSequenceNumber = 0; if (msg.getExtrasLength() > 0) { final ByteBuf extras = msg.getExtras(); startSequenceNumber = extras.readLong(); endSequenceNumber = extras.readLong(); flags = extras.readInt(); } request = new SnapshotMarkerMessage(msg.getTotalBodyLength(), msg.getStatus(), startSequenceNumber, endSequenceNumber, flags, connection.bucket()); break; case OP_MUTATION: int expiration = 0; int lockTime = 0; if (msg.getExtrasLength() > 0) { final ByteBuf extras = msg.getExtras(); bySeqno = extras.readLong(); revSeqno = extras.readLong(); flags = extras.readInt(); expiration = extras.readInt(); lockTime = extras.readInt(); } request = new MutationMessage(msg.getTotalBodyLength(), msg.getStatus(), new String(msg.getKey(), CHARSET), msg.content().retain(), expiration, bySeqno, revSeqno, flags, lockTime, msg.getCAS(), connection.bucket()); break; case OP_REMOVE: if (msg.getExtrasLength() > 0) { final ByteBuf extras = msg.getExtras(); bySeqno = extras.readLong(); revSeqno = extras.readLong(); } request = new RemoveMessage(msg.getTotalBodyLength(), msg.getStatus(), new String(msg.getKey(), CHARSET), msg.getCAS(), bySeqno, revSeqno, connection.bucket()); break; case OP_EXPIRATION: if (msg.getExtrasLength() > 0) { final ByteBuf extras = msg.getExtras(); bySeqno = extras.readLong(); revSeqno = extras.readLong(); } request = new ExpirationMessage(msg.getTotalBodyLength(), msg.getStatus(), new String(msg.getKey(), CHARSET), msg.getCAS(), bySeqno, revSeqno, connection.bucket()); break; case OP_STREAM_END: final ByteBuf extras = msg.getExtras(); StreamEndMessage.Reason reason = StreamEndMessage.Reason.valueOf(extras.readInt()); request = new StreamEndMessage(msg.getTotalBodyLength(), msg.getStatus(), reason, connection.bucket()); connection.streamClosed(request.partition(), reason); break; default: LOGGER.info("Unhandled DCP message: {}, {}", msg.getOpcode(), msg); } if (request != null) { connection.subject().onNext(request); } }