List of usage examples for io.netty.buffer ByteBuf readInt
public abstract int readInt();
From source file:com.eightkdata.mongowp.server.decoder.QueryMessageDecoder.java
License:Open Source License
@Override public QueryMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage) throws MongoException { try {/*from ww w .ja v a 2 s . co m*/ MyBsonContext bsonContext = new MyBsonContext(buffer); int flags = buffer.readInt(); String fullCollectionName = stringReader.readCString(buffer, true); final int numberToSkip = buffer.readInt(); final int numberToReturn = buffer.readInt(); //TODO: improve the way database and cache are pooled QueryMessage.Builder queryBuilder = new Builder(requestBaseMessage, bsonContext, getDatabase(fullCollectionName).intern(), getCollection(fullCollectionName).intern(), getQueryOptions(flags)); analyzeDoc(buffer, queryBuilder); BsonDocument returnFieldsSelector = null; if (buffer.readableBytes() > 0) { returnFieldsSelector = docReader.readDocument(HEAP, buffer); } assert buffer.readableBytes() == 0; queryBuilder.setReturnFieldsSelector(returnFieldsSelector).setNumberToReturn(numberToReturn) .setNumberToSkip(numberToSkip); return queryBuilder.build(); } catch (BsonDocumentReaderException ex) { throw new InvalidBsonException(ex); } }
From source file:com.eightkdata.mongowp.server.decoder.UpdateMessageDecoder.java
License:Open Source License
@Override public UpdateMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage) throws InvalidNamespaceException, InvalidBsonException { try {//ww w . j ava 2 s . c om buffer.skipBytes(4); String fullCollectionName = stringReader.readCString(buffer, true); int flags = buffer.readInt(); BsonDocument selector = docReader.readDocument(HEAP, buffer); BsonDocument update = docReader.readDocument(HEAP, buffer); //TODO: improve the way database and cache are pooled return new UpdateMessage(requestBaseMessage, EmptyBsonContext.getInstance(), getDatabase(fullCollectionName).intern(), getCollection(fullCollectionName).intern(), selector, update, EnumInt32FlagsUtil.isActive(Flag.UPSERT, flags), EnumInt32FlagsUtil.isActive(Flag.MULTI_UPDATE, flags)); } catch (NettyBsonReaderException ex) { throw new InvalidBsonException(ex); } }
From source file:com.eightkdata.mongowp.server.wp.RequestMessageByteHandler.java
License:Open Source License
@Override protected void decodeLittleEndian(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> objects) throws Exception { if (byteBuf instanceof EmptyByteBuf) { //TODO: This is a workaround. Check how to prevent calling decode on channel inactive return;/*from ww w. j a va 2 s .com*/ } // Header final RequestBaseMessage requestBaseMessage = BaseMessageDecoder.decode(channelHandlerContext, byteBuf); byteBuf.skipBytes(Ints.BYTES); // Ignore responseTo field in header int requestOpCodeInt = byteBuf.readInt(); RequestOpCode requestOpCode = RequestOpCode.getByOpcode(requestOpCodeInt); if (null == requestOpCode) { LOGGER.warn(INVALID_OPCODE_MESSAGE + requestOpCodeInt); throw new IllegalOperationException(requestOpCodeInt); } // Body MessageDecoder<?> messageDecoder = decoderLocator.getByOpCode(requestOpCode); if (null == messageDecoder) { LOGGER.error(OPERATION_NOT_IMPLEMENTED + requestOpCode); throw new UnsupportedOperationException(OPERATION_NOT_IMPLEMENTED + requestOpCode); } objects.add(messageDecoder.decode(byteBuf, requestBaseMessage)); }
From source file:com.eightkdata.nettybson.mongodriver.MongoBSONDocument.java
License:Open Source License
/** * Generates an instance reading from the ByteBuf. Advances the readerIndex of the buffer until the end of the bson * @param buffer//from ww w.j ava2 s . c o m */ public MongoBSONDocument(ByteBuf buffer) { buffer.markReaderIndex(); int documentLength = buffer.readInt(); buffer.resetReaderIndex(); byte[] bsonBytes = new byte[documentLength]; buffer.readBytes(bsonBytes); BSONDecoder bsonDecoder = new BasicBSONDecoder(); bson = bsonDecoder.readObject(bsonBytes); }
From source file:com.farincorporated.frameutils.client.packet.FrameFieldPacket.java
@Override public void fromBytes(ByteBuf buf) { this.type = ByteBufUtils.readUTF8String(buf); this.x = buf.readInt(); this.y = buf.readInt(); this.z = buf.readInt(); }
From source file:com.feihong.newzxclient.tcp.IntLengthDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) { // Wait until the length prefix is available. if (in.readableBytes() < 4) { //String strError = String.format("Read length data error, in.readableBytes(): %d, length: %d", in.readableBytes(), 4); //writeLog(strError); return;/* w w w . j a va 2 s.c om*/ } in.markReaderIndex(); // Wait until the whole data is available. int dataLength = in.readInt(); if (in.readableBytes() < dataLength) { //String strError = String.format("Read length data error, in.readableBytes(): %d, length: %d", in.readableBytes(), dataLength + 4); //writeLog(strError); in.resetReaderIndex(); return; } // Convert the received data into a new BigInteger. byte[] decoded = new byte[dataLength]; in.readBytes(decoded); try { Msg.CommonMessage commonMessage = Msg.CommonMessage.parseFrom(decoded); out.add(commonMessage); } catch (InvalidProtocolBufferException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.fireball1725.firecore.common.network.messages.PacketButtonClick.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { this.buttonID = buf.readInt(); this.blockX = buf.readInt(); this.blockY = buf.readInt(); this.blockZ = buf.readInt(); this.playerUUID = UUID.fromString(ByteBufUtils.readUTF8String(buf)); }
From source file:com.fireball1725.firelib.guimaker.util.NetworkHelper.java
License:Open Source License
public static BlockPos readBlockPos(ByteBuf byteBuf) { return new BlockPos(byteBuf.readInt(), byteBuf.readInt(), byteBuf.readInt()); }
From source file:com.flowpowered.engine.network.codec.ChunkDataCodec.java
License:MIT License
@Override public ChunkDataMessage decode(ByteBuf buffer) throws IOException { final byte info = buffer.readByte(); final boolean unload = (info & ISUNLOAD) == ISUNLOAD; final int x = buffer.readInt(); final int y = buffer.readInt(); final int z = buffer.readInt(); if (unload) { return new ChunkDataMessage(x, y, z); } else {//from w ww .j a va 2s. c o m int uncompressedSize = INTIAL_DATA_SIZE; final byte[] uncompressedData = new byte[uncompressedSize]; final byte[] compressedData = new byte[buffer.readInt()]; buffer.readBytes(compressedData); Inflater inflater = new Inflater(); inflater.setInput(compressedData); try { inflater.inflate(uncompressedData); } catch (DataFormatException e) { throw new IOException("Error while reading chunk (" + x + "," + y + "," + z + ")!", e); } inflater.end(); final int[] blocks = new int[Chunk.BLOCKS.VOLUME]; int index = 0; for (int i = 0; i < blocks.length; ++i) { blocks[i] = uncompressedData[index++] | (uncompressedData[index++] << 8) | (uncompressedData[index++] << 16) | (uncompressedData[index++] << 24); } if (index != uncompressedData.length) { throw new IllegalStateException( "Incorrect parse size - actual:" + index + " expected: " + uncompressedData.length); } return new ChunkDataMessage(x, y, z, blocks); } }
From source file:com.flowpowered.engine.network.codec.InputSnapshotCodec.java
License:MIT License
@Override public InputSnapshotMessage decode(ByteBuf buf) throws IOException { List<KeyboardEvent> keyEvents = new LinkedList<>(); int amount = buf.readInt(); for (int i = 0; i < amount; i++) { keyEvents.add(new KeyboardEvent(buf.readByte(), buf.readBoolean())); }//w ww . jav a 2 s .c o m amount = buf.readInt(); List<MouseEvent> mouseEvents = new LinkedList<>(); for (int i = 0; i < amount; i++) { mouseEvents.add(new MouseEvent(buf.readInt(), buf.readInt(), buf.readInt(), buf.readInt(), buf.readInt(), buf.readInt(), buf.readBoolean())); } return new InputSnapshotMessage(buf.readFloat(), buf.readBoolean(), keyEvents, mouseEvents); }