Java Code Examples for com.google.protobuf.ByteString.newOutput()

The following are Jave code examples for showing how to use newOutput() 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: OpenYOLO-Android   File: ProtoListUtil.java   Source Code and License Vote up 6 votes
/**
 * Creates a {@link ByteString} by serializing the list of protos. Use
 * {@link #readMessageList(ByteString, Parser)} to deserialize.
 */
public static <T extends MessageLite> ByteString writeMessageList(List<T> protos) {
    Output output = ByteString.newOutput();
    try {
        writeMessageListTo(output, protos);
    } catch (IOException ex) {
        throw new IllegalStateException("Unable to write protobufs to memory");
    }

    return output.toByteString();
}
 
Example 2
Project: hadoop   File: BlockListAsLongs.java   Source Code and License Vote up 4 votes
Builder() {
  out = ByteString.newOutput(64*1024);
  cos = CodedOutputStream.newInstance(out);
}
 
Example 3
Project: ditb   File: Procedure.java   Source Code and License Vote up 4 votes
/**
 * Helper to convert the procedure to protobuf.
 * Used by ProcedureStore implementations.
 */
@InterfaceAudience.Private
public static ProcedureProtos.Procedure convert(final Procedure proc)
    throws IOException {
  Preconditions.checkArgument(proc != null);
  validateClass(proc);

  ProcedureProtos.Procedure.Builder builder = ProcedureProtos.Procedure.newBuilder()
    .setClassName(proc.getClass().getName())
    .setProcId(proc.getProcId())
    .setState(proc.getState())
    .setStartTime(proc.getStartTime())
    .setLastUpdate(proc.getLastUpdate());

  if (proc.hasParent()) {
    builder.setParentId(proc.getParentProcId());
  }

  if (proc.hasTimeout()) {
    builder.setTimeout(proc.getTimeout());
  }

  if (proc.hasOwner()) {
    builder.setOwner(proc.getOwner());
  }

  int[] stackIds = proc.getStackIndexes();
  if (stackIds != null) {
    for (int i = 0; i < stackIds.length; ++i) {
      builder.addStackId(stackIds[i]);
    }
  }

  if (proc.hasException()) {
    RemoteProcedureException exception = proc.getException();
    builder.setException(
      RemoteProcedureException.toProto(exception.getSource(), exception.getCause()));
  }

  byte[] result = proc.getResult();
  if (result != null) {
    builder.setResult(ByteStringer.wrap(result));
  }

  ByteString.Output stateStream = ByteString.newOutput();
  proc.serializeStateData(stateStream);
  if (stateStream.size() > 0) {
    builder.setStateData(stateStream.toByteString());
  }

  if (proc.getNonceKey() != null) {
    builder.setNonceGroup(proc.getNonceKey().getNonceGroup());
    builder.setNonce(proc.getNonceKey().getNonce());
  }

  return builder.build();
}