Refine search
private void readUnknownFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener) throws Http2Exception { payload = payload.readSlice(payload.readableBytes()); listener.onUnknownFrame(ctx, frameType, streamId, flags, payload); }
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf buf = innerCodec.getValueEncoder().encode(in); ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { int chunksAmount = (int)Math.ceil(buf.readableBytes() / (double)Short.MAX_VALUE); for (int i = 1; i <= chunksAmount; i++) { int chunkSize = Math.min(Short.MAX_VALUE, buf.readableBytes()); ByteBuf chunk = buf.readSlice(chunkSize); int lenIndex = out.writerIndex(); out.writeInt(0); snappyEncoder.get().encode(chunk, out, chunk.readableBytes()); int compressedDataLength = out.writerIndex() - 4 - lenIndex; out.setInt(lenIndex, compressedDataLength); } return out; } finally { buf.release(); snappyEncoder.get().reset(); } } };
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf buf = innerCodec.getValueEncoder().encode(in); ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { int chunksAmount = (int)Math.ceil(buf.readableBytes() / (double)Short.MAX_VALUE); for (int i = 1; i <= chunksAmount; i++) { int chunkSize = Math.min(Short.MAX_VALUE, buf.readableBytes()); ByteBuf chunk = buf.readSlice(chunkSize); int lenIndex = out.writerIndex(); out.writeInt(0); snappyEncoder.get().encode(chunk, out, chunk.readableBytes()); int compressedDataLength = out.writerIndex() - 4 - lenIndex; out.setInt(lenIndex, compressedDataLength); } return out; } finally { buf.release(); snappyEncoder.get().reset(); } } };
int dataLength = in.readableBytes(); if (dataLength > MIN_COMPRESSIBLE_LENGTH) { for (;;) { final int lengthIdx = out.writerIndex() + 1; if (dataLength < MIN_COMPRESSIBLE_LENGTH) { ByteBuf slice = in.readSlice(dataLength); writeUnencodedChunk(slice, out, dataLength); break; ByteBuf slice = in.readSlice(Short.MAX_VALUE); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, Short.MAX_VALUE); dataLength -= Short.MAX_VALUE; } else { ByteBuf slice = in.readSlice(dataLength); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, dataLength);
private boolean decodeBulkStringContent(ByteBuf in, List<Object> out) throws Exception { final int readableBytes = in.readableBytes(); if (readableBytes == 0 || remainingBulkLength == 0 && readableBytes < RedisConstants.EOL_LENGTH) { return false; } // if this is last frame. if (readableBytes >= remainingBulkLength + RedisConstants.EOL_LENGTH) { ByteBuf content = in.readSlice(remainingBulkLength); readEndOfLine(in); // Only call retain after readEndOfLine(...) as the method may throw an exception. out.add(new DefaultLastBulkStringRedisContent(content.retain())); resetDecoder(); return true; } // chunked write. int toRead = Math.min(remainingBulkLength, readableBytes); remainingBulkLength -= toRead; out.add(new DefaultBulkStringRedisContent(in.readSlice(toRead).retain())); return true; }
private static void readGoAwayFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener) throws Http2Exception { int lastStreamId = readUnsignedInt(payload); long errorCode = payload.readUnsignedInt(); ByteBuf debugData = payload.readSlice(payload.readableBytes()); listener.onGoAwayRead(ctx, lastStreamId, errorCode, debugData); }
int dataLength = in.readableBytes(); if (dataLength > MIN_COMPRESSIBLE_LENGTH) { for (;;) { final int lengthIdx = out.writerIndex() + 1; if (dataLength < MIN_COMPRESSIBLE_LENGTH) { ByteBuf slice = in.readSlice(dataLength); writeUnencodedChunk(slice, out, dataLength); break; ByteBuf slice = in.readSlice(Short.MAX_VALUE); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, Short.MAX_VALUE); dataLength -= Short.MAX_VALUE; } else { ByteBuf slice = in.readSlice(dataLength); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, dataLength);
incompleteBuffer.ensureWritable(in.readableBytes()); incompleteBuffer.writeBytes(in); } else { ByteBuf lineBuf = in.readSlice(lastReadIndex - startIndex); String line; if (null != incompleteBuffer) {
private void readDataFrame(ChannelHandlerContext ctx, ByteBuf payload, Http2FrameListener listener) throws Http2Exception { int padding = readPadding(payload); verifyPadding(padding); // Determine how much data there is to read by removing the trailing // padding. int dataLength = lengthWithoutTrailingPadding(payload.readableBytes(), padding); ByteBuf data = payload.readSlice(dataLength); listener.onDataRead(ctx, streamId, data, padding, flags.endOfStream()); payload.skipBytes(payload.readableBytes()); }
return null; return buffer.readSlice(length); } else { final int length = buffer.readableBytes(); if (length > v2MaxHeaderSize) { discardedBytes = length; discarding = false; } else { discardedBytes = buffer.readableBytes(); buffer.skipBytes(discardedBytes);
private void readContinuationFrame(ByteBuf payload, Http2FrameListener listener) throws Http2Exception { // Process the initial fragment, invoking the listener's callback if end of headers. final ByteBuf continuationFragment = payload.readSlice(payload.readableBytes()); headersContinuation.processFragment(flags.endOfHeaders(), continuationFragment, listener); resetHeadersContinuationIfEnd(flags.endOfHeaders()); }
private RawMessageExtend doDeserializeRawMessagesExtend(ByteBuf body) { body.markReaderIndex(); int headerStart = body.readerIndex(); long bodyCrc = body.readLong(); MessageHeader header = deserializeMessageHeader(body); header.setBodyCrc(bodyCrc); int bodyLen = body.readInt(); int headerLen = body.readerIndex() - headerStart; int totalLen = headerLen + bodyLen; body.resetReaderIndex(); ByteBuf messageBuf = body.readSlice(totalLen); // client config error,prefer to send after ten second long scheduleTime = System.currentTimeMillis() + 10000; if (Flags.isDelay(header.getFlag())) { scheduleTime = header.getExpireTime(); } return new RawMessageExtend(header, messageBuf, messageBuf.readableBytes(), scheduleTime); } }
return null; ByteBuf frame = buffer.readSlice(length); buffer.skipBytes(DELIMITER_LENGTH); return frame; } else { final int length = buffer.readableBytes(); if (length > V1_MAX_LENGTH) { discardedBytes = length; discarding = false; } else { discardedBytes = buffer.readableBytes(); buffer.skipBytes(discardedBytes);
int dataLength = in.readableBytes(); if (dataLength > MIN_COMPRESSIBLE_LENGTH) { for (;;) { final int lengthIdx = out.writerIndex() + 1; if (dataLength < MIN_COMPRESSIBLE_LENGTH) { ByteBuf slice = in.readSlice(dataLength); writeUnencodedChunk(slice, out, dataLength); break; ByteBuf slice = in.readSlice(Short.MAX_VALUE); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, Short.MAX_VALUE); dataLength -= Short.MAX_VALUE; } else { ByteBuf slice = in.readSlice(dataLength); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, dataLength);
@Override protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Object> list) throws Exception { if (in.readableBytes() < RemotingHeader.MIN_HEADER_SIZE + RemotingHeader.LENGTH_FIELD) return; if (in.readableBytes() < total) { in.resetReaderIndex(); return; ByteBuf bodyData = in.readSlice(bodyLength); bodyData.retain(); remotingCommand.setBody(bodyData);
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; }
private List<Position> decodeRetransmission(ByteBuf buf, DeviceSession deviceSession) { List<Position> positions = new LinkedList<>(); int count = buf.readUnsignedByte(); for (int i = 0; i < count; i++) { buf.readUnsignedByte(); // alarm int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\\'); if (endIndex < 0) { endIndex = buf.writerIndex() - 4; } String sentence = buf.readSlice(endIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII); Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); position = decodeRegular(position, sentence); if (position != null) { positions.add(position); } if (buf.readableBytes() > 4) { buf.readUnsignedByte(); // delimiter } } return positions; }
private static HAProxyTLV readNextTLV(final ByteBuf header) { if (header.readableBytes() < 4) { return null; case PP2_TYPE_SSL: final ByteBuf rawContent = header.retainedSlice(header.readerIndex(), length); final ByteBuf byteBuf = header.readSlice(length); final byte client = byteBuf.readByte(); final int verify = byteBuf.readInt(); if (byteBuf.readableBytes() >= 4) { } while (byteBuf.readableBytes() >= 4);
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) { if (in.readableBytes() < MobileMessageDecoder.PROTOCOL_APP_HEADER_SIZE) { return; int length = (int) in.readUnsignedInt(); if (in.readableBytes() < length) { in.resetReaderIndex(); return; ByteBuf buf = in.readSlice(length); switch (command) { case GET_ENHANCED_GRAPH_DATA : case LOAD_PROFILE_GZIPPED : case GET_PROJECT_BY_TOKEN : byte[] bytes = new byte[buf.readableBytes()]; buf.readBytes(bytes); message = new BinaryMessage(messageId, command, bytes);
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (corrupted) { in.skipBytes(in.readableBytes()); return; final int inSize = in.readableBytes(); if (inSize < 4) { snappy.decode(in.readSlice(chunkLength - 4), uncompressed);