List of usage examples for io.netty.buffer ByteBuf readInt
public abstract int readInt();
From source file:com.crowsofwar.avatar.common.network.packets.PacketSUseAbility.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { ability = BendingManager.getAbility(buf.readInt()); if (ability == null) { throw new NullPointerException("Server sent invalid ability over network: ID " + ability); }/*from w ww.j a v a 2s . com*/ raytrace = Raytrace.Result.fromBytes(buf); }
From source file:com.crowsofwar.avatar.common.network.packets.PacketSUseStatusControl.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { int id = buf.readInt(); statusControl = StatusControl.lookup(id); if (statusControl == null) { AvatarLog.warn(WarningType.POSSIBLE_HACKING, "Player trying to crash the server?? While sending UseStatusControl packet, sent invalid id " + id);// w w w .ja v a 2s. com return; // TODO Cancel packet processing } raytrace = Raytrace.Result.fromBytes(buf); }
From source file:com.crowsofwar.avatar.common.util.AvatarByteBufUtils.java
License:Open Source License
public static <T> List<T> readList(ByteBuf buf, Supplier<T> itemSupplier) { List<T> list = new ArrayList<>(); int size = buf.readInt(); for (int i = 0; i < size; i++) { list.add(itemSupplier.get());// ww w . j av a 2s . co m } return list; }
From source file:com.crowsofwar.avatar.common.util.AvBlockPos.java
License:Open Source License
public static AvBlockPos fromBytes(ByteBuf buf) { return new AvBlockPos(buf.readInt(), buf.readInt(), buf.readInt()); }
From source file:com.crowsofwar.gorecore.util.GoreCoreByteBufUtil.java
License:Open Source License
public static String readString(ByteBuf buf) { String res = ""; int length = buf.readInt(); for (int i = 0; i < length; i++) { res += buf.readChar();// w w w . j a v a 2 s. c om } return res; }
From source file:com.crowsofwar.gorecore.util.VectorI.java
License:Open Source License
/** * Creates a new vector from the packet information in the byte buffer. * /* w w w . j a v a2 s . c o m*/ * @param buf * Buffer to read from */ public static VectorI fromBytes(ByteBuf buf) { return new VectorI(buf.readInt(), buf.readInt(), buf.readInt()); }
From source file:com.datastax.driver.core.CBUtil.java
License:Apache License
public static String readLongString(ByteBuf cb) { try {/*from ww w. ja v a 2 s. c o m*/ int length = cb.readInt(); return readString(cb, length); } catch (IndexOutOfBoundsException e) { throw new DriverInternalError( "Not enough bytes to read an UTF8 serialized string preceded by it's 4 bytes length"); } }
From source file:com.datastax.driver.core.CBUtil.java
License:Apache License
public static ByteBuffer readValue(ByteBuf cb) { int length = cb.readInt(); if (length < 0) return null; ByteBuf slice = cb.readSlice(length); return ByteBuffer.wrap(readRawBytes(slice)); }
From source file:com.datastax.driver.core.CBUtil.java
License:Apache License
public static InetSocketAddress readInet(ByteBuf cb) { int addrSize = cb.readByte(); byte[] address = new byte[addrSize]; cb.readBytes(address);/*w ww. j a va 2 s .c o m*/ int port = cb.readInt(); try { return new InetSocketAddress(InetAddress.getByAddress(address), port); } catch (UnknownHostException e) { throw new DriverInternalError( String.format("Invalid IP address (%d.%d.%d.%d) while deserializing inet address", address[0], address[1], address[2], address[3])); } }
From source file:com.datastax.driver.core.Frame.java
License:Apache License
private static Frame create(ByteBuf fullFrame) { assert fullFrame.readableBytes() >= 1 : String.format("Frame too short (%d bytes)", fullFrame.readableBytes());/*from w w w. jav a2 s . c o m*/ int versionBytes = fullFrame.readByte(); // version first byte is the "direction" of the frame (request or response) ProtocolVersion version = ProtocolVersion.fromInt(versionBytes & 0x7F); int hdrLen = Header.lengthFor(version); assert fullFrame.readableBytes() >= (hdrLen - 1) : String.format("Frame too short (%d bytes)", fullFrame.readableBytes()); int flags = fullFrame.readByte(); int streamId = readStreamid(fullFrame, version); int opcode = fullFrame.readByte(); int length = fullFrame.readInt(); assert length == fullFrame.readableBytes(); Header header = new Header(version, flags, streamId, opcode); return new Frame(header, fullFrame); }