/** * Compute the number of bytes that would be needed to encode a {@code * float} field, including tag. */ public static int computeFloatSize(int fieldNumber, float value) { return computeTagSize(fieldNumber) + LITTLE_ENDIAN_32_SIZE; }
/** * Compute the number of bytes that would be needed to encode an {@code * sfixed32} field, including tag. */ public static int computeSFixed32Size(int fieldNumber, int value) { return computeTagSize(fieldNumber) + LITTLE_ENDIAN_32_SIZE; }
/** * Compute the number of bytes that would be needed to encode an {@code * sfixed64} field, including tag. */ public static int computeSFixed64Size(int fieldNumber, long value) { return computeTagSize(fieldNumber) + LITTLE_ENDIAN_64_SIZE; }
/** * Compute the number of bytes that would be needed to encode a {@code * fixed64} field, including tag. */ public static int computeFixed64Size(int fieldNumber, long value) { return computeTagSize(fieldNumber) + LITTLE_ENDIAN_64_SIZE; }
/** * Compute the number of bytes that would be needed to encode a {@code * double} field, including tag. */ public static int computeDoubleSize(int fieldNumber, double value) { return computeTagSize(fieldNumber) + LITTLE_ENDIAN_64_SIZE; }
/** * Compute the number of bytes that would be needed to encode a {@code * fixed32} field, including tag. */ public static int computeFixed32Size(int fieldNumber, int value) { return computeTagSize(fieldNumber) + LITTLE_ENDIAN_32_SIZE; }
/** * Compute the number of bytes that would be needed to encode a {@code bool} * field, including tag. */ public static int computeBoolSize(int fieldNumber, boolean value) { return computeTagSize(fieldNumber) + 1; }
/** * Compute the number of bytes that would be needed to encode an {@code * int32} field, including tag. */ public static int computeInt32Size(int fieldNumber, int value) { if (value >= 0) { return computeTagSize(fieldNumber) + computeRawVarint32Size(value); } else { // Must sign-extend. return computeTagSize(fieldNumber) + 10; } }
/** * Compute the number of bytes that would be needed to encode a {@code * bytes} field, including tag. */ public static int computeBytesSize(int fieldNumber, Buffer value) { return computeTagSize(fieldNumber) + computeRawVarint32Size(value.length) + value.length; }
/** * Compute the number of bytes that would be needed to encode a {@code * uint64} field, including tag. */ public static int computeUInt64Size(int fieldNumber, long value) { return computeTagSize(fieldNumber) + computeRawVarint64Size(value); }
/** * Compute the number of bytes that would be needed to encode an enum field, * including tag. Caller is responsible for converting the enum value to its * numeric value. */ public static int computeEnumSize(int fieldNumber, int value) { return computeTagSize(fieldNumber) + computeRawVarint32Size(value); }
/** * Compute the number of bytes that would be needed to encode an {@code * int64} field, including tag. */ public static int computeInt64Size(int fieldNumber, long value) { return computeTagSize(fieldNumber) + computeRawVarint64Size(value); }
/** * Compute the number of bytes that would be needed to encode a {@code * string} field, including tag. */ public static int computeStringSize(int fieldNumber, String value) { try { byte[] bytes = value.getBytes("UTF-8"); return computeTagSize(fieldNumber) + computeRawVarint32Size(bytes.length) + bytes.length; } catch (java.io.UnsupportedEncodingException e) { throw new RuntimeException("UTF-8 not supported.", e); } }
/** * Compute the number of bytes that would be needed to encode a {@code * uint32} field, including tag. */ public static int computeUInt32Size(int fieldNumber, int value) { return computeTagSize(fieldNumber) + computeRawVarint32Size(value); }
static protected int computeGroupSize(int tag, BaseMessage message) { return CodedOutputStream.computeTagSize(tag) * 2 + message.serializedSizeUnframed(); }
static protected int computeMessageSize(int tag, BaseMessage message) { return CodedOutputStream.computeTagSize(tag) + message.serializedSizeFramed(); }
public static int computeMessageSize(int tag, MessageBuffer message) { return CodedOutputStream.computeTagSize(tag) + message.serializedSizeFramed(); }
/** * Compute the number of bytes that would be needed to encode an {@code * sint64} field, including tag. */ public static int computeSInt64Size(int fieldNumber, long value) { return computeTagSize(fieldNumber) + computeRawVarint64Size(encodeZigZag64(value)); }
/** * Compute the number of bytes that would be needed to encode an {@code * sint32} field, including tag. */ public static int computeSInt32Size(int fieldNumber, int value) { return computeTagSize(fieldNumber) + computeRawVarint32Size(encodeZigZag32(value)); }