Java Code Examples for io.netty.buffer.ByteBuf#getLong()
The following examples show how to use
io.netty.buffer.ByteBuf#getLong() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DirectMemoryBuffer.java From pravega with Apache License 2.0 | 6 votes |
/** * Rolls back a partially executed call to {@link #write} that failed while being written to the buffer. This walks * back the chain of blocks that were written, marks them as free and re-chains them into the free block chain. This * method is a simpler version of {@link #deallocateBlocks} that does not attempt to merge two sorted lists and does * not require the root metadata to have been properly updated (since it likely wasn't). * @param lastWrittenBlockId The id of the last Block id that has been written and had its metadata updated. * @param nextFreeBlockId The id of the next free Block id after `lastWrittenBlockId`. Usually this is the id of * the block for which the write failed but for which we couldn't update the metadata yet. */ @GuardedBy("this") private void rollbackWrite(int lastWrittenBlockId, int nextFreeBlockId) { ByteBuf metadataBuf = getMetadataBlock(); int blockId = lastWrittenBlockId; while (blockId != CacheLayout.NO_BLOCK_ID) { // Get block metadata and fetch the predecessor address, before we reset it. int bufIndex = blockId * this.layout.blockMetadataSize(); long blockMetadata = metadataBuf.getLong(bufIndex); int predecessorAddress = this.layout.getPredecessorAddress(blockMetadata); // Reset the block metadata. blockMetadata = this.layout.setNextFreeBlockId(this.layout.emptyBlockMetadata(), nextFreeBlockId); metadataBuf.setLong(bufIndex, blockMetadata); nextFreeBlockId = blockId; this.usedBlockCount--; // Determine the previous block to rollback. blockId = this.layout.getBlockId(predecessorAddress); if (this.layout.getBufferId(predecessorAddress) != this.id) { break; } } }
Example 2
Source File: LengthFieldBasedFrameDecoder.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
/** * Decodes the specified region of the buffer into an unadjusted frame length. The default implementation is * capable of decoding the specified region into an unsigned 8/16/24/32/64 bit integer. Override this method to * decode the length field encoded differently. Note that this method must not modify the state of the specified * buffer (e.g. {@code readerIndex}, {@code writerIndex}, and the content of the buffer.) * * @throws DecoderException if failed to decode the specified region */ protected long getUnadjustedFrameLength(ByteBuf buf, int offset, int length, ByteOrder order) { buf = buf.order(order); long frameLength; switch (length) { case 1: frameLength = buf.getUnsignedByte(offset); break; case 2: frameLength = buf.getUnsignedShort(offset); break; case 3: frameLength = buf.getUnsignedMedium(offset); break; case 4: frameLength = buf.getUnsignedInt(offset); break; case 8: frameLength = buf.getLong(offset); break; default: throw new DecoderException( "unsupported lengthFieldLength: " + lengthFieldLength + " (expected: 1, 2, 3, 4, or 8)"); } return frameLength; }
Example 3
Source File: ByteBufUtils.java From graylog-plugin-netflow with Apache License 2.0 | 6 votes |
public static long getUnsignedInteger(final ByteBuf buf, final int offset, final int length) { switch (length) { case 1: return buf.getUnsignedByte(offset); case 2: return buf.getUnsignedShort(offset); case 3: return buf.getUnsignedMedium(offset); case 4: return buf.getUnsignedInt(offset); case 8: return buf.getLong(offset) & 0x00000000ffffffffL; default: return 0L; } }
Example 4
Source File: PduCodec.java From herddb with Apache License 2.0 | 5 votes |
public static long readTx(Pdu pdu) { ByteBuf buffer = pdu.buffer; return buffer.getLong(VERSION_SIZE + FLAGS_SIZE + TYPE_SIZE + MSGID_SIZE + ONE_BYTE); }
Example 5
Source File: PduCodec.java From herddb with Apache License 2.0 | 5 votes |
public static long readStatementId(Pdu pdu) { ByteBuf buffer = pdu.buffer; return buffer.getLong(VERSION_SIZE + FLAGS_SIZE + TYPE_SIZE + MSGID_SIZE + ONE_BYTE + ONE_LONG); }
Example 6
Source File: PduCodec.java From herddb with Apache License 2.0 | 5 votes |
public static long readScannerId(Pdu pdu) { ByteBuf buffer = pdu.buffer; return buffer.getLong(VERSION_SIZE + FLAGS_SIZE + TYPE_SIZE + MSGID_SIZE); }
Example 7
Source File: PduCodec.java From herddb with Apache License 2.0 | 5 votes |
public static long readScannerId(Pdu pdu) { ByteBuf buffer = pdu.buffer; return buffer.getLong(VERSION_SIZE + FLAGS_SIZE + TYPE_SIZE + MSGID_SIZE); }
Example 8
Source File: PduCodec.java From herddb with Apache License 2.0 | 5 votes |
public static long readTx(Pdu pdu) { ByteBuf buffer = pdu.buffer; return buffer.getLong(VERSION_SIZE + FLAGS_SIZE + TYPE_SIZE + MSGID_SIZE); }
Example 9
Source File: PduCodec.java From herddb with Apache License 2.0 | 5 votes |
public static long readScannerId(Pdu pdu) { ByteBuf buffer = pdu.buffer; return buffer.getLong(VERSION_SIZE + FLAGS_SIZE + TYPE_SIZE + MSGID_SIZE + ONE_LONG + ONE_LONG + ONE_INT + ONE_INT ); }
Example 10
Source File: PduCodec.java From herddb with Apache License 2.0 | 5 votes |
public static long readLedgerId(Pdu pdu) { ByteBuf buffer = pdu.buffer; return buffer.getLong(VERSION_SIZE + FLAGS_SIZE + TYPE_SIZE + MSGID_SIZE); }
Example 11
Source File: PduCodec.java From herddb with Apache License 2.0 | 5 votes |
public static long readTx(Pdu pdu) { ByteBuf buffer = pdu.buffer; return buffer.getLong(VERSION_SIZE + FLAGS_SIZE + TYPE_SIZE + MSGID_SIZE); }
Example 12
Source File: RSocketBrokerResponderHandler.java From alibaba-rsocket-broker with Apache License 2.0 | 5 votes |
@Nullable protected BinaryRoutingMetadata binaryRoutingMetadata(ByteBuf compositeByteBuf) { long typeAndService = compositeByteBuf.getLong(0); if ((typeAndService >> 56) == BINARY_ROUTING_MARK) { int metadataContentLen = (int) (typeAndService >> 32) & 0x00FFFFFF; return BinaryRoutingMetadata.from(compositeByteBuf.slice(4, metadataContentLen)); } return null; }
Example 13
Source File: PduCodec.java From herddb with Apache License 2.0 | 5 votes |
public static Pdu decodePdu(ByteBuf in) throws IOException { byte version = in.getByte(0); if (version == VERSION_3) { byte flags = in.getByte(1); byte type = in.getByte(2); long messageId = in.getLong(3); return Pdu.newPdu(in, type, flags, messageId); } throw new IOException("Cannot decode version " + version); }
Example 14
Source File: PduCodec.java From herddb with Apache License 2.0 | 5 votes |
public static long readStatementId(Pdu pdu) { ByteBuf buffer = pdu.buffer; return buffer.getLong(VERSION_SIZE + FLAGS_SIZE + TYPE_SIZE + MSGID_SIZE + ONE_BYTE + ONE_LONG); }
Example 15
Source File: PduCodec.java From herddb with Apache License 2.0 | 5 votes |
public static long readOffset(Pdu pdu) { ByteBuf buffer = pdu.buffer; return buffer.getLong(VERSION_SIZE + FLAGS_SIZE + TYPE_SIZE + MSGID_SIZE + ONE_LONG ); }
Example 16
Source File: HttpObjectDecoder.java From servicetalk with Apache License 2.0 | 5 votes |
static HttpProtocolVersion nettyBufferToHttpVersion(final ByteBuf buffer, final int start, final int length) { if (length != 8) { httpVersionError(buffer, start, length); } final long httpVersion = buffer.getLong(start); if ((httpVersion & HTTP_VERSION_MASK) != HTTP_VERSION_FORMAT) { httpVersionError(buffer, start, length); } return HttpProtocolVersion.of(1, toDecimal((int) httpVersion & 0xff)); }
Example 17
Source File: UpstreamForwardRSocket.java From alibaba-rsocket-broker with Apache License 2.0 | 5 votes |
@Nullable protected BinaryRoutingMetadata binaryRoutingMetadata(ByteBuf compositeByteBuf) { long typeAndService = compositeByteBuf.getLong(0); if ((typeAndService >> 56) == BINARY_ROUTING_MARK) { int metadataContentLen = (int) (typeAndService >> 32) & 0x00FFFFFF; return BinaryRoutingMetadata.from(compositeByteBuf.slice(4, metadataContentLen)); } return null; }
Example 18
Source File: NettyServerHandler.java From iot-dc3 with Apache License 2.0 | 4 votes |
@Override @SneakyThrows public void channelRead(ChannelHandlerContext context, Object msg) { ByteBuf byteBuf = (ByteBuf) msg; log.info("{}->{}", context.channel().remoteAddress(), ByteBufUtil.hexDump(byteBuf)); String deviceName = byteBuf.toString(0, 22, CharsetUtil.CHARSET_ISO_8859_1); Long deviceId = nettyServerHandler.driverContext.getDeviceIdByName(deviceName); String hexKey = ByteBufUtil.hexDump(byteBuf, 22, 1); List<PointValue> pointValues = new ArrayList<>(); Map<Long, Map<String, AttributeInfo>> pointInfoMap = nettyServerHandler.driverContext.getDevicePointInfoMap().get(deviceId); for (Long pointId : pointInfoMap.keySet()) { Point point = nettyServerHandler.driverContext.getDevicePoint(deviceId, pointId); Map<String, AttributeInfo> infoMap = pointInfoMap.get(pointId); int start = DriverUtils.value(infoMap.get("start").getType(), infoMap.get("start").getValue()); int end = DriverUtils.value(infoMap.get("end").getType(), infoMap.get("end").getValue()); if (infoMap.get("key").getValue().equals(hexKey)) { PointValue pointValue = null; switch (point.getName()) { case "海拔": float altitude = byteBuf.getFloat(start); pointValue = nettyServerHandler.driverService.convertValue(deviceId, pointId, String.valueOf(altitude)); break; case "速度": double speed = byteBuf.getDouble(start); pointValue = nettyServerHandler.driverService.convertValue(deviceId, pointId, String.valueOf(speed)); break; case "液位": long level = byteBuf.getLong(start); pointValue = nettyServerHandler.driverService.convertValue(deviceId, pointId, String.valueOf(level)); break; case "方向": int direction = byteBuf.getInt(start); pointValue = nettyServerHandler.driverService.convertValue(deviceId, pointId, String.valueOf(direction)); break; case "锁定": boolean lock = byteBuf.getBoolean(start); pointValue = nettyServerHandler.driverService.convertValue(deviceId, pointId, String.valueOf(lock)); break; case "经纬": String lalo = byteBuf.toString(start, end, CharsetUtil.CHARSET_ISO_8859_1).trim(); pointValue = nettyServerHandler.driverService.convertValue(deviceId, pointId, String.valueOf(lalo)); break; default: break; } if (null != pointValue) { pointValues.add(pointValue); } } } nettyServerHandler.driverService.pointValueSender(pointValues); }
Example 19
Source File: TagsMetadata.java From spring-cloud-rsocket with Apache License 2.0 | 4 votes |
protected static long decodeLong(ByteBuf byteBuf, AtomicInteger offset) { return byteBuf.getLong(offset.getAndAdd(8)); }
Example 20
Source File: CollectdParser.java From datacollector with Apache License 2.0 | 4 votes |
private long parseNumeric(int offset, ByteBuf buf) { // 8 bytes return buf.getLong(offset); }