List of usage examples for io.netty.buffer ByteBuf skipBytes
public abstract ByteBuf skipBytes(int length);
From source file:com.eightkdata.mongowp.mongoserver.decoder.KillCursorsMessageDecoder.java
License:Open Source License
@Override public @Nonnegative KillCursorsMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage) throws InvalidMessageException { buffer.skipBytes(4); int numberOfCursors = buffer.readInt(); long[] cursorIds = new long[numberOfCursors]; for (int index = 0; index < numberOfCursors; index++) { cursorIds[index] = buffer.readLong(); }//from w w w. j a va 2 s.co m return new KillCursorsMessage(requestBaseMessage, numberOfCursors, cursorIds); }
From source file:com.eightkdata.mongowp.mongoserver.decoder.UpdateMessageDecoder.java
License:Open Source License
@Override public @Nonnegative UpdateMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage) throws InvalidMessageException { buffer.skipBytes(4); String fullCollectionName = ByteBufUtil.readCString(buffer); int flags = buffer.readInt(); BSONDocument selector = new MongoBSONDocument(buffer); BSONDocument update = new MongoBSONDocument(buffer); return new UpdateMessage(requestBaseMessage, flags, fullCollectionName, selector, update); }
From source file:com.eightkdata.mongowp.mongoserver.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 www .ja va 2 s. co m } // Header 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 InvalidMessageException(INVALID_OPCODE_MESSAGE + requestOpCodeInt); } // Body MessageDecoder<?> messageDecoder = MessageDecoderLocator.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.mongowp.server.decoder.DeleteMessageDecoder.java
License:Open Source License
@Override @Nonnegative//from ww w . j a v a2s.c om public DeleteMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage) throws InvalidNamespaceException, InvalidBsonException { try { MyBsonContext context = new MyBsonContext(buffer); buffer.skipBytes(4); String fullCollectionName = stringReader.readCString(buffer, true); int flags = buffer.readInt(); BsonDocument document = docReader.readDocument(HEAP, buffer); //TODO: improve the way database and cache are pooled String database = getDatabase(fullCollectionName).intern(); String collection = getCollection(fullCollectionName).intern(); return new DeleteMessage(requestBaseMessage, context, database, collection, document, EnumInt32FlagsUtil.isActive(Flag.SINGLE_REMOVE, flags)); } catch (NettyBsonReaderException ex) { throw new InvalidBsonException(ex); } }
From source file:com.eightkdata.mongowp.server.decoder.GetMoreMessageDecoder.java
License:Open Source License
@Override public GetMoreMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage) throws InvalidNamespaceException, InvalidBsonException { try {//w w w.j a v a2 s . com buffer.skipBytes(4); String fullCollectionName = stringReader.readCString(buffer, true); int numberToReturn = buffer.readInt(); long cursorId = buffer.readLong(); //TODO: improve the way database and cache are pooled return new GetMoreMessage(requestBaseMessage, getDatabase(fullCollectionName).intern(), getCollection(fullCollectionName).intern(), numberToReturn, cursorId); } catch (NettyBsonReaderException ex) { throw new InvalidBsonException(ex); } }
From source file:com.eightkdata.mongowp.server.decoder.KillCursorsMessageDecoder.java
License:Open Source License
@Override public KillCursorsMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage) throws InvalidNamespaceException { buffer.skipBytes(4); int numberOfCursors = buffer.readInt(); long[] cursorIds = new long[numberOfCursors]; for (int index = 0; index < numberOfCursors; index++) { cursorIds[index] = buffer.readLong(); }/*from w w w .jav a2 s . co m*/ return new KillCursorsMessage(requestBaseMessage, numberOfCursors, cursorIds); }
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 {/* w w w.j a v a 2s. 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;// www. j ava 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.facebook.nifty.core.NettyThriftDecoder.java
License:Apache License
protected TTransport getTransport(Channel channel, ByteBuf cb) { ThriftTransportType type = (cb.getUnsignedByte(0) < 0x80) ? ThriftTransportType.FRAMED : ThriftTransportType.UNFRAMED; if (type == ThriftTransportType.FRAMED) { cb.skipBytes(4); }//ww w.java 2 s .c o m return new TNiftyTransport(channel, new ThriftMessage(cb, type)); }
From source file:com.github.pgasync.impl.netty.ByteBufMessageDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() == 0) { return;/*from w ww . j a v a2 s.co m*/ } byte id = in.readByte(); int length = in.readInt(); Decoder<?> decoder = DECODERS.get(id); try { if (decoder != null) { ByteBuffer buffer = in.nioBuffer(); out.add(decoder.read(buffer)); in.skipBytes(buffer.position()); } else { in.skipBytes(length - 4); } } catch (Throwable t) { // broad catch as otherwise the exception is silently dropped ctx.fireExceptionCaught(t); } }