Java Code Examples for io.netty.buffer.ByteBuf#readLong()
The following examples show how to use
io.netty.buffer.ByteBuf#readLong() .
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: ReplierSupport.java From fastdfs-client with Apache License 2.0 | 6 votes |
private void readHead(ByteBuf in) { if (in.readableBytes() < FastdfsConstants.FDFS_HEAD_LEN) { return; } length = in.readLong(); byte cmd = in.readByte(); byte errno = in.readByte(); if (errno != 0) { throw new FastdfsException("Fastdfs responsed with an error, errno is " + errno); } if (cmd != RESP) { throw new FastdfsException("Expect response command code error : " + cmd); } long expectLength = expectLength(); if (expectLength >= 0 && length != expectLength) { throw new FastdfsException("Expect response length : " + expectLength + " , but reply length : " + length); } atHead = false; }
Example 2
Source File: UpdateRetryCodec.java From joyqueue with Apache License 2.0 | 6 votes |
@Override public Object decode(JoyQueueHeader header, ByteBuf buffer) throws Exception { if (buffer == null) { return null; } String topic = Serializer.readString(buffer); String app = Serializer.readString(buffer); byte updateType = buffer.readByte(); short count = buffer.readShort(); if (count < 0) { count = 0; } Long[] messages = new Long[count]; for (int i = 0; i < count; i++) { messages[i] = buffer.readLong(); } UpdateRetry updateRetryPayload = new UpdateRetry().topic(topic).app(app).updateType(updateType) .updateType(updateType).messages(messages); return updateRetryPayload; }
Example 3
Source File: IndexQueryResponseDecoder.java From joyqueue with Apache License 2.0 | 6 votes |
@Override public Object decode(final JoyQueueHeader header, final ByteBuf buffer) throws Exception { Map<String, Map<Integer, IndexMetadataAndError>> topicPartitionIndex = new HashedMap(); int topics = buffer.readInt(); for (int i = 0; i < topics; i++) { String topic = Serializer.readString(buffer, Serializer.SHORT_SIZE); int partitions = buffer.readInt(); Map<Integer, IndexMetadataAndError> partitionIndexs = new HashedMap(); for (int j = 0; j < partitions; j++) { int partition = buffer.readInt(); long index = buffer.readLong(); String metadata = Serializer.readString(buffer, Serializer.SHORT_SIZE); short error = buffer.readShort(); partitionIndexs.put(partition, new IndexMetadataAndError(index, metadata, error)); } topicPartitionIndex.put(topic, partitionIndexs); } return new ConsumeIndexQueryResponse(topicPartitionIndex); }
Example 4
Source File: ByteBufUtils.java From Cleanstone with MIT License | 6 votes |
public static Vector readVector(ByteBuf byteBuf, boolean legacy) { long val = byteBuf.readLong(); long x, y, z; if (legacy) { x = val >> 38; y = (val >> 26) & 0xFFF; z = val << 38 >> 38; } else { x = val >> 38; y = val & 0xFFF; z = (val << 26 >> 38); } return new Vector(x, y, z); }
Example 5
Source File: PacketProfile.java From The-5zig-Mod with GNU General Public License v3.0 | 6 votes |
@Override public void read(ByteBuf buffer) throws IOException { this.id = PacketBuffer.readVarIntFromBuffer(buffer); this.rank = PacketBuffer.readRank(buffer); this.firstConnectTime = buffer.readLong(); this.profileMessage = PacketBuffer.readString(buffer); int ordinal = PacketBuffer.readVarIntFromBuffer(buffer); if (ordinal < 0 || ordinal >= Friend.OnlineStatus.values().length) throw new IllegalArgumentException("Received Integer is out of enum range"); this.onlineStatus = Friend.OnlineStatus.values()[ordinal]; this.showServer = buffer.readBoolean(); this.showMessageRead = buffer.readBoolean(); this.showFriendRequests = buffer.readBoolean(); this.showCape = buffer.readBoolean(); this.showCountry = buffer.readBoolean(); this.displayColor = ChatColor.RESET; }
Example 6
Source File: PullRequestSerde.java From qmq with Apache License 2.0 | 6 votes |
public PullRequest read(final int version, final ByteBuf in) { final String prefix = PayloadHolderUtils.readString(in); final String group = PayloadHolderUtils.readString(in); final String consumerId = PayloadHolderUtils.readString(in); final int requestNum = in.readInt(); final long offset = in.readLong(); final long pullOffsetBegin = in.readLong(); final long pullOffsetLast = in.readLong(); final long timeout = in.readLong(); final byte broadcast = in.readByte(); final List<PullFilter> filters = readFilters(version, in); final PullRequest request = new PullRequest(); request.setSubject(prefix); request.setGroup(group); request.setConsumerId(consumerId); request.setRequestNum(requestNum); request.setOffset(offset); request.setPullOffsetBegin(pullOffsetBegin); request.setPullOffsetLast(pullOffsetLast); request.setTimeoutMillis(timeout); request.setBroadcast(broadcast != 0); request.setFilters(filters); return request; }
Example 7
Source File: ChunkSectonBlockData.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
public static ChunkSectonBlockData readFromStream(ByteBuf stream) { short nonAirBlockCount = stream.readShort(); byte bitsPerBlock = stream.readByte(); short[] palette = ChunkConstants.GLOBAL_PALETTE; if (bitsPerBlock != ChunkConstants.GLOBAL_PALETTE_BITS_PER_BLOCK) { palette = new short[VarNumberSerializer.readVarInt(stream)]; for (int i = 0; i < palette.length; i++) { palette[i] = (short) VarNumberSerializer.readVarInt(stream); } } long[] blockdata = new long[VarNumberSerializer.readVarInt(stream)]; for (int i = 0; i < blockdata.length; i++) { blockdata[i] = stream.readLong(); } return new ChunkSectonBlockData(nonAirBlockCount, palette, bitsPerBlock, blockdata); }
Example 8
Source File: DefaultLispMapReferral.java From onos with Apache License 2.0 | 5 votes |
@Override public LispMapReferral readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException, DeserializationException { if (byteBuf.readerIndex() != 0) { return null; } // let's skip the reserved field byteBuf.skipBytes(RESERVED_SKIP_LENGTH); // record count -> 8 bits byte recordCount = (byte) byteBuf.readUnsignedByte(); // nonce -> 64 bits long nonce = byteBuf.readLong(); List<LispReferralRecord> referralRecords = Lists.newArrayList(); for (int i = 0; i < recordCount; i++) { referralRecords.add(new ReferralRecordReader().readFrom(byteBuf)); } return new DefaultMapReferralBuilder() .withNonce(nonce) .withReferralRecords(referralRecords) .build(); }
Example 9
Source File: ZMTP10WireFormat.java From netty-zmtp with Apache License 2.0 | 5 votes |
/** * Read a ZMTP/1.0 frame length. */ static long readLength(final ByteBuf in) { if (in.readableBytes() < 1) { return -1; } long size = in.readByte() & 0xFF; if (size == 0xFF) { if (in.readableBytes() < 8) { return -1; } size = in.readLong(); } return size; }
Example 10
Source File: TrafficShapingHandlerTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { long lastTimestamp = 0; loggerClient.debug("Step: " + step + " Read: " + in.readableBytes() / 8 + " blocks"); while (in.isReadable()) { lastTimestamp = in.readLong(); multipleMessage[step]--; } if (multipleMessage[step] > 0) { // still some message to get return; } long minimalWait = minimalWaitBetween != null? minimalWaitBetween[step] : 0; int ar = 0; if (autoRead != null) { if (step > 0 && autoRead[step - 1] != 0) { ar = autoRead[step - 1]; } } loggerClient.info("Step: " + step + " Interval: " + (lastTimestamp - currentLastTime) + " compareTo " + minimalWait + " (" + ar + ')'); assertTrue("The interval of time is incorrect:" + (lastTimestamp - currentLastTime) + " not> " + minimalWait, lastTimestamp - currentLastTime >= minimalWait); currentLastTime = lastTimestamp; step++; if (multipleMessage.length > step) { int nb = multipleMessage[step]; for (int i = 0; i < nb; i++) { channel.write(channel.alloc().buffer().writeBytes(data)); } channel.flush(); } else { promise.setSuccess(true); } }
Example 11
Source File: FailoverLogResponse.java From java-dcp-client with Apache License 2.0 | 5 votes |
public FailoverLogResponse(final ByteBuf response) { final ByteBuf content = MessageUtil.getContent(response); final int numEntries = content.readableBytes() / 16; final List<FailoverLogEntry> entries = new ArrayList<>(numEntries); for (int i = 0; i < numEntries; i++) { final long vbuuid = content.readLong(); final long seqno = content.readLong(); entries.add(new FailoverLogEntry(seqno, vbuuid)); } this.logEntries = Collections.unmodifiableList(entries); }
Example 12
Source File: PacketNewMessages.java From The-5zig-Mod with GNU General Public License v3.0 | 5 votes |
@Override public void read(ByteBuf buffer) throws IOException { int size = PacketBuffer.readVarIntFromBuffer(buffer); for(int i = 0; i < size; i++) { UUID uuid = PacketBuffer.readUUID(buffer); String name = PacketBuffer.readString(buffer); String text = PacketBuffer.readString(buffer); long time = buffer.readLong(); messages.add(new Message(time, name, uuid, text)); } }
Example 13
Source File: PullService.java From qmq with Apache License 2.0 | 5 votes |
private List<BaseMessage> deserializeBaseMessage(ByteBuf input) { if (input.readableBytes() == 0) return Collections.emptyList(); List<BaseMessage> result = Lists.newArrayList(); long pullLogOffset = input.readLong(); //ignore consumer offset input.readLong(); while (input.isReadable()) { BaseMessage message = new BaseMessage(); byte flag = input.readByte(); input.skipBytes(8 + 8); String subject = PayloadHolderUtils.readString(input); String messageId = PayloadHolderUtils.readString(input); readTags(input, message, flag); int bodyLen = input.readInt(); ByteBuf body = input.readSlice(bodyLen); HashMap<String, Object> attrs = deserializeMapWrapper(subject, messageId, body); message.setMessageId(messageId); message.setSubject(subject); message.setAttrs(attrs); message.setProperty(BaseMessage.keys.qmq_pullOffset, pullLogOffset); result.add(message); pullLogOffset++; } return result; }
Example 14
Source File: PacketBuffer.java From The-5zig-Mod with GNU General Public License v3.0 | 5 votes |
public static ArrayList<Rank> readRank(ByteBuf byteBuf) { long bits = byteBuf.readLong(); ArrayList<Rank> ranks = new ArrayList<>(); for(Rank r : Rank.values()) { r.addIfSet(bits, ranks); } return ranks; }
Example 15
Source File: Http2ClientResponseHandler.java From ambry with Apache License 2.0 | 5 votes |
@Override protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) { ByteBuf dup = msg.content().retainedDuplicate(); // Consume length dup.readLong(); RequestInfo requestInfo = ctx.channel().attr(Http2NetworkClient.REQUEST_INFO).getAndSet(null); http2ClientMetrics.http2StreamFirstToAllFrameReadyTime.update( System.currentTimeMillis() - requestInfo.getStreamHeaderFrameReceiveTime()); ResponseInfo responseInfo = new ResponseInfo(requestInfo, null, dup); responseInfoQueue.put(responseInfo); releaseAndCloseStreamChannel(ctx.channel()); }
Example 16
Source File: CollectionFlushed.java From java-dcp-client with Apache License 2.0 | 5 votes |
public CollectionFlushed(int vbucket, long seqno, int version, ByteBuf buffer) { super(Type.COLLECTION_FLUSHED, vbucket, seqno, version); ByteBuf value = MessageUtil.getContent(buffer); newManifestId = value.readLong(); scopeId = value.readUnsignedInt(); collectionId = value.readUnsignedInt(); }
Example 17
Source File: LongSerializer.java From rpc-benchmark with Apache License 2.0 | 4 votes |
@Override public Long read(ByteBuf byteBuf) { return byteBuf.readLong(); }
Example 18
Source File: DefaultLispMapRequest.java From onos with Apache License 2.0 | 4 votes |
@Override public LispMapRequest readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { if (byteBuf.readerIndex() != 0) { return null; } byte typeWithFlags = byteBuf.readByte(); // authoritative -> 1 bit boolean authoritative = ByteOperator.getBit(typeWithFlags, AUTHORITATIVE_INDEX); // mapDataPresent -> 1 bit boolean mapDataPresent = ByteOperator.getBit(typeWithFlags, MAP_DATA_PRESENT_INDEX); // probe -> 1 bit boolean probe = ByteOperator.getBit(typeWithFlags, PROBE_INDEX); // smr -> 1 bit boolean smr = ByteOperator.getBit(typeWithFlags, SMR_INDEX); byte reservedWithFlags = byteBuf.readByte(); // pitr -> 1 bit boolean pitr = ByteOperator.getBit(reservedWithFlags, PITR_INDEX); // smrInvoked -> 1 bit boolean smrInvoked = ByteOperator.getBit(reservedWithFlags, SMR_INVOKED_INDEX); // let's skip reserved field, only obtains ITR counter value // assume that first 3 bits are all set as 0, // remain 5 bits represent Itr Rloc Counter (IRC) int irc = byteBuf.readUnsignedByte(); // record count -> 8 bits int recordCount = byteBuf.readUnsignedByte(); // nonce -> 64 bits long nonce = byteBuf.readLong(); LispAfiAddress sourceEid = new AfiAddressReader().readFrom(byteBuf); // deserialize a collection of RLOC addresses List<LispAfiAddress> itrRlocs = Lists.newArrayList(); for (int i = 0; i < irc + 1; i++) { itrRlocs.add(new AfiAddressReader().readFrom(byteBuf)); } // deserialize a collection of EID records List<LispEidRecord> eidRecords = Lists.newArrayList(); for (int i = 0; i < recordCount; i++) { eidRecords.add(new EidRecordReader().readFrom(byteBuf)); } // reply record -> 32 bits int replyRecord = 0; // only obtains the reply record when map data present bit is set if (mapDataPresent) { replyRecord = byteBuf.readInt(); } return new DefaultRequestBuilder() .withIsAuthoritative(authoritative) .withIsMapDataPresent(mapDataPresent) .withIsProbe(probe) .withIsSmr(smr) .withIsPitr(pitr) .withIsSmrInvoked(smrInvoked) .withNonce(nonce) .withSourceEid(sourceEid) .withEidRecords(eidRecords) .withItrRlocs(itrRlocs) .withReplyRecord(replyRecord) .build(); }
Example 19
Source File: JoinGame.java From Velocity with MIT License | 4 votes |
@Override public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { this.entityId = buf.readInt(); this.gamemode = buf.readByte(); String dimensionIdentifier = null; String levelName = null; if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { this.previousGamemode = buf.readByte(); ImmutableSet<String> levelNames = ImmutableSet.copyOf(ProtocolUtils.readStringArray(buf)); ImmutableSet<DimensionData> readData = DimensionRegistry.fromGameData(ProtocolUtils.readCompoundTag(buf)); this.dimensionRegistry = new DimensionRegistry(readData, levelNames); dimensionIdentifier = ProtocolUtils.readString(buf); levelName = ProtocolUtils.readString(buf); } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) { this.dimension = buf.readInt(); } else { this.dimension = buf.readByte(); } if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) { this.difficulty = buf.readUnsignedByte(); } if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) { this.partialHashedSeed = buf.readLong(); } this.maxPlayers = buf.readUnsignedByte(); if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) { this.levelType = ProtocolUtils.readString(buf, 16); } if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) { this.viewDistance = ProtocolUtils.readVarInt(buf); } this.reducedDebugInfo = buf.readBoolean(); if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) { this.showRespawnScreen = buf.readBoolean(); } if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { boolean isDebug = buf.readBoolean(); boolean isFlat = buf.readBoolean(); this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug); } }
Example 20
Source File: ZclDataUtil.java From arcusplatform with Apache License 2.0 | 4 votes |
private static Object readBit64(ByteBuf input, boolean decode, boolean signed) throws IOException { if (decode) return decode(input.readLong(), signed); return input.readLong(); }