com.google.protobuf.ByteString.copyFrom()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(632)

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

ByteString.copyFrom介绍

[英]Concatenates all byte strings in the iterable and returns the result. This is designed to run in O(list size), not O(total bytes).

The returned ByteString is not necessarily a unique object. If the list is empty, the returned object is the singleton empty ByteString. If the list has only one element, that ByteString will be returned without copying.
[中]连接iterable中的所有字节字符串并返回结果。这是为了在O(列表大小)中运行,而不是在O(总字节)中运行。
返回的ByteString不一定是唯一的对象。如果列表为空,则返回的对象是singleton empty ByteString。如果列表只有一个元素,那么将返回该ByteString而不进行复制。

代码示例

代码示例来源:origin: osmandapp/Osmand

/**
 * Copies the given bytes into a {@code ByteString}.
 *
 * @param bytes to copy
 * @return new {@code ByteString}
 */
public static ByteString copyFrom(byte[] bytes) {
 return copyFrom(bytes, 0, bytes.length);
}

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

/**
 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
 */
@Deprecated
public ByteString toByteString() {
 return ByteString.copyFrom(this.bytes, this.offset, this.length);
}

代码示例来源:origin: osmandapp/Osmand

/**
 * Copies the remaining bytes from a {@code java.nio.ByteBuffer} into
 * a {@code ByteString}.
 *
 * @param bytes sourceBuffer
 * @return new {@code ByteString}
 */
public static ByteString copyFrom(ByteBuffer bytes) {
 return copyFrom(bytes, bytes.remaining());
}

代码示例来源:origin: apache/incubator-shardingsphere

private ByteString getRangeEnd(final String key) {
    byte[] noPrefix = {0};
    byte[] endKey = key.getBytes().clone();
    for (int i = endKey.length - 1; i >= 0; i--) {
      if (endKey[i] < 0xff) {
        endKey[i] = (byte) (endKey[i] + 1);
        return ByteString.copyFrom(Arrays.copyOf(endKey, i + 1));
      }
    }
    return ByteString.copyFrom(noPrefix);
  }
}

代码示例来源:origin: Alluxio/alluxio

/**
 * A wrapper of
 * {@link alluxio.proto.journal.Job.TaskInfo.Builder#setResult} to take byte[] as input.
 *
 * @param builder the builder to update
 * @param bytes results bytes to set
 * @return updated builder
 */
public static alluxio.proto.journal.Job.TaskInfo.Builder setResult(
    alluxio.proto.journal.Job.TaskInfo.Builder builder, byte[] bytes) {
 return builder.setResult(com.google.protobuf.ByteString.copyFrom(bytes));
}

代码示例来源:origin: Alluxio/alluxio

/**
 * A wrapper of
 * {@link alluxio.proto.journal.Job.StartJobEntry.Builder#setSerializedJobConfig}
 * to take byte[] as input.
 *
 * @param builder the builder to update
 * @param bytes results bytes to set
 * @return updated builder
 */
public static alluxio.proto.journal.Job.StartJobEntry.Builder setSerializedJobConfig(
    alluxio.proto.journal.Job.StartJobEntry.Builder builder, byte[] bytes) {
 return builder.setSerializedJobConfig(com.google.protobuf.ByteString.copyFrom(bytes));
}

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

/**
  * Wraps a subset of a byte array in a {@link ByteString} without copying it.
  */
 public static ByteString wrap(final byte[] array, int offset, int length) {
  return USE_ZEROCOPYBYTESTRING? HBaseZeroCopyByteString.wrap(array, offset, length):
   ByteString.copyFrom(array, offset, length);
 }
}

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

/**
 * Wraps a byte array in a {@link ByteString} without copying it.
 */
public static ByteString wrap(final byte[] array) {
 return USE_ZEROCOPYBYTESTRING? HBaseZeroCopyByteString.wrap(array): ByteString.copyFrom(array);
}

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

private ByteString getCredentials(Credentials credentials) throws IOException {
 ByteBuffer credentialsBinary = credentialMap.get(currentQueryIdentifierProto);
 if (credentialsBinary == null) {
  credentialsBinary = LlapTezUtils.serializeCredentials(credentials);
  credentialMap.putIfAbsent(currentQueryIdentifierProto, credentialsBinary.duplicate());
 } else {
  credentialsBinary = credentialsBinary.duplicate();
 }
 return ByteString.copyFrom(credentialsBinary);
}

代码示例来源:origin: osmandapp/Osmand

/**
 * Creates a byte string. Its size is the current size of this output
 * stream and its output has been copied to it.
 *
 * @return  the current contents of this output stream, as a byte string.
 */
public synchronized ByteString toByteString() {
 flushLastBuffer();
 return ByteString.copyFrom(flushedBuffers);
}

代码示例来源:origin: Alluxio/alluxio

@Override
 public long run(final JobConfig jobConfig) throws IOException {
  final ByteString jobConfigStr = ByteString.copyFrom(SerializationUtils.serialize(jobConfig));
  return retryRPC(new RpcCallable<Long>() {
   public Long call() throws StatusRuntimeException {
    return mClient.run(RunPRequest.newBuilder().setJobConfig(jobConfigStr).build()).getJobId();
   }
  });
 }
}

代码示例来源:origin: MovingBlocks/Terasology

public static NetData.Certificate convert(PublicIdentityCertificate data) {
  return NetData.Certificate.newBuilder()
      .setId(data.getId())
      .setModulus(ByteString.copyFrom(data.getModulus().toByteArray()))
      .setExponent(ByteString.copyFrom(data.getExponent().toByteArray()))
      .setSignature(ByteString.copyFrom(data.getSignatureBytes())).build();
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public PersistedData create(byte[] value) {
  return new ProtobufPersistedData(EntityData.Value.newBuilder().setBytes(ByteString.copyFrom(value)).build());
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public PersistedData create(ByteBuffer value) {
  return new ProtobufPersistedData(EntityData.Value.newBuilder().setBytes(ByteString.copyFrom(value)).build());
}

代码示例来源:origin: voldemort/voldemort

public static VProto.Versioned.Builder encodeVersioned(Versioned<byte[]> versioned) {
  return VProto.Versioned.newBuilder()
              .setValue(ByteString.copyFrom(versioned.getValue()))
              .setVersion(ProtoUtils.encodeClock(versioned.getVersion()));
}

代码示例来源:origin: Alluxio/alluxio

/**
 * @return proto representation of the task info
 * @throws IOException if serialization fails
 */
public alluxio.grpc.TaskInfo toProto() throws IOException {
 ByteBuffer result =
   mResult == null ? null : ByteBuffer.wrap(SerializationUtils.serialize(mResult));
 alluxio.grpc.TaskInfo.Builder taskInfoBuilder =
   alluxio.grpc.TaskInfo.newBuilder().setJobId(mJobId).setTaskId(mTaskId)
     .setStatus(mStatus.toProto()).setErrorMessage(mErrorMessage);
 if (result != null) {
  taskInfoBuilder.setResult(ByteString.copyFrom(result));
 }
 return taskInfoBuilder.build();
}

代码示例来源:origin: Graylog2/graylog2-server

public void setRemoteAddress(ResolvableInetSocketAddress address) {
  final JournalMessages.RemoteAddress.Builder builder = msgBuilder.getRemoteBuilder();
  builder.setAddress(ByteString.copyFrom(address.getAddressBytes()))
      .setPort(address.getPort());
  // do not perform any reverse lookup here
  if (address.isReverseLookedUp()) {
    builder.setResolved(address.getHostName());
  }
}

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

private Map<byte[], SumResponse> sum(final Table table, final byte[] family,
  final byte[] qualifier, final byte[] start, final byte[] end) throws ServiceException,
  Throwable {
 ColumnAggregationProtos.SumRequest.Builder builder = ColumnAggregationProtos.SumRequest
   .newBuilder();
 builder.setFamily(ByteString.copyFrom(family));
 if (qualifier != null && qualifier.length > 0) {
  builder.setQualifier(ByteString.copyFrom(qualifier));
 }
 return table.batchCoprocessorService(
   ColumnAggregationProtos.ColumnAggregationService.getDescriptor().findMethodByName("sum"),
   builder.build(), start, end, ColumnAggregationProtos.SumResponse.getDefaultInstance());
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void bytes_field_can_not_be_converted() {
 expectedException.expect(RuntimeException.class);
 expectedException.expectMessage("JSON format does not support type 'BYTE_STRING' of field 'bytesField'");
 PrimitiveTypeMsg protobuf = PrimitiveTypeMsg.newBuilder()
  .setBytesField(ByteString.copyFrom(new byte[]{2, 4}))
  .build();
 ProtobufJsonFormat.write(protobuf, JsonWriter.of(new StringWriter()));
}

代码示例来源:origin: MovingBlocks/Terasology

@Test
public void testPersistBytes() throws Exception {
  ByteString bytes = ByteString.copyFrom(new byte[]{1, 2, 3, 4});
  nameValueBuilder.setName(VALUE_NAME);
  nameValueBuilder.setValue(EntityData.Value.newBuilder().setBytes(bytes));
  componentBuilder.addField(nameValueBuilder);
  entityBuilder.addComponent(componentBuilder.build());
  worldBuilder.addEntity(entityBuilder.build());
  EntityData.GlobalStore actual = persistAndRetrieve(worldBuilder.build());
  assertEquals(VALUE_NAME, actual.getEntity(0).getComponent(0).getField(0).getName());
  assertArrayEquals(bytes.toByteArray(), actual.getEntity(0).getComponent(0).getField(0).getValue().getBytes().toByteArray());
}

相关文章