final int length = Math.min(in.readableBytes(), MAX_CHUNK_LENGTH); final int outputIdx = out.writerIndex(); out.setMedium(outputIdx, MAGIC_NUMBER); int outputOffset = outputIdx + CHECKSUM_OFFSET + (checksum != null ? 4 : 0); chunkLength = compressedLength; out.setShort(outputOffset, chunkLength); outputOffset += 2; } else { out.setShort(outputOffset, length); out.writerIndex(outputOffset + 2 + chunkLength); in.skipBytes(length);
public static void writeString(String str, ByteBuf cb) { int writerIndex = cb.writerIndex(); cb.writeShort(0); int lengthBytes = ByteBufUtil.writeUtf8(cb, str); cb.setShort(writerIndex, lengthBytes); }
protected void writeActions(final List<Action> actions, final ByteBuf outBuffer, int startIndex) { int lengthIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION); ListSerializer.serializeList(actions, ACTION_KEY_MAKER, getRegistry(), outBuffer); int instructionLength = outBuffer.writerIndex() - startIndex; outBuffer.setShort(lengthIndex, instructionLength); }
ByteBuf out = ctx.alloc().buffer(NettyNetwork.INITIAL_BUFFER_SIZE, NettyNetwork.SEND_BUFFER_SIZE); component.extLog.trace("Trying to encode outgoing data to {} from {}: {}.", ctx.channel().remoteAddress(), ctx.channel().localAddress(), msgw.msg.getClass()); int startIdx = out.writerIndex(); out.writeBytes(LENGTH_PLACEHOLDER); int endIdx = out.writerIndex(); int diff = endIdx - startIdx - LENGTH_PLACEHOLDER.length; if (diff > 65532) { //2^16 - 2bytes for the length header (snappy wants no more than 65536 bytes uncompressed) throw new Exception("Can't encode message longer than 65532 bytes!"); out.setShort(startIdx, diff);
public void writeData(ByteBuf byteBuf) { int startIndex = byteBuf.writerIndex(); // Just reserve the bytes to add length of header at last. byteBuf.writeShort(Short.MAX_VALUE); byte[] tableIdBytes = tableUniqueId.getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); byteBuf.writeInt(tableIdBytes.length); byteBuf.writeBytes(tableIdBytes); byte[] colBytes = columnName.getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); byteBuf.writeInt(colBytes.length); byteBuf.writeBytes(colBytes); byteBuf.writeByte(type.getType()); if (dictionaryValue > 0) { byteBuf.writeByte(0); byteBuf.writeInt(dictionaryValue); } else { byteBuf.writeByte(1); byte[] dataBytes = data.getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); byteBuf.writeInt(dataBytes.length); byteBuf.writeBytes(dataBytes); } int endIndex = byteBuf.writerIndex(); // Add the length of message at the starting.it is required while decoding as in TCP protocol // it not guarantee that we receive all data in one packet, so we need to wait to receive all // packets before proceeding to process the message.Based on the length it waits. byteBuf.setShort(startIndex, endIndex - startIndex - 2); }
final int length = Math.min(in.readableBytes(), MAX_CHUNK_LENGTH); final int outputIdx = out.writerIndex(); out.setMedium(outputIdx, MAGIC_NUMBER); int outputOffset = outputIdx + CHECKSUM_OFFSET + (checksum != null ? 4 : 0); chunkLength = compressedLength; out.setShort(outputOffset, chunkLength); outputOffset += 2; } else { out.setShort(outputOffset, length); out.writerIndex(outputOffset + 2 + chunkLength); in.skipBytes(length);
public static void writeString(String str, ByteBuf cb) { int writerIndex = cb.writerIndex(); cb.writeShort(0); int lengthBytes = ByteBufUtil.writeUtf8(cb, str); cb.setShort(writerIndex, lengthBytes); }
private static void writeNextTableRelatedTableProperty(final ByteBuf output, final TableFeatureProperties property, final byte code) { int startIndex = output.writerIndex(); output.writeShort(code); int lengthIndex = output.writerIndex(); output.writeShort(EncodeConstants.EMPTY_LENGTH); List<NextTableIds> nextTableIds = property.getAugmentation(NextTableRelatedTableFeatureProperty.class) .getNextTableIds(); if (nextTableIds != null) { for (NextTableIds next : nextTableIds) { output.writeByte(next.getTableId()); } } int length = output.writerIndex() - startIndex; output.setShort(lengthIndex, length); output.writeZero(paddingNeeded(length)); }
final int length = Math.min(in.readableBytes(), MAX_CHUNK_LENGTH); final int outputIdx = out.writerIndex(); out.setMedium(outputIdx, MAGIC_NUMBER); int outputOffset = outputIdx + CHECKSUM_OFFSET + (checksum != null ? 4 : 0); chunkLength = compressedLength; out.setShort(outputOffset, chunkLength); outputOffset += 2; } else { out.setShort(outputOffset, length); out.writerIndex(outputOffset + 2 + chunkLength); in.skipBytes(length);
public static void writeString(String str, ByteBuf cb) { int writerIndex = cb.writerIndex(); cb.writeShort(0); int lengthBytes = ByteBufUtil.writeUtf8(cb, str); cb.setShort(writerIndex, lengthBytes); }
private static void writeNextTableRelatedTableProperty(final ByteBuf output, final TableFeatureProperties property, final byte code) { int startIndex = output.writerIndex(); output.writeShort(code); int lengthIndex = output.writerIndex(); output.writeShort(EncodeConstants.EMPTY_LENGTH); List<NextTableIds> nextTableIds = property. getAugmentation(NextTableRelatedTableFeatureProperty.class).getNextTableIds(); if (nextTableIds != null) { for (NextTableIds next : nextTableIds) { output.writeByte(next.getTableId()); } } int length = output.writerIndex() - startIndex; output.setShort(lengthIndex, length); output.writeZero(paddingNeeded(length)); }
private void closeChunkIfOpen() { if ( chunkOpen ) { int chunkSize = buffer.writerIndex() - (currentChunkHeaderOffset + CHUNK_HEADER_SIZE); buffer.setShort( currentChunkHeaderOffset, chunkSize ); chunkOpen = false; } }
@Override public void serialize(Match match, ByteBuf outBuffer) { if (match == null) { LOG.debug("Match is null"); return; } int matchStartIndex = outBuffer.writerIndex(); serializeType(match, outBuffer); int matchLengthIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); serializeMatchEntries(match.getMatchEntry(), outBuffer); // Length of ofp_match (excluding padding) int matchLength = outBuffer.writerIndex() - matchStartIndex; outBuffer.setShort(matchLengthIndex, matchLength); int paddingRemainder = matchLength % EncodeConstants.PADDING; if (paddingRemainder != 0) { outBuffer.writeZero(EncodeConstants.PADDING - paddingRemainder); } }
private void closeChunkIfOpen() { if ( chunkOpen ) { int chunkSize = buffer.writerIndex() - (currentChunkHeaderOffset + CHUNK_HEADER_SIZE); buffer.setShort( currentChunkHeaderOffset, chunkSize ); chunkOpen = false; } }
private void serializerBuckets(List<BucketsList> buckets, ByteBuf outBuffer) { if (buckets != null) { for (BucketsList currentBucket : buckets) { int bucketLengthIndex = outBuffer.writerIndex(); outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH); outBuffer.writeShort(currentBucket.getWeight().shortValue()); outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue()); outBuffer.writeInt(currentBucket.getWatchGroup().intValue()); outBuffer.writeZero(PADDING_IN_BUCKET); ListSerializer.serializeList(currentBucket.getAction(), TypeKeyMakerFactory .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, outBuffer); outBuffer.setShort(bucketLengthIndex, outBuffer.writerIndex() - bucketLengthIndex); } } }
final int length = Math.min(in.readableBytes(), MAX_CHUNK_LENGTH); final int outputIdx = out.writerIndex(); out.setMedium(outputIdx, MAGIC_NUMBER); int outputOffset = outputIdx + CHECKSUM_OFFSET + (checksum != null ? 4 : 0); chunkLength = compressedLength; out.setShort(outputOffset, chunkLength); outputOffset += 2; } else { out.setShort(outputOffset, length); out.writerIndex(outputOffset + 2 + chunkLength); in.skipBytes(length);
private void writeActionsRelatedTableProperty(final ByteBuf output, final TableFeatureProperties property, final byte code) { int startIndex = output.writerIndex(); output.writeShort(code); int lengthIndex = output.writerIndex(); output.writeShort(EncodeConstants.EMPTY_LENGTH); List<Action> actions = property.getAugmentation(ActionRelatedTableFeatureProperty.class).getAction(); if (actions != null) { TypeKeyMaker<Action> keyMaker = TypeKeyMakerFactory.createActionKeyMaker(EncodeConstants.OF13_VERSION_ID); ListSerializer.serializeHeaderList(actions, keyMaker, registry, output); } int length = output.writerIndex() - startIndex; output.setShort(lengthIndex, length); output.writeZero(paddingNeeded(length)); }
final int length = Math.min(in.readableBytes(), MAX_CHUNK_LENGTH); final int outputIdx = out.writerIndex(); out.setMedium(outputIdx, MAGIC_NUMBER); int outputOffset = outputIdx + CHECKSUM_OFFSET + (checksum != null ? 4 : 0); chunkLength = compressedLength; out.setShort(outputOffset, chunkLength); outputOffset += 2; } else { out.setShort(outputOffset, length); out.writerIndex(outputOffset + 2 + chunkLength); in.skipBytes(length);
private void serializeQueueBody(MultipartReplyBody body, ByteBuf outBuffer) { MultipartReplyQueueCase queueCase = (MultipartReplyQueueCase) body; MultipartReplyQueue queue = queueCase.getMultipartReplyQueue(); for (QueueStats queueStats : queue.getQueueStats()) { ByteBuf queueStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer(); queueStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH); queueStatsBuff.writeZero(QUEUE_PADDING); queueStatsBuff.writeInt(queueStats.getQueueId().intValue()); queueStatsBuff.writeLong(queueStats.getTxBytes().longValue()); queueStatsBuff.writeLong(queueStats.getTxPackets().longValue()); queueStatsBuff.writeLong(queueStats.getTxErrors().longValue()); queueStatsBuff.setShort(QUEUE_STATS_LENGTH_INDEX, queueStatsBuff.readableBytes()); outBuffer.writeBytes(queueStatsBuff); } }
final int length = Math.min(in.readableBytes(), MAX_CHUNK_LENGTH); final int outputIdx = out.writerIndex(); out.setMedium(outputIdx, MAGIC_NUMBER); int outputOffset = outputIdx + CHECKSUM_OFFSET + (checksum != null ? 4 : 0); chunkLength = compressedLength; out.setShort(outputOffset, chunkLength); outputOffset += 2; } else { out.setShort(outputOffset, length); out.writerIndex(outputOffset + 2 + chunkLength); in.skipBytes(length);