List of usage examples for io.netty.buffer ByteBuf readInt
public abstract int readInt();
From source file:cn.academy.energy.msg.matrix.MsgInitMatrix.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { x = buf.readInt(); y = buf.readInt();//ww w.j av a2s .com z = buf.readInt(); channel = ByteBufUtils.readUTF8String(buf); pwd = ByteBufUtils.readUTF8String(buf); }
From source file:cn.academy.energy.msg.MsgEnergyHeartbeat.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { x = buf.readInt(); y = buf.readInt();// w ww . j a v a 2s .co m z = buf.readInt(); energy = buf.readFloat(); loaded = buf.readBoolean(); }
From source file:cn.academy.energy.msg.node.MsgInitNode.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { x = buf.readInt(); y = buf.readInt();// ww w . j av a 2 s . c o m z = buf.readInt(); ssid = ByteBufUtils.readUTF8String(buf); pwd = ByteBufUtils.readUTF8String(buf); }
From source file:cn.ifengkou.hestia.serialize.MessageDecoder.java
License:Apache License
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) { if (in.readableBytes() < MessageDecoder.MESSAGE_LENGTH) { return;/*from w ww .j a va2 s . c o m*/ } in.markReaderIndex(); int messageLength = in.readInt(); if (messageLength < 0) { ctx.close(); } if (in.readableBytes() < messageLength) { in.resetReaderIndex(); return; } else { byte[] messageBody = new byte[messageLength]; in.readBytes(messageBody); try { Object obj = messageCodecUtil.decode(messageBody); out.add(obj); } catch (IOException ex) { LOGGER.error("messageCodeUtil decode failed!", ex); } } }
From source file:cn.lambdacraft.mob.network.MsgSentrySync.java
License:Open Source License
@Override public void fromBytes(ByteBuf stream) { xCoord = stream.readInt(); yCoord = stream.readInt();/*from w w w . jav a2 s.c o m*/ zCoord = stream.readInt(); isValid = stream.readBoolean(); if (isValid) { linkX = stream.readInt(); linkY = stream.readInt(); linkZ = stream.readInt(); } }
From source file:cn.lambdalib.multiblock.MsgBlockMulti.java
License:MIT License
@Override public void fromBytes(ByteBuf buf) { x = buf.readInt(); y = buf.readInt();//from ww w. j a v a 2s . co m z = buf.readInt(); dir = ForgeDirection.values()[buf.readByte()]; s = buf.readByte(); }
From source file:cn.liutils.api.player.state.StateBase.java
License:Open Source License
public final void fromBytes(ByteBuf buf) { tick = buf.readInt(); readBytes(buf); }
From source file:com.almuradev.guide.client.network.play.C00PageInformation.java
License:MIT License
@Override public void fromBytes(ByteBuf buf) { identifier = ByteBufUtils.readUTF8String(buf); index = buf.readInt(); title = ByteBufUtils.readUTF8String(buf); contents = ByteBufUtils.readUTF8String(buf); }
From source file:com.almuradev.guide.server.network.play.S00PageInformation.java
License:MIT License
@Override public void fromBytes(ByteBuf buf) { identifier = ByteBufUtils.readUTF8String(buf); index = buf.readInt(); title = ByteBufUtils.readUTF8String(buf); created = new Date(buf.readLong()); author = ByteBufUtils.readUTF8String(buf); lastModified = new Date(buf.readLong()); lastContributor = ByteBufUtils.readUTF8String(buf); contents = ByteBufUtils.readUTF8String(buf); }
From source file:com.antsdb.saltedfish.server.mysql.ReplicationPacketDecoder.java
License:Open Source License
@SuppressWarnings("unused") private ReplicationPacket readPacket(ByteBuf in, int size) { // packet sequence number for multiple packets // byte packetSequence = in.readByte(); byte seqId = in.readByte(); // handshake/*from w ww . ja v a 2s . c om*/ ReplicationPacket packet = null; // using state to decide how to handle connecting messages. if (state == StateIndicator.INITIAL_STATE) { packet = new StateIndicator(StateIndicator.INITIAL_STATE); packet.packetLength = size; packet.packetId = seqId; packet.read(this.handler, in); state = StateIndicator.RESPONSED_STATE; } else if (state == StateIndicator.RESPONSED_STATE) { byte header = in.readByte(); if (header == 0) { packet = new StateIndicator(StateIndicator.HANDSHAKEN_STATE); state = StateIndicator.HANDSHAKEN_STATE; } else { packet = new StateIndicator(StateIndicator.HANDSHAKE_FAIL_STATE); state = StateIndicator.HANDSHAKE_FAIL_STATE; } char[] bytes = new char[size]; for (int i = 0; i < size; i++) { int ch = in.getByte(i); bytes[i] = (char) ch; } packet.packetId = seqId; packet.packetLength = size; packet.read(this.handler, in); } else if (state == StateIndicator.HANDSHAKEN_STATE) { // expecting response for registered slave byte header = in.readByte(); if (header == 0) { packet = new StateIndicator(StateIndicator.REGISTERED_STATE); state = StateIndicator.REGISTERED_STATE; } else { packet = new StateIndicator(StateIndicator.REGISTER_FAIL_STATE); state = StateIndicator.REGISTER_FAIL_STATE; } packet.packetId = seqId; packet.packetLength = size; packet.read(this.handler, in); } else { // binlog stream started with 00 ok-byte byte okByte = in.readByte(); if (okByte == 0) { // read event header // timestamp 4 bytes int timeStamp = in.readInt(); // event type byte eventType = in.readByte(); // server id, 4 bytes int serverId = (int) BufferUtils.readLong(in); // event length, 4 bytes long eventLength = BufferUtils.readLong(in); // next position, 4 bytes long nextPosition = BufferUtils.readLong(in); // flags int flags = in.readShort(); // events switch (eventType) { case ReplicationPacket.ROTATE_EVENT: packet = new RotatePacket(eventType, eventLength, nextPosition); break; case ReplicationPacket.TABLE_MAP_EVENT: packet = new TableMapPacket(eventType, eventLength, nextPosition); break; case ReplicationPacket.WRITE_ROWS_EVENT: case ReplicationPacket.UPDATE_ROWS_EVENT: case ReplicationPacket.DELETE_ROWS_EVENT: packet = new RowsEventV2Packet(eventType, eventLength, nextPosition); break; case ReplicationPacket.STOP_EVENT: packet = new StopPacket(eventType, eventLength, nextPosition); break; case ReplicationPacket.XID_EVENT: packet = new XIDPacket(eventType, eventLength, nextPosition); break; case ReplicationPacket.QUERY_EVENT: case ReplicationPacket.FORMAT_DESCRIPTION_EVENT: case ReplicationPacket.START_EVENT_V3: // use GenericPacket to ignore unsupported events for now packet = new GenericPacket(eventType, eventLength, nextPosition); break; default: _log.error("unknown event: " + eventType); throw new CodingError("unknown event: " + eventType); } if (packet != null) { packet.packetId = seqId; packet.packetLength = size; packet.read(this.handler, in); } } else { ByteBuf pkt = (ByteBuf) in; ByteBuffer bbuf = pkt.nioBuffer(); int i = bbuf.remaining(); byte[] bytes = new byte[i]; pkt.readBytes(bytes); String dump = '\n' + UberUtil.hexDump(bytes); _log.error("unknown packet: " + dump); throw new CodingError("unknown packet"); } } return packet; }