本文整理匯總了Java中com.google.protobuf.CodedOutputStream.computeInt32SizeNoTag方法的典型用法代碼示例。如果您正苦於以下問題:Java CodedOutputStream.computeInt32SizeNoTag方法的具體用法?Java CodedOutputStream.computeInt32SizeNoTag怎麽用?Java CodedOutputStream.computeInt32SizeNoTag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.protobuf.CodedOutputStream
的用法示例。
在下文中一共展示了CodedOutputStream.computeInt32SizeNoTag方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sizeOfMap
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
private static int sizeOfMap(MapSchema mapSchema, Map value) {
Set<Map.Entry> entrySet = value.entrySet();
Iterator<Map.Entry> it = entrySet.iterator();
int size = CodedOutputStream.computeInt32SizeNoTag(value.size());
while (it.hasNext()) {
Map.Entry entry = it.next();
if (entry.getKey() == null || entry.getValue() == null) {
continue;
}
int keySize = sizeOf(mapSchema.getKeySchema(), entry.getKey());
if (mapSchema.getKeySchema().getType().isAlwaysSkippable()) {
keySize += getSkippableIndexOverheadSize(mapSchema.getKeySchema().getType(), keySize);
}
int valSize = sizeOf(mapSchema.getValueSchema(), entry.getValue());
if (mapSchema.getValueSchema().getType().isAlwaysSkippable()) {
valSize += getSkippableIndexOverheadSize(mapSchema.getValueSchema().getType(), valSize);
}
size += keySize + valSize;
}
return size;
}
示例2: sizeOf
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
public static int sizeOf(Schema schema, Object value) {
if (value == null) {
return 0;
}
switch (schema.getType()) {
// natively skippable types
case INT:
return CodedOutputStream.computeInt32SizeNoTag((Integer) value);
case BOOLEAN:
return 1;
case LONG:
return CodedOutputStream.computeInt64SizeNoTag((Long) value);
case DOUBLE:
return CodedOutputStream.computeDoubleSizeNoTag((Double) value);
case FLOAT:
return CodedOutputStream.computeFloatSizeNoTag((Float) value);
case ENUM:
return CodedOutputStream.computeUInt32SizeNoTag(((EnumConstant) value).getOrd());
case ANY:
return CodedOutputStream.computeUInt32SizeNoTag(((Any) value).getSchemaId()) +
CodedOutputStream.computeBoolSizeNoTag(((Any) value).isId()) +
CodedOutputStream.computeUInt32SizeNoTag(((Any) value).getData().length()) + ((Any) value).getData().length();
// naturally length-delimited types
case BYTES:
return CodedOutputStream.computeUInt32SizeNoTag(((ByteArray) value).length()) + ((ByteArray) value).length();
case STRING:
return CodedOutputStream.computeStringSizeNoTag((String) value);
// complex types
case MAP:
return sizeOfMap((MapSchema) schema, (Map) value);
case LIST:
return sizeOfList((ListSchema) schema, (List) value);
case RECORD:
return sizeOfRecord((Record) value);
default:
throw new IllegalArgumentException("Unknown type " + schema.getType());
}
}
示例3: sizeOfList
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
private static int sizeOfList(ListSchema listSchema, List list) {
int size = CodedOutputStream.computeInt32SizeNoTag(list.size());
for (int i = 0; i < list.size(); i++) {
if (list.get(i) == null) {
continue;
}
int valSize = sizeOf(listSchema.getValueSchema(), list.get(i));
if (listSchema.getValueSchema().getType().isAlwaysSkippable()) {
valSize += getSkippableIndexOverheadSize(listSchema.getValueSchema().getType(), valSize);
}
size += valSize;
}
return size;
}
示例4: computeSize
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
/**
* get object size by {@link FieldType}.
*
* @param order the order
* @param o the o
* @param type the type
* @param list the list
* @param debug the debug
* @param path the path
* @return the int
*/
public static int computeSize(int order, Object o, FieldType type, boolean list, boolean debug, File path) {
int size = 0;
if (o == null) {
return size;
}
if (type == FieldType.OBJECT) {
Class cls = o.getClass();
Codec target = ProtobufProxy.create(cls, debug, path);
try {
size = target.size(o);
size = size + CodedOutputStream.computeRawVarint32Size(size);
return size + CodedOutputStream.computeTagSize(order);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
if (type == FieldType.STRING) {
size = CodedOutputStream.computeStringSizeNoTag(String.valueOf(o));
} else if (type == FieldType.BOOL) {
size = CodedOutputStream.computeBoolSizeNoTag(Boolean.valueOf(String.valueOf(o)));
} else if (type == FieldType.BYTES) {
byte[] bb = (byte[]) o;
size = CodedOutputStream.computeBytesSizeNoTag(ByteString.copyFrom(bb));
} else if (type == FieldType.DOUBLE) {
size = CodedOutputStream.computeDoubleSizeNoTag(Double.valueOf(o.toString()));
} else if (type == FieldType.FIXED32 || type == FieldType.INT32 || type == FieldType.SFIXED32
|| type == FieldType.SINT32 || type == FieldType.UINT32) {
size = CodedOutputStream.computeInt32SizeNoTag(Integer.valueOf(o.toString()));
} else if (type == FieldType.FIXED64 || type == FieldType.INT64 || type == FieldType.SFIXED64
|| type == FieldType.SINT64 || type == FieldType.UINT64) {
size = CodedOutputStream.computeInt64SizeNoTag(Long.valueOf(o.toString()));
} else if (type == FieldType.FLOAT) {
size = CodedOutputStream.computeFloatSizeNoTag(Float.valueOf(o.toString()));
} else if (type == FieldType.ENUM) {
if (o instanceof EnumReadable) {
size = CodedOutputStream.computeInt32SizeNoTag(((EnumReadable) o).value());
} else if (o instanceof Enum) {
size = CodedOutputStream.computeInt32SizeNoTag(((Enum) o).ordinal());
}
}
return size;
}
示例5: computeElementSizeNoTag
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
/**
* 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 {
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.");
}
示例6: computeSize
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
/**
* get object size by {@link FieldType}
*
* @param o
* @param type
* @return
*/
public static int computeSize(int order, Object o, FieldType type, boolean list, boolean debug, File path) {
int size = 0;
if (o == null) {
return size;
}
if (type == FieldType.OBJECT) {
Class cls = o.getClass();
Codec target = ProtobufProxy.create(cls);
try {
size = target.size(o);
size = size + CodedOutputStream.computeRawVarint32Size(size);
return size + CodedOutputStream.computeTagSize(order);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
if (type == FieldType.STRING) {
size = CodedOutputStream.computeStringSizeNoTag(String.valueOf(o));
} else if (type == FieldType.BOOL) {
size = CodedOutputStream.computeBoolSizeNoTag(Boolean.valueOf(String.valueOf(o)));
} else if (type == FieldType.BYTES) {
byte[] bb = (byte[]) o;
size = CodedOutputStream.computeBytesSizeNoTag(ByteString.copyFrom(bb));
} else if (type == FieldType.DOUBLE) {
size = CodedOutputStream.computeDoubleSizeNoTag(Double.valueOf(o.toString()));
} else if (type == FieldType.FIXED32 || type == FieldType.INT32 || type == FieldType.SFIXED32
|| type == FieldType.SINT32 || type == FieldType.UINT32) {
size = CodedOutputStream.computeInt32SizeNoTag(Integer.valueOf(o.toString()));
} else if (type == FieldType.FIXED64 || type == FieldType.INT64 || type == FieldType.SFIXED64
|| type == FieldType.SINT64 || type == FieldType.UINT64) {
size = CodedOutputStream.computeInt64SizeNoTag(Long.valueOf(o.toString()));
} else if (type == FieldType.FLOAT) {
size = CodedOutputStream.computeFloatSizeNoTag(Float.valueOf(o.toString()));
} else if (type == FieldType.ENUM) {
if (o instanceof EnumReadable) {
size = CodedOutputStream.computeInt32SizeNoTag(((EnumReadable) o).value());
} else if (o instanceof Enum) {
size = CodedOutputStream.computeInt32SizeNoTag(((Enum) o).ordinal());
}
}
return size;
}