com.google.protobuf.CodedOutputStream# computeUInt32SizeNoTag ( ) 源码实例Demo

下面列出了com.google.protobuf.CodedOutputStream# computeUInt32SizeNoTag ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: zetasketch   文件: State.java

public int getSerializedSize() {
  int size = 0;

  size += CodedOutputStream.computeUInt32SizeNoTag(TYPE_TAG);
  size += CodedOutputStream.computeEnumSizeNoTag(type.getNumber());

  size += CodedOutputStream.computeUInt32SizeNoTag(NUM_VALUES_TAG);
  size += CodedOutputStream.computeInt64SizeNoTag(numValues);

  if (encodingVersion != DEFAULT_ENCODING_VERSION) {
    size += CodedOutputStream.computeUInt32SizeNoTag(ENCODING_VERSION_TAG);
    size += CodedOutputStream.computeInt32SizeNoTag(encodingVersion);
  }

  if (!valueType.equals(DEFAULT_VALUE_TYPE)) {
    size += CodedOutputStream.computeUInt32SizeNoTag(VALUE_TYPE_TAG);
    size += CodedOutputStream.computeEnumSizeNoTag(valueType.getNumber());
  }

  int hllSize = getSerializedHllSize();
  size += CodedOutputStream.computeUInt32SizeNoTag(HYPERLOGLOGPLUS_UNIQUE_STATE_TAG);
  size += CodedOutputStream.computeUInt32SizeNoTag(hllSize);
  size += hllSize;

  return size;
}
 
源代码2 项目: zipkin-gcp   文件: StackdriverSender.java

StackdriverSender(Builder builder) {
  channel = builder.channel;
  callOptions = builder.callOptions;
  projectName = ByteString.copyFromUtf8("projects/" + builder.projectId);
  serverResponseTimeoutMs = builder.serverResponseTimeoutMs;
  traceIdPrefix = projectName.concat(ByteString.copyFromUtf8("/traces/"));
  shutdownChannelOnClose = builder.shutdownChannelOnClose;
  projectNameFieldSize = CodedOutputStream.computeBytesSize(1, projectName);

  // The size of the contents of the Span.name field, used to preallocate the correct sized
  // buffer when computing Span.name.
  spanNameSize = traceIdPrefix.size() + 32 + SPAN_ID_PREFIX.size() + 16;

  spanNameFieldSize = CodedOutputStream.computeTagSize(1)
      + CodedOutputStream.computeUInt32SizeNoTag(spanNameSize) + spanNameSize;

  BatchWriteSpansRequest healthcheckRequest = BatchWriteSpansRequest.newBuilder()
      .setNameBytes(projectName)
      .addSpans(Span.newBuilder().build())
      .build();
  healthcheckCall = new BatchWriteSpansCall(healthcheckRequest);
}
 

/**
 * Writes a delimited protocol buffer message in the same format as {@link
 * MessageLite#writeDelimitedTo(java.io.OutputStream)}.
 *
 * <p>Unfortunately, {@link MessageLite#writeDelimitedTo(java.io.OutputStream)} may result in
 * multiple calls to write on the underlying stream, so we have to provide this method here
 * instead of the caller using it directly.
 */
@Override
public void write(Message m) {
  Preconditions.checkNotNull(m);
  final int size = m.getSerializedSize();
  ByteArrayOutputStream bos =
      new ByteArrayOutputStream(CodedOutputStream.computeUInt32SizeNoTag(size) + size);
  try {
    m.writeDelimitedTo(bos);
  } catch (IOException e) {
    // This should never happen with an in-memory stream.
    exception.compareAndSet(null, new IllegalStateException(e.toString()));
    return;
  }
  write(bos.toByteArray());
}
 
源代码4 项目: bazel   文件: IdXmlResourceValue.java

@Override
public int serializeTo(int sourceId, Namespaces namespaces, OutputStream output)
    throws IOException {
  DataValueXml.Builder xmlValue =
      SerializeFormat.DataValueXml.newBuilder()
          .setType(XmlType.ID)
          .putAllNamespace(namespaces.asMap());
  if (value != null) {
    xmlValue.setValue(value);
  }
  SerializeFormat.DataValue dataValue =
      XmlResourceValues.newSerializableDataValueBuilder(sourceId).setXmlValue(xmlValue).build();
  dataValue.writeDelimitedTo(output);
  return CodedOutputStream.computeUInt32SizeNoTag(dataValue.getSerializedSize())
      + dataValue.getSerializedSize();
}
 
源代码5 项目: bazel   文件: PluralXmlResourceValue.java

@Override
public int serializeTo(int sourceId, Namespaces namespaces, OutputStream output)
    throws IOException {
  SerializeFormat.DataValue.Builder builder =
      XmlResourceValues.newSerializableDataValueBuilder(sourceId);
  SerializeFormat.DataValue value =
      builder
          .setXmlValue(
              builder
                  .getXmlValueBuilder()
                  .setType(XmlType.PLURAL)
                  .putAllNamespace(namespaces.asMap())
                  .putAllAttribute(attributes)
                  .putAllMappedStringValue(values))
          .build();
  value.writeDelimitedTo(output);
  return CodedOutputStream.computeUInt32SizeNoTag(value.getSerializedSize())
      + value.getSerializedSize();
}
 
源代码6 项目: zetasketch   文件: State.java

private int getSerializedHllSize() {
  int size = 0;

  if (sparseSize != DEFAULT_SPARSE_SIZE) {
    size += CodedOutputStream.computeUInt32SizeNoTag(SPARSE_SIZE_TAG);
    size += CodedOutputStream.computeInt32SizeNoTag(sparseSize);
  }

  if (precision != DEFAULT_PRECISION_OR_NUM_BUCKETS) {
    size += CodedOutputStream.computeUInt32SizeNoTag(PRECISION_OR_NUM_BUCKETS_TAG);
    size += CodedOutputStream.computeInt32SizeNoTag(precision);
  }

  if (sparsePrecision != DEFAULT_SPARSE_PRECISION_OR_NUM_BUCKETS) {
    size += CodedOutputStream.computeUInt32SizeNoTag(SPARSE_PRECISION_OR_NUM_BUCKETS_TAG);
    size += CodedOutputStream.computeInt32SizeNoTag(sparsePrecision);
  }

  if (data != null) {
    int dataLength = data.remaining();
    size += CodedOutputStream.computeUInt32SizeNoTag(DATA_TAG);
    size += CodedOutputStream.computeUInt32SizeNoTag(dataLength);
    size += dataLength;
  }

  if (sparseData != null) {
    int sparseDataLength = sparseData.remaining();
    size += CodedOutputStream.computeUInt32SizeNoTag(SPARSE_DATA_TAG);
    size += CodedOutputStream.computeUInt32SizeNoTag(sparseDataLength);
    size += sparseDataLength;
  }

  return size;
}
 
源代码7 项目: bazel   文件: BinaryFormatFileTransport.java

@Override
protected byte[] serializeEvent(BuildEventStreamProtos.BuildEvent buildEvent) {
  final int size = buildEvent.getSerializedSize();
  ByteArrayOutputStream bos =
      new ByteArrayOutputStream(CodedOutputStream.computeUInt32SizeNoTag(size) + size);
  try {
    buildEvent.writeDelimitedTo(bos);
  } catch (IOException e) {
    throw new RuntimeException(
        "Unexpected error serializing protobuf to in memory outputstream.", e);
  }
  return bos.toByteArray();
}
 
源代码8 项目: bazel   文件: XmlResourceValues.java

public static int serializeProtoDataValue(
    OutputStream output, SerializeFormat.DataValue.Builder builder) throws IOException {
  SerializeFormat.DataValue value = builder.build();
  value.writeDelimitedTo(output);
  return CodedOutputStream.computeUInt32SizeNoTag(value.getSerializedSize())
      + value.getSerializedSize();
}
 
源代码9 项目: bazel   文件: DataValueFile.java

@Override
public int serializeTo(DataSourceTable sourceTable, OutputStream output)
    throws IOException {
  SerializeFormat.DataValue.Builder builder = SerializeFormat.DataValue.newBuilder();
  SerializeFormat.DataValue value = builder.setSourceId(sourceTable.getSourceId(source)).build();
  value.writeDelimitedTo(output);
  return CodedOutputStream.computeUInt32SizeNoTag(value.getSerializedSize())
      + value.getSerializedSize();
}
 
源代码10 项目: jprotobuf   文件: CodedConstant.java

/**
 * Compute the number of bytes that would be needed to encode a particular value of arbitrary type, excluding tag.
 *
 * @param type The field's type.
 * @param value Object representing the field's value. Must be of the exact type which would be returned by
 *            {@link Message#getField(Descriptors.FieldDescriptor)} for this field.
 * @return the int
 */
public static int computeElementSizeNoTag(final WireFormat.FieldType type, final Object value) {
    switch (type) {
        // Note: Minor violation of 80-char limit rule here because this would
        // actually be harder to read if we wrapped the lines.
        case DOUBLE:
            return CodedOutputStream.computeDoubleSizeNoTag((Double) value);
        case FLOAT:
            return CodedOutputStream.computeFloatSizeNoTag((Float) value);
        case INT64:
            return CodedOutputStream.computeInt64SizeNoTag((Long) value);
        case UINT64:
            return CodedOutputStream.computeUInt64SizeNoTag((Long) value);
        case INT32:
            return CodedOutputStream.computeInt32SizeNoTag((Integer) value);
        case FIXED64:
            return CodedOutputStream.computeFixed64SizeNoTag((Long) value);
        case FIXED32:
            return CodedOutputStream.computeFixed32SizeNoTag((Integer) value);
        case BOOL:
            return CodedOutputStream.computeBoolSizeNoTag((Boolean) value);
        case STRING:
            return CodedOutputStream.computeStringSizeNoTag((String) value);
        case GROUP:
            return CodedOutputStream.computeGroupSizeNoTag((MessageLite) value);
        case BYTES:
            if (value instanceof ByteString) {
                return CodedOutputStream.computeBytesSizeNoTag((ByteString) value);
            } else {
                if (value instanceof Byte[]) {
                    return computeLengthDelimitedFieldSize(((Byte[]) value).length);
                }
                return CodedOutputStream.computeByteArraySizeNoTag((byte[]) value);
            }
        case UINT32:
            return CodedOutputStream.computeUInt32SizeNoTag((Integer) value);
        case SFIXED32:
            return CodedOutputStream.computeSFixed32SizeNoTag((Integer) value);
        case SFIXED64:
            return CodedOutputStream.computeSFixed64SizeNoTag((Long) value);
        case SINT32:
            return CodedOutputStream.computeSInt32SizeNoTag((Integer) value);
        case SINT64:
            return CodedOutputStream.computeSInt64SizeNoTag((Long) value);

        case MESSAGE:
            if (value instanceof LazyField) {
                return CodedOutputStream.computeLazyFieldSizeNoTag((LazyField) value);
            } else {
                return computeObjectSizeNoTag(value);
            }

        case ENUM:
            if (value instanceof Internal.EnumLite) {
                return CodedOutputStream.computeEnumSizeNoTag(((Internal.EnumLite) value).getNumber());
            } else {
                if (value instanceof EnumReadable) {
                    return CodedOutputStream.computeEnumSizeNoTag(((EnumReadable) value).value());
                } else if (value instanceof Enum) {
                    return CodedOutputStream.computeEnumSizeNoTag(((Enum) value).ordinal());
                }

                return CodedOutputStream.computeEnumSizeNoTag((Integer) value);
            }
    }

    throw new RuntimeException("There is no way to get here, but the compiler thinks otherwise.");
}
 
源代码11 项目: jprotobuf   文件: CodedConstant.java

/**
 * Compute length delimited field size.
 *
 * @param fieldLength the field length
 * @return the int
 */
public static int computeLengthDelimitedFieldSize(int fieldLength) {
    return CodedOutputStream.computeUInt32SizeNoTag(fieldLength) + fieldLength;
}