当前位置: 首页>>代码示例>>Java>>正文


Java WireFormat.FieldType方法代码示例

本文整理汇总了Java中com.google.protobuf.WireFormat.FieldType方法的典型用法代码示例。如果您正苦于以下问题:Java WireFormat.FieldType方法的具体用法?Java WireFormat.FieldType怎么用?Java WireFormat.FieldType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.protobuf.WireFormat的用法示例。


在下文中一共展示了WireFormat.FieldType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseField

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
/**
 * Parses the field.
 *
 * @param <T> the generic type
 * @param input the input
 * @param extensionRegistry the extension registry
 * @param type the type
 * @param value the value
 * @return the t
 * @throws IOException Signals that an I/O exception has occurred.
 */
@SuppressWarnings("unchecked")
static <T> T parseField(CodedInputStream input, ExtensionRegistryLite extensionRegistry, WireFormat.FieldType type,
        T value) throws IOException {
    switch (type) {
        case MESSAGE:
            int length = input.readRawVarint32();
            final int oldLimit = input.pushLimit(length);
            Codec<? extends Object> codec = ProtobufProxy.create(value.getClass());
            T ret = (T) codec.decode(input.readRawBytes(length));
            input.popLimit(oldLimit);
            return ret;
        case ENUM:
            return (T) (java.lang.Integer) input.readEnum();
        case GROUP:
            throw new RuntimeException("Groups are not allowed in maps.");
        default:
            return (T) CodedConstant.readPrimitiveField(input, type, true);
    }
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:31,代码来源:MapEntryLite.java

示例2: computeElementSize

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
/**
 * Compute the number of bytes that would be needed to encode a single tag/value pair of arbitrary type.
 *
 * @param type The field's type.
 * @param number The field's number.
 * @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 computeElementSize(final WireFormat.FieldType type, final int number, final Object value) {
    int tagSize = CodedOutputStream.computeTagSize(number);
    if (type == WireFormat.FieldType.GROUP) {
        // Only count the end group tag for proto2 messages as for proto1 the end
        // group tag will be counted as a part of getSerializedSize().
        tagSize *= 2;
    }
    return tagSize + computeElementSizeNoTag(type, value);
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:19,代码来源:CodedConstant.java

示例3: writeElement

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
/**
 * Write a single tag-value pair to the stream.
 *
 * @param output The output stream.
 * @param type The field's type.
 * @param number The field's number.
 * @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.
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void writeElement(final CodedOutputStream output, final WireFormat.FieldType type, final int number,
        final Object value) throws IOException {
    // Special case for groups, which need a start and end tag; other fields
    // can just use writeTag() and writeFieldNoTag().
    if (type == WireFormat.FieldType.GROUP) {
        output.writeGroup(number, (MessageLite) value);
    } else {
        output.writeTag(number, getWireFormatForFieldType(type, false));
        writeElementNoTag(output, type, value);
    }
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:22,代码来源:CodedConstant.java

示例4: Metadata

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
/**
 * Instantiates a new metadata.
 *
 * @param descriptor the descriptor
 * @param defaultInstance the default instance
 * @param keyType the key type
 * @param valueType the value type
 */
public Metadata(Descriptor descriptor, MapEntry<K, V> defaultInstance, WireFormat.FieldType keyType,
        WireFormat.FieldType valueType) {
    super(keyType, defaultInstance.key, valueType, defaultInstance.value);
    this.descriptor = descriptor;
    this.parser = new AbstractParser<MapEntry<K, V>>() {

        @Override
        public MapEntry<K, V> parsePartialFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)
                throws InvalidProtocolBufferException {
            return new MapEntry<K, V>(Metadata.this, input, extensionRegistry);
        }
    };
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:22,代码来源:MapEntry.java

示例5: readPrimitiveField

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
/**
 * Read a field of any primitive type for immutable messages from a CodedInputStream. Enums, groups, and embedded
 * messages are not handled by this method.
 *
 * @param input The stream from which to read.
 * @param type Declared type of the field.
 * @param checkUtf8 When true, check that the input is valid utf8.
 * @return An object representing the field's value, of the exact type which would be returned by
 *         {@link Message#getField(Descriptors.FieldDescriptor)} for this field.
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static Object readPrimitiveField(CodedInputStream input, final WireFormat.FieldType type, boolean checkUtf8)
        throws IOException {
    switch (type) {
        case DOUBLE:
            return input.readDouble();
        case FLOAT:
            return input.readFloat();
        case INT64:
            return input.readInt64();
        case UINT64:
            return input.readUInt64();
        case INT32:
            return input.readInt32();
        case FIXED64:
            return input.readFixed64();
        case FIXED32:
            return input.readFixed32();
        case BOOL:
            return input.readBool();
        case STRING:
            if (checkUtf8) {
                return input.readStringRequireUtf8();
            } else {
                return input.readString();
            }
        case BYTES:
            return input.readBytes();
        case UINT32:
            return input.readUInt32();
        case SFIXED32:
            return input.readSFixed32();
        case SFIXED64:
            return input.readSFixed64();
        case SINT32:
            return input.readSInt32();
        case SINT64:
            return input.readSInt64();

        case GROUP:
            throw new IllegalArgumentException("readPrimitiveField() cannot handle nested groups.");
        case MESSAGE:
            throw new IllegalArgumentException("readPrimitiveField() cannot handle embedded messages.");
        case ENUM:
            // We don't handle enums because we don't know what to do if the
            // value is not recognized.
            throw new IllegalArgumentException("readPrimitiveField() cannot handle enums.");
    }

    throw new RuntimeException("There is no way to get here, but the compiler thinks otherwise.");
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:62,代码来源:CodedConstant.java

示例6: computeElementSizeNoTag

import com.google.protobuf.WireFormat; //导入方法依赖的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.");
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:73,代码来源:CodedConstant.java

示例7: newSingleScalarFields

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
public static ScalarFields newSingleScalarFields(WireFormat.FieldType type) {
  ScalarFields.Builder builder = ScalarFields.newBuilder();
  
  switch (type) {
    case BOOL:
      builder.setBooleanField(true);
      break;
    case BYTES:
      builder.setBytesField(ByteString.copyFromUtf8("Hello!"));
      break;
    case DOUBLE:
      builder.setDoubleField(-1.1D);
      break;
    case FIXED32:
      builder.setFixed32Field(111);
      break;
    case FIXED64:
      builder.setFixed64Field(111111);
      break;
    case FLOAT:
      builder.setFloatField(-1.2F);
      break;
    case INT32:
      builder.setInt32Field(-222);
      break;
    case INT64:
      builder.setInt64Field(-222222);
      break;
    case SFIXED32:
      builder.setSfixed32Field(333);
      break;
    case SFIXED64:
      builder.setSfixed64Field(333333);
      break;
    case SINT32:
      builder.setSint32Field(444);
      break;
    case SINT64:
      builder.setSint64Field(444444);
      break;
    case STRING:
      builder.setStringField("Hello!");
      break;
    case UINT32:
      builder.setUint32Field(555);
      break;
    case UINT64:
      builder.setUint64Field(555555);
      break;
    case ENUM:
    case MESSAGE:
    case GROUP:
    default:
      break;
  }
  
  return builder.build();
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:59,代码来源:ProtoUtils.java

示例8: newSingleScalarAndEnumFields

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
public static ScalarAndEnumFields newSingleScalarAndEnumFields(WireFormat.FieldType type) {
  ScalarAndEnumFields.Builder builder = ScalarAndEnumFields.newBuilder();
  
  switch (type) {
    case BOOL:
      builder.setBooleanField(true);
      break;
    case BYTES:
      builder.setBytesField(ByteString.copyFromUtf8("Hello!"));
      break;
    case DOUBLE:
      builder.setDoubleField(-1.1D);
      break;
    case FIXED32:
      builder.setFixed32Field(111);
      break;
    case FIXED64:
      builder.setFixed64Field(111111);
      break;
    case FLOAT:
      builder.setFloatField(-1.2F);
      break;
    case INT32:
      builder.setInt32Field(-222);
      break;
    case INT64:
      builder.setInt64Field(-222222);
      break;
    case SFIXED32:
      builder.setSfixed32Field(333);
      break;
    case SFIXED64:
      builder.setSfixed64Field(333333);
      break;
    case SINT32:
      builder.setSint32Field(444);
      break;
    case SINT64:
      builder.setSint64Field(444444);
      break;
    case STRING:
      builder.setStringField("Hello!");
      break;
    case UINT32:
      builder.setUint32Field(555);
      break;
    case UINT64:
      builder.setUint64Field(555555);
      break;
    case ENUM:
      builder.setEnumField(EnumField1.ONE);
      break;
    case GROUP:
    case MESSAGE:
    default:
      break;
  }
  
  return builder.build();
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:61,代码来源:ProtoUtils.java

示例9: newSingleScalarEnumMessageFields

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
public static ScalarEnumMessageFields newSingleScalarEnumMessageFields(WireFormat.FieldType type) {
  ScalarEnumMessageFields.Builder builder = ScalarEnumMessageFields.newBuilder();
  
  switch (type) {
    case BOOL:
      builder.setBooleanField(true);
      break;
    case BYTES:
      builder.setBytesField(ByteString.copyFromUtf8("Hello!"));
      break;
    case DOUBLE:
      builder.setDoubleField(-1.1D);
      break;
    case FIXED32:
      builder.setFixed32Field(111);
      break;
    case FIXED64:
      builder.setFixed64Field(111111);
      break;
    case FLOAT:
      builder.setFloatField(-1.2F);
      break;
    case INT32:
      builder.setInt32Field(-222);
      break;
    case INT64:
      builder.setInt64Field(-222222);
      break;
    case SFIXED32:
      builder.setSfixed32Field(333);
      break;
    case SFIXED64:
      builder.setSfixed64Field(333333);
      break;
    case SINT32:
      builder.setSint32Field(444);
      break;
    case SINT64:
      builder.setSint64Field(444444);
      break;
    case STRING:
      builder.setStringField("Hello!");
      break;
    case UINT32:
      builder.setUint32Field(555);
      break;
    case UINT64:
      builder.setUint64Field(555555);
      break;
    case ENUM:
      builder.setEnumField(EnumField1.ONE);
      break;
    case MESSAGE:
      builder.setMessageField(newScalarEnumMessageFields(false));
      break;
    case GROUP:
    default:
      break;
  }
  
  return builder.build();
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:63,代码来源:ProtoUtils.java

示例10: getWireFormatForFieldType

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
/**
 * Given a field type, return the wire type.
 *
 * @param type the type
 * @param isPacked the is packed
 * @return the wire format for field type
 * @returns One of the {@code WIRETYPE_} constants defined in {@link WireFormat}.
 */
static int getWireFormatForFieldType(final WireFormat.FieldType type, boolean isPacked) {
    if (isPacked) {
        return WireFormat.WIRETYPE_LENGTH_DELIMITED;
    } else {
        return type.getWireType();
    }
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:16,代码来源:CodedConstant.java

示例11: Metadata

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
/**
 * Instantiates a new metadata.
 *
 * @param keyType the key type
 * @param defaultKey the default key
 * @param valueType the value type
 * @param defaultValue the default value
 */
public Metadata(WireFormat.FieldType keyType, K defaultKey, WireFormat.FieldType valueType, V defaultValue) {
    this.keyType = keyType;
    this.defaultKey = defaultKey;
    this.valueType = valueType;
    this.defaultValue = defaultValue;
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:15,代码来源:MapEntryLite.java

示例12: MapEntry

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
/**
 *  Create a default MapEntry instance.
 *
 * @param descriptor the descriptor
 * @param keyType the key type
 * @param defaultKey the default key
 * @param valueType the value type
 * @param defaultValue the default value
 */
private MapEntry(Descriptor descriptor, WireFormat.FieldType keyType, K defaultKey, WireFormat.FieldType valueType,
        V defaultValue) {
    this.key = defaultKey;
    this.value = defaultValue;
    this.metadata = new Metadata<K, V>(descriptor, this, keyType, valueType);
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:16,代码来源:MapEntry.java

示例13: MapEntryLite

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
/**
 *  Creates a default MapEntryLite message instance.
 *
 * @param keyType the key type
 * @param defaultKey the default key
 * @param valueType the value type
 * @param defaultValue the default value
 */
private MapEntryLite(WireFormat.FieldType keyType, K defaultKey, WireFormat.FieldType valueType, V defaultValue) {
    this.metadata = new Metadata<K, V>(keyType, defaultKey, valueType, defaultValue);
    this.key = defaultKey;
    this.value = defaultValue;
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:14,代码来源:MapEntryLite.java

示例14: newDefaultInstance

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
/**
 * Creates a default MapEntryLite message instance.
 * 
 * This method is used by generated code to create the default instance for a map entry message. The created default
 * instance should be used to create new map entry messages of the same type. For each map entry message, only one
 * default instance should be created.
 *
 * @param <K> the key type
 * @param <V> the value type
 * @param keyType the key type
 * @param defaultKey the default key
 * @param valueType the value type
 * @param defaultValue the default value
 * @return the map entry lite
 */
public static <K, V> MapEntryLite<K, V> newDefaultInstance(WireFormat.FieldType keyType, K defaultKey,
        WireFormat.FieldType valueType, V defaultValue) {
    return new MapEntryLite<K, V>(keyType, defaultKey, valueType, defaultValue);
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:20,代码来源:MapEntryLite.java

示例15: newDefaultInstance

import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
/**
 * Create a default MapEntry instance. A default MapEntry instance should be created only once for each map entry
 * message type. Generated code should store the created default instance and use it later to create new MapEntry
 * messages of the same type.
 *
 * @param <K> the key type
 * @param <V> the value type
 * @param descriptor the descriptor
 * @param keyType the key type
 * @param defaultKey the default key
 * @param valueType the value type
 * @param defaultValue the default value
 * @return the map entry
 */
public static <K, V> MapEntry<K, V> newDefaultInstance(Descriptor descriptor, WireFormat.FieldType keyType,
        K defaultKey, WireFormat.FieldType valueType, V defaultValue) {
    return new MapEntry<K, V>(descriptor, keyType, defaultKey, valueType, defaultValue);
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:19,代码来源:MapEntry.java


注:本文中的com.google.protobuf.WireFormat.FieldType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。