List of usage examples for io.netty.buffer ByteBuf readInt
public abstract int readInt();
From source file:com.dinstone.jrpc.transport.netty4.TransportProtocolDecoder.java
License:Apache License
private byte[] readFrame(ByteBuf in) { if (in.readableBytes() > 4) { in.markReaderIndex();// w w w .j av a 2 s .co m int len = in.readInt(); if (len > maxObjectSize) { throw new IllegalStateException( "The encoded object is too big: " + len + " (> " + maxObjectSize + ")"); } else if (len < 1) { throw new IllegalStateException("The encoded object is too small: " + len + " (< 1)"); } if (in.readableBytes() < len) { in.resetReaderIndex(); return null; } byte[] rpcBytes = new byte[len]; in.readBytes(rpcBytes); return rpcBytes; } return null; }
From source file:com.dinstone.rpc.netty.RpcProtocolDecoder.java
License:Apache License
private byte[] readFrame(ByteBuf in) { int remaining = in.readableBytes(); if (remaining < 4) { return null; }// ww w .j a va 2s . c o m int objectSize = in.getInt(0); if (objectSize > maxObjectSize) { throw new IllegalArgumentException( "The encoded object is too big: " + objectSize + " (> " + maxObjectSize + ')'); } if (remaining - 4 >= objectSize) { objectSize = in.readInt(); // RPC object size byte[] rpcBytes = new byte[objectSize]; in.readBytes(rpcBytes); return rpcBytes; } return null; }
From source file:com.doctor.netty5.example.factorial_algorithm.BigIntegerDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { // ? ?F + + -> 1 + 4 + ?? // ??/// ww w . j av a 2 s.c o m if (in.readableBytes() < 5) { return; // F + } in.markReaderIndex(); short magicNumber = in.readUnsignedByte();// ?F if (magicNumber != 'F') { in.resetReaderIndex(); throw new RuntimeException("magicNumber must be 'F' "); } // ??? int dataLength = in.readInt(); if (in.readableBytes() < dataLength) { in.resetReaderIndex(); return; } byte[] data = new byte[dataLength]; in.readBytes(data); out.add(new BigInteger(data)); }
From source file:com.dwarf.netty.guide.factorial.BigIntegerDecoder.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() < 5) { return;/* w w w.j av a 2 s . c om*/ } in.markReaderIndex(); // Check the magic number. int magicNumber = in.readUnsignedByte(); if (magicNumber != 'F') { in.resetReaderIndex(); throw new CorruptedFrameException("Invalid magic number: " + magicNumber); } // Wait until the whole data is available. int dataLength = in.readInt(); if (in.readableBytes() < dataLength) { in.resetReaderIndex(); return; } // Convert the received data into a new BigInteger. byte[] decoded = new byte[dataLength]; in.readBytes(decoded); out.add(new BigInteger(decoded)); }
From source file:com.eagle.adventurersalchemy.tile.TileEntityAlchemicalFire.java
License:Open Source License
@Override public void readFromByteBuff(ByteBuf buf) { fireColor = buf.readInt(); }
From source file:com.eagle.resonantreflux.networking.MessageChamber.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { x = buf.readInt(); y = buf.readInt();//w w w. j av a 2 s . c o m z = buf.readInt(); progress = buf.readInt(); multiplier = buf.readInt(); multiplierDuration = buf.readInt(); powerStored = buf.readInt(); powerMax = buf.readInt(); }
From source file:com.eightkdata.mongowp.bson.netty.DefaultNettyBsonLowLevelReader.java
License:Open Source License
@Override BsonArray readArray(@Loose @ModifiesIndexes ByteBuf byteBuf) throws NettyBsonReaderException { int length = byteBuf.readInt(); int significantLenght = length - 4 - 1; ByteBuf significantSlice = byteBuf.readSlice(significantLenght); byte b = byteBuf.readByte(); assert b == 0x00; ArrayList<BsonValue<?>> list = new ArrayList<>(); while (significantSlice.readableBytes() > 0) { list.add(readArrayEntry(significantSlice)); }/* ww w .j a va 2s . co m*/ return new ListBsonArray(list); }
From source file:com.eightkdata.mongowp.bson.netty.DefaultNettyBsonLowLevelReader.java
License:Open Source License
@Override BsonBinary readBinary(@Loose @ModifiesIndexes ByteBuf byteBuf) { int length = byteBuf.readInt(); byte subtype = byteBuf.readByte(); byte[] content = new byte[length]; byteBuf.readBytes(content);/* w w w . j ava2 s. c o m*/ return new ByteArrayBsonBinary(ParsingTools.getBinarySubtype(subtype), subtype, content); }
From source file:com.eightkdata.mongowp.bson.netty.DefaultNettyBsonLowLevelReader.java
License:Open Source License
@Override BsonDocument readDocument(@Loose @ModifiesIndexes ByteBuf byteBuf) throws NettyBsonReaderException { int length = byteBuf.readInt(); int significantLenght = length - 4 - 1; ByteBuf significantSlice = byteBuf.readSlice(significantLenght); byte b = byteBuf.readByte(); assert b == 0x00; LinkedHashMap<String, BsonValue<?>> values = new LinkedHashMap<>(); while (significantSlice.readableBytes() > 0) { Entry<?> entry = readDocumentEntry(significantSlice); values.put(entry.getKey(), entry.getValue()); }// w ww .java 2 s .c om return new MapBasedBsonDocument(values); }
From source file:com.eightkdata.mongowp.bson.netty.DefaultNettyBsonLowLevelReader.java
License:Open Source License
@Override BsonInt32 readInt32(@Loose @ModifiesIndexes ByteBuf byteBuf) { return PrimitiveBsonInt32.newInstance(byteBuf.readInt()); }