org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf.readInt()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(169)

本文整理了Java中org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf.readInt()方法的一些代码示例,展示了ByteBuf.readInt()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.readInt()方法的具体详情如下:
包路径:org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:readInt

ByteBuf.readInt介绍

暂无

代码示例

代码示例来源:origin: apache/flink

/**
 * De-serializes the header and returns the {@link MessageType}.
 * <pre>
 *  <b>The buffer is expected to be at the header position.</b>
 * </pre>
 * @param buf                        The {@link ByteBuf} containing the serialized header.
 * @return                            The message type.
 * @throws IllegalStateException    If unexpected message version or message type.
 */
public static MessageType deserializeHeader(final ByteBuf buf) {
  // checking the version
  int version = buf.readInt();
  Preconditions.checkState(version == VERSION,
      "Version Mismatch:  Found " + version + ", Expected: " + VERSION + '.');
  // fetching the message type
  int msgType = buf.readInt();
  MessageType[] values = MessageType.values();
  Preconditions.checkState(msgType >= 0 && msgType < values.length,
      "Illegal message type with index " + msgType + '.');
  return values[msgType];
}

代码示例来源:origin: apache/flink

@Override
  public KvStateResponse deserializeMessage(ByteBuf buf) {
    int length = buf.readInt();
    Preconditions.checkArgument(length >= 0,
        "Negative length for state content. " +
            "This indicates a serialization error.");
    byte[] content = new byte[length];
    buf.readBytes(content);
    return new KvStateResponse(content);
  }
}

代码示例来源:origin: apache/flink

@Override
  public KvStateRequest deserializeMessage(ByteBuf buf) {
    JobID jobId = new JobID(buf.readLong(), buf.readLong());
    int statenameLength = buf.readInt();
    Preconditions.checkArgument(statenameLength >= 0,
        "Negative length for state name. " +
            "This indicates a serialization error.");
    String stateName = "";
    if (statenameLength > 0) {
      byte[] name = new byte[statenameLength];
      buf.readBytes(name);
      stateName = new String(name, ConfigConstants.DEFAULT_CHARSET);
    }
    int keyHashCode = buf.readInt();
    int knamespaceLength = buf.readInt();
    Preconditions.checkArgument(knamespaceLength >= 0,
        "Negative length for key and namespace. " +
            "This indicates a serialization error.");
    byte[] serializedKeyAndNamespace = new byte[knamespaceLength];
    if (knamespaceLength > 0) {
      buf.readBytes(serializedKeyAndNamespace);
    }
    return new KvStateRequest(jobId, stateName, keyHashCode, serializedKeyAndNamespace);
  }
}

代码示例来源:origin: apache/flink

@Override
  public TestMessage deserializeMessage(ByteBuf buf) {
    int length = buf.readInt();
    String message = "";
    if (length > 0) {
      byte[] name = new byte[length];
      buf.readBytes(name);
      message = new String(name, ConfigConstants.DEFAULT_CHARSET);
    }
    return new TestMessage(message);
  }
}

代码示例来源:origin: apache/flink

@Override
  public KvStateInternalRequest deserializeMessage(ByteBuf buf) {
    KvStateID kvStateId = new KvStateID(buf.readLong(), buf.readLong());
    int length = buf.readInt();
    Preconditions.checkArgument(length >= 0,
        "Negative length for key and namespace. " +
            "This indicates a serialization error.");
    byte[] serializedKeyAndNamespace = new byte[length];
    if (length > 0) {
      buf.readBytes(serializedKeyAndNamespace);
    }
    return new KvStateInternalRequest(kvStateId, serializedKeyAndNamespace);
  }
}

代码示例来源:origin: apache/flink

/**
 * Tests server failure serialization.
 */
@Test
public void testServerFailureSerialization() throws Exception {
  IllegalStateException cause = new IllegalStateException("Expected test");
  ByteBuf buf = MessageSerializer.serializeServerFailure(alloc, cause);
  int frameLength = buf.readInt();
  assertEquals(MessageType.SERVER_FAILURE, MessageSerializer.deserializeHeader(buf));
  Throwable request = MessageSerializer.deserializeServerFailure(buf);
  assertEquals(buf.readerIndex(), frameLength + 4);
  assertEquals(cause.getClass(), request.getClass());
  assertEquals(cause.getMessage(), request.getMessage());
}

代码示例来源:origin: apache/flink

/**
 * Tests request failure serialization.
 */
@Test
public void testKvStateRequestFailureSerialization() throws Exception {
  long requestId = Integer.MAX_VALUE + 1111222L;
  IllegalStateException cause = new IllegalStateException("Expected test");
  ByteBuf buf = MessageSerializer.serializeRequestFailure(alloc, requestId, cause);
  int frameLength = buf.readInt();
  assertEquals(MessageType.REQUEST_FAILURE, MessageSerializer.deserializeHeader(buf));
  RequestFailure requestFailure = MessageSerializer.deserializeRequestFailure(buf);
  assertEquals(buf.readerIndex(), frameLength + 4);
  assertEquals(requestId, requestFailure.getRequestId());
  assertEquals(cause.getClass(), requestFailure.getCause().getClass());
  assertEquals(cause.getMessage(), requestFailure.getCause().getMessage());
}

代码示例来源:origin: apache/flink

/**
 * Tests response serialization with zero-length serialized result.
 */
@Test
public void testResponseSerializationWithZeroLengthSerializedResult() throws Exception {
  byte[] serializedResult = new byte[0];
  final KvStateResponse response = new KvStateResponse(serializedResult);
  final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer =
      new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
  ByteBuf buf = MessageSerializer.serializeResponse(alloc, 72727278L, response);
  int frameLength = buf.readInt();
  assertEquals(MessageType.REQUEST_RESULT, MessageSerializer.deserializeHeader(buf));
  assertEquals(72727278L, MessageSerializer.getRequestId(buf));
  KvStateResponse responseDeser = serializer.deserializeResponse(buf);
  assertEquals(buf.readerIndex(), frameLength + 4);
  assertArrayEquals(serializedResult, responseDeser.getContent());
}

代码示例来源:origin: apache/flink

/**
 * Tests response serialization.
 */
@Test
public void testResponseSerialization() throws Exception {
  long requestId = Integer.MAX_VALUE + 72727278L;
  byte[] serializedResult = randomByteArray(1024);
  final KvStateResponse response = new KvStateResponse(serializedResult);
  final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer =
      new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
  ByteBuf buf = MessageSerializer.serializeResponse(alloc, requestId, response);
  int frameLength = buf.readInt();
  assertEquals(MessageType.REQUEST_RESULT, MessageSerializer.deserializeHeader(buf));
  assertEquals(requestId, MessageSerializer.getRequestId(buf));
  KvStateResponse responseDeser = serializer.deserializeResponse(buf);
  assertEquals(buf.readerIndex(), frameLength + 4);
  assertArrayEquals(serializedResult, responseDeser.getContent());
}

代码示例来源:origin: apache/flink

/**
 * Tests request serialization with zero-length serialized key and namespace.
 */
@Test
public void testRequestSerializationWithZeroLengthKeyAndNamespace() throws Exception {
  long requestId = Integer.MAX_VALUE + 1337L;
  KvStateID kvStateId = new KvStateID();
  byte[] serializedKeyAndNamespace = new byte[0];
  final KvStateInternalRequest request = new KvStateInternalRequest(kvStateId, serializedKeyAndNamespace);
  final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer =
      new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
  ByteBuf buf = MessageSerializer.serializeRequest(alloc, requestId, request);
  int frameLength = buf.readInt();
  assertEquals(MessageType.REQUEST, MessageSerializer.deserializeHeader(buf));
  assertEquals(requestId, MessageSerializer.getRequestId(buf));
  KvStateInternalRequest requestDeser = serializer.deserializeRequest(buf);
  assertEquals(buf.readerIndex(), frameLength + 4);
  assertEquals(kvStateId, requestDeser.getKvStateId());
  assertArrayEquals(serializedKeyAndNamespace, requestDeser.getSerializedKeyAndNamespace());
}

代码示例来源:origin: apache/flink

/**
 * Tests request serialization.
 */
@Test
public void testRequestSerialization() throws Exception {
  long requestId = Integer.MAX_VALUE + 1337L;
  KvStateID kvStateId = new KvStateID();
  byte[] serializedKeyAndNamespace = randomByteArray(1024);
  final KvStateInternalRequest request = new KvStateInternalRequest(kvStateId, serializedKeyAndNamespace);
  final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer =
      new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
  ByteBuf buf = MessageSerializer.serializeRequest(alloc, requestId, request);
  int frameLength = buf.readInt();
  assertEquals(MessageType.REQUEST, MessageSerializer.deserializeHeader(buf));
  assertEquals(requestId, MessageSerializer.getRequestId(buf));
  KvStateInternalRequest requestDeser = serializer.deserializeRequest(buf);
  assertEquals(buf.readerIndex(), frameLength + 4);
  assertEquals(kvStateId, requestDeser.getKvStateId());
  assertArrayEquals(serializedKeyAndNamespace, requestDeser.getSerializedKeyAndNamespace());
}

代码示例来源:origin: org.apache.flink/flink-runtime

static BufferResponse readFrom(ByteBuf buffer) {
    InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
    int sequenceNumber = buffer.readInt();
    int backlog = buffer.readInt();
    boolean isBuffer = buffer.readBoolean();
    int size = buffer.readInt();
    ByteBuf retainedSlice = buffer.readSlice(size).retain();
    return new BufferResponse(retainedSlice, isBuffer, sequenceNumber, receiverId, backlog);
  }
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.11

static BufferResponse readFrom(ByteBuf buffer) {
    InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
    int sequenceNumber = buffer.readInt();
    int backlog = buffer.readInt();
    boolean isBuffer = buffer.readBoolean();
    int size = buffer.readInt();
    ByteBuf retainedSlice = buffer.readSlice(size).retain();
    return new BufferResponse(retainedSlice, isBuffer, sequenceNumber, receiverId, backlog);
  }
}

代码示例来源:origin: org.apache.flink/flink-runtime

static PartitionRequest readFrom(ByteBuf buffer) {
  ResultPartitionID partitionId =
    new ResultPartitionID(
      IntermediateResultPartitionID.fromByteBuf(buffer),
      ExecutionAttemptID.fromByteBuf(buffer));
  int queueIndex = buffer.readInt();
  InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
  int credit = buffer.readInt();
  return new PartitionRequest(partitionId, queueIndex, receiverId, credit);
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.11

static PartitionRequest readFrom(ByteBuf buffer) {
  ResultPartitionID partitionId =
    new ResultPartitionID(
      IntermediateResultPartitionID.fromByteBuf(buffer),
      ExecutionAttemptID.fromByteBuf(buffer));
  int queueIndex = buffer.readInt();
  InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
  int credit = buffer.readInt();
  return new PartitionRequest(partitionId, queueIndex, receiverId, credit);
}

代码示例来源:origin: com.alibaba.blink/flink-queryable-state-client-java

@Override
  public KvStateResponse deserializeMessage(ByteBuf buf) {
    int length = buf.readInt();
    Preconditions.checkArgument(length >= 0,
        "Negative length for state content. " +
            "This indicates a serialization error.");
    byte[] content = new byte[length];
    buf.readBytes(content);
    return new KvStateResponse(content);
  }
}

代码示例来源:origin: org.apache.flink/flink-queryable-state-client-java_2.11

@Override
  public KvStateResponse deserializeMessage(ByteBuf buf) {
    int length = buf.readInt();
    Preconditions.checkArgument(length >= 0,
        "Negative length for state content. " +
            "This indicates a serialization error.");
    byte[] content = new byte[length];
    buf.readBytes(content);
    return new KvStateResponse(content);
  }
}

代码示例来源:origin: org.apache.flink/flink-runtime

static AddCredit readFrom(ByteBuf buffer) {
  ResultPartitionID partitionId =
    new ResultPartitionID(
      IntermediateResultPartitionID.fromByteBuf(buffer),
      ExecutionAttemptID.fromByteBuf(buffer));
  int credit = buffer.readInt();
  InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
  return new AddCredit(partitionId, credit, receiverId);
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.11

static AddCredit readFrom(ByteBuf buffer) {
  ResultPartitionID partitionId =
    new ResultPartitionID(
      IntermediateResultPartitionID.fromByteBuf(buffer),
      ExecutionAttemptID.fromByteBuf(buffer));
  int credit = buffer.readInt();
  InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
  return new AddCredit(partitionId, credit, receiverId);
}

代码示例来源:origin: com.alibaba.blink/flink-runtime

static AddCredit readFrom(ByteBuf buffer) {
  ResultPartitionID partitionId =
    new ResultPartitionID(
      IntermediateResultPartitionID.fromByteBuf(buffer),
      ExecutionAttemptID.fromByteBuf(buffer));
  int credit = buffer.readInt();
  InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
  return new AddCredit(partitionId, credit, receiverId);
}

相关文章