Java Code Examples for com.google.protobuf.ByteString.EMPTY

The following are Jave code examples for showing how to use EMPTY of the com.google.protobuf.ByteString class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: google-assistant-java-demo   File: AssistantClient.java   Source Code and License Vote up 6 votes
public AssistantClient(OAuthCredentials oAuthCredentials, AssistantConf assistantConf, DeviceModel deviceModel,
                       Device device) {

    this.assistantConf = assistantConf;
    this.deviceModel = deviceModel;
    this.device = device;
    this.currentConversationState = ByteString.EMPTY;

    // Create a channel to the test service.
    ManagedChannel channel = ManagedChannelBuilder.forAddress(assistantConf.getAssistantApiEndpoint(), 443)
            .build();

    // Create a stub with credential
    embeddedAssistantStub = EmbeddedAssistantGrpc.newStub(channel);

    updateCredentials(oAuthCredentials);
}
 
Example 2
Project: hadoop-oss   File: NuCypherExtPBHelperClient.java   Source Code and License Vote up 5 votes
public static ByteString getByteString(byte[] bytes) {
  // return singleton to reduce object allocation
  return (bytes.length == 0) ? ByteString.EMPTY : ByteString.copyFrom(bytes);
}
 
Example 3
Project: seldon-core   File: JsonFormat.java   Source Code and License Vote up 5 votes
/**
 * Gets the default value for a field type. Note that we use proto3
 * language defaults and ignore any default values set through the
 * proto "default" option.
 */
private Object getDefaultValue(FieldDescriptor field, Message.Builder builder) {
  switch (field.getType()) {
    case INT32:
    case SINT32:
    case SFIXED32:
    case UINT32:
    case FIXED32:
      return 0;
    case INT64:
    case SINT64:
    case SFIXED64:
    case UINT64:
    case FIXED64:
      return 0L;
    case FLOAT:
      return 0.0f;
    case DOUBLE:
      return 0.0;
    case BOOL:
      return false;
    case STRING:
      return "";
    case BYTES:
      return ByteString.EMPTY;
    case ENUM:
      return field.getEnumType().getValues().get(0);
    case MESSAGE:
    case GROUP:
      return builder.newBuilderForField(field).getDefaultInstanceForType();
    default:
      throw new IllegalStateException("Invalid field type: " + field.getType());
  }
}
 
Example 4
Project: seldon-core   File: JsonFormat.java   Source Code and License Vote up 5 votes
/**
 * Gets the default value for a field type. Note that we use proto3
 * language defaults and ignore any default values set through the
 * proto "default" option.
 */
private Object getDefaultValue(FieldDescriptor field, Message.Builder builder) {
  switch (field.getType()) {
    case INT32:
    case SINT32:
    case SFIXED32:
    case UINT32:
    case FIXED32:
      return 0;
    case INT64:
    case SINT64:
    case SFIXED64:
    case UINT64:
    case FIXED64:
      return 0L;
    case FLOAT:
      return 0.0f;
    case DOUBLE:
      return 0.0;
    case BOOL:
      return false;
    case STRING:
      return "";
    case BYTES:
      return ByteString.EMPTY;
    case ENUM:
      return field.getEnumType().getValues().get(0);
    case MESSAGE:
    case GROUP:
      return builder.newBuilderForField(field).getDefaultInstanceForType();
    default:
      throw new IllegalStateException("Invalid field type: " + field.getType());
  }
}
 
Example 5
Project: seldon-core   File: JsonFormat.java   Source Code and License Vote up 5 votes
/**
 * Gets the default value for a field type. Note that we use proto3
 * language defaults and ignore any default values set through the
 * proto "default" option.
 */
private Object getDefaultValue(FieldDescriptor field, Message.Builder builder) {
  switch (field.getType()) {
    case INT32:
    case SINT32:
    case SFIXED32:
    case UINT32:
    case FIXED32:
      return 0;
    case INT64:
    case SINT64:
    case SFIXED64:
    case UINT64:
    case FIXED64:
      return 0L;
    case FLOAT:
      return 0.0f;
    case DOUBLE:
      return 0.0;
    case BOOL:
      return false;
    case STRING:
      return "";
    case BYTES:
      return ByteString.EMPTY;
    case ENUM:
      return field.getEnumType().getValues().get(0);
    case MESSAGE:
    case GROUP:
      return builder.newBuilderForField(field).getDefaultInstanceForType();
    default:
      throw new IllegalStateException("Invalid field type: " + field.getType());
  }
}
 
Example 6
Project: bazel-buildfarm   File: ByteStringIteratorInputStream.java   Source Code and License Vote up 5 votes
private void advance() {
  ByteString data = ByteString.EMPTY;
  while (iterator.hasNext() && data.isEmpty()) {
    data = iterator.next();
  }
  input = data.newInput();
}
 
Example 7
Project: bazel-buildfarm   File: ByteStreamService.java   Source Code and License Vote up 5 votes
private void readBlob(
    ReadRequest request,
    StreamObserver<ReadResponse> responseObserver) {
  String resourceName = request.getResourceName();

  Instance instance;
  try {
    instance = instances.getFromBlob(resourceName);
  } catch (InstanceNotFoundException ex) {
    responseObserver.onError(BuildFarmInstances.toStatusException(ex));
    return;
  }

  Digest digest = UrlPath.parseBlobDigest(resourceName);

  ByteString blob = instance.getBlob(
      digest, request.getReadOffset(), request.getReadLimit());
  if (blob == null) {
    responseObserver.onError(new StatusException(Status.NOT_FOUND));
    return;
  }

  while (!blob.isEmpty()) {
    ByteString chunk;
    if (blob.size() < DEFAULT_CHUNK_SIZE) {
      chunk = blob;
      blob = ByteString.EMPTY;
    } else {
      chunk = blob.substring(0, (int) DEFAULT_CHUNK_SIZE);
      blob = blob.substring((int) DEFAULT_CHUNK_SIZE);
    }
    responseObserver.onNext(ReadResponse.newBuilder()
        .setData(chunk)
        .build());
  }

  responseObserver.onCompleted();
}
 
Example 8
Project: sstore-soft   File: TransactionWorkRequestBuilder.java   Source Code and License Vote up 4 votes
public void addParameterSets(List<ByteString> params) {
    for (int i = 0, cnt = params.size(); i < cnt; i++) {
        ByteString bs = (this.param_indexes.get(i) ? params.get(i) : ByteString.EMPTY);
        this.builder.addParams(bs); 
    } // FOR
}
 
Example 9
Project: hadoop-oss   File: KeyRotationBC.java   Source Code and License Vote up 4 votes
public static ByteString getByteString(byte[] bytes) {
	// return singleton to reduce object allocation
	return (bytes.length == 0) ? ByteString.EMPTY : ByteString.copyFrom(bytes);
}
 
Example 10
Project: dataflow-opinion-analysis   File: RecordFileSource.java   Source Code and License Vote up 4 votes
private RecordFileReader(RecordFileSource<T> source) {
  super(source);
  buffer = ByteString.EMPTY;
  coder = source.coder;
  separator = source.separator;
}
 
Example 11
Project: s-store   File: TransactionWorkRequestBuilder.java   Source Code and License Vote up 4 votes
public void addParameterSets(List<ByteString> params) {
    for (int i = 0, cnt = params.size(); i < cnt; i++) {
        ByteString bs = (this.param_indexes.get(i) ? params.get(i) : ByteString.EMPTY);
        this.builder.addParams(bs); 
    } // FOR
}
 
Example 12
Project: tikv-client-lib-java   File: KeyRangeUtils.java   Source Code and License Vote up 4 votes
public static List<Coprocessor.KeyRange> split(Coprocessor.KeyRange range, int splitFactor) {
  if (splitFactor > 32 || splitFactor <= 0 || (splitFactor & (splitFactor - 1)) != 0) {
    throw new TiClientInternalException(
        "splitFactor must be positive integer power of 2 and no greater than 16");
  }

  ByteString startKey = range.getStart();
  ByteString endKey = range.getEnd();
  // we don't cut infinite
  if (startKey.isEmpty() || endKey.isEmpty()) {
    return ImmutableList.of(range);
  }

  ImmutableList.Builder<Coprocessor.KeyRange> resultList = ImmutableList.builder();
  int maxSize = Math.max(startKey.size(), endKey.size());
  int i;

  for (i = 0; i < maxSize; i++) {
    byte sb = i < startKey.size() ? startKey.byteAt(i) : 0;
    byte eb = i < endKey.size() ? endKey.byteAt(i) : 0;
    if (sb != eb) {
      break;
    }
  }

  ByteString sRemaining = i < startKey.size() ? startKey.substring(i) : ByteString.EMPTY;
  ByteString eRemaining = i < endKey.size() ? endKey.substring(i) : ByteString.EMPTY;

  CodecDataInput cdi = new CodecDataInput(sRemaining);
  int uss = cdi.readPartialUnsignedShort();

  cdi = new CodecDataInput(eRemaining);
  int ues = cdi.readPartialUnsignedShort();

  int delta = (ues - uss) / splitFactor;
  if (delta <= 0) {
    return ImmutableList.of(range);
  }

  ByteString prefix = startKey.size() > endKey.size() ?
                      startKey.substring(0, i) : endKey.substring(0, i);
  ByteString newStartKey = startKey;
  ByteString newEndKey;
  for (int j = 0; j < splitFactor; j++) {
    uss += delta;
    if (j == splitFactor - 1) {
      newEndKey = endKey;
    } else {
      CodecDataOutput cdo = new CodecDataOutput();
      cdo.writeShort(uss);
      newEndKey = prefix.concat(cdo.toByteString());
    }
    resultList.add(makeCoprocRange(newStartKey, newEndKey));
    newStartKey = newEndKey;
  }

  return resultList.build();
}
 
Example 13
Project: tikv-client-lib-java   File: RangeSplitterTest.java   Source Code and License Vote up 4 votes
private static ByteString handleToByteString(long tableId, Long k) {
  if (k != null) {
    return TableCodec.encodeRowKeyWithHandle(tableId, k);
  }
  return ByteString.EMPTY;
}
 
Example 14
Project: hadoop   File: BlockListAsLongs.java   Source Code and License Vote up 4 votes
@Override
public ByteString getBlocksBuffer() {
  return ByteString.EMPTY;
}
 
Example 15
Project: bazel-buildfarm   File: ByteStringSinkReader.java   Source Code and License Vote up 4 votes
public ByteStringSinkReader(InputStream input, OutputStream sink) {
  this.input = input;
  this.sink = sink;
  data = ByteString.EMPTY;
  completed = false;
}