io.protostuff.compiler.model.ScalarFieldType Java Examples
The following examples show how to use
io.protostuff.compiler.model.ScalarFieldType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 6 votes |
/** * Returns a java field default value for proto field. */ public static String getDefaultValue(Field field) { FieldType type = field.getType(); if (type instanceof ScalarFieldType) { return ScalarFieldTypeUtil.getDefaultValue((ScalarFieldType) type); } if (type instanceof Message) { Message m = (Message) type; return UserTypeUtil.getCanonicalName(m) + ".getDefaultInstance()"; } if (type instanceof Enum) { Enum anEnum = (Enum) type; String defaultValue; List<EnumConstant> constants = anEnum.getConstants(); if (constants.isEmpty()) { defaultValue = "UNRECOGNIZED"; } else { DynamicMessage options = field.getOptions(); defaultValue = options.containsKey(DEFAULT) ? options.get(DEFAULT).getEnumName() : constants.get(0).getName(); } return UserTypeUtil.getCanonicalName(anEnum) + "." + defaultValue; } throw new IllegalArgumentException(String.valueOf(type)); }
Example #2
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 6 votes |
/** * Returns map field value type name. */ public static String getMapFieldValueType(Field field) { FieldType type = field.getType(); if (!(type instanceof Message)) { throw new IllegalArgumentException(field.toString()); } Message entryType = (Message) type; Type valueType = entryType.getField(MAP_ENTRY_VALUE).getType(); String v; if (valueType instanceof ScalarFieldType) { ScalarFieldType scalarValueType = (ScalarFieldType) valueType; v = ScalarFieldTypeUtil.getWrapperType(scalarValueType); } else { UserType userType = (UserType) valueType; v = UserTypeUtil.getCanonicalName(userType); } return v; }
Example #3
Source File: OptionsPostProcessor.java From protostuff-compiler with Apache License 2.0 | 6 votes |
private void checkFieldValue(ProtoContext context, Descriptor descriptor, Field field, DynamicMessage.Value value) { String fieldName = field.getName(); FieldType fieldType = field.getType(); DynamicMessage.Value.Type valueType = value.getType(); if (fieldType instanceof ScalarFieldType) { ScalarFieldType scalarFieldType = (ScalarFieldType) fieldType; if (!isAssignableFrom(scalarFieldType, value)) { throw new ParserException(value, "Cannot set option '%s': expected %s value", fieldName, fieldType); } } else if (fieldType instanceof Enum) { Enum anEnum = (Enum) fieldType; Set<String> allowedNames = anEnum.getConstantNames(); if (valueType != DynamicMessage.Value.Type.ENUM || !allowedNames.contains(value.getEnumName())) { throw new ParserException(value, "Cannot set option '%s': expected enum = %s", fieldName, allowedNames); } } else if (fieldType instanceof Message) { if (valueType != DynamicMessage.Value.Type.MESSAGE) { throw new ParserException(value, "Cannot set option '%s': expected message value", fieldName); } Message message = (Message) fieldType; processOptions(context, message, descriptor, value.getMessage()); } else { throw new IllegalStateException("Unknown field type: " + fieldType); } }
Example #4
Source File: OneofTest.java From protostuff-compiler with Apache License 2.0 | 6 votes |
@Test public void testSample() throws Exception { ProtoContext context = importer.importFile(new ClasspathFileReader(), "protostuff_unittest/oneof_sample.proto"); Message m = context.resolve(".protostuff_unittest.SampleMessage", Message.class); Oneof oneof = m.getOneof("test_oneof"); assertEquals("test_oneof", oneof.getName()); assertEquals(".protostuff_unittest.SampleMessage.", oneof.getNamespace()); Field name = oneof.getField("name"); assertEquals(ScalarFieldType.STRING, name.getType()); assertEquals(4, name.getTag()); assertFalse(name.hasModifier()); Field subMessage = oneof.getField("sub_message"); assertEquals("SubMessage", subMessage.getType().getName()); assertEquals(9, subMessage.getTag()); assertFalse(subMessage.hasModifier()); }
Example #5
Source File: MapTest.java From protostuff-compiler with Apache License 2.0 | 5 votes |
private void checkMap(Message m, String mapFieldName, ScalarFieldType keyType, String valueType, int tag) { Field field = m.getField(mapFieldName); Message type = (Message) field.getType(); assertEquals(keyType, type.getField(MAP_ENTRY_KEY).getType()); assertEquals(valueType, type.getField(MAP_ENTRY_VALUE).getType().getFullyQualifiedName()); assertEquals(tag, field.getTag()); }
Example #6
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns a java field type for proto field. */ public static String getFieldType(Field field) { FieldType type = field.getType(); if (type instanceof ScalarFieldType) { ScalarFieldType scalarFieldType = (ScalarFieldType) type; return ScalarFieldTypeUtil.getPrimitiveType(scalarFieldType); } if (type instanceof UserType) { UserType userType = (UserType) type; return UserTypeUtil.getCanonicalName(userType); } throw new IllegalArgumentException(field.toString()); }
Example #7
Source File: ScalarFieldTypeUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
@Nonnull private static String getNonNull(Map<ScalarFieldType, String> map, ScalarFieldType type) { String value = map.get(type); if (value == null) { throw new IllegalArgumentException(String.valueOf(type)); } return value; }
Example #8
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns a java field type for proto repeated field. */ public static String getRepeatedFieldType(Field field) { FieldType type = field.getType(); if (type instanceof ScalarFieldType) { ScalarFieldType scalarFieldType = (ScalarFieldType) type; return LIST + "<" + ScalarFieldTypeUtil.getWrapperType(scalarFieldType) + ">"; } if (type instanceof UserType) { UserType userType = (UserType) type; return LIST + "<" + UserTypeUtil.getCanonicalName(userType) + ">"; } throw new IllegalArgumentException(field.toString()); }
Example #9
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns an iterable wrapper for proto repeated field. */ public static String getIterableFieldType(Field field) { FieldType type = field.getType(); if (type instanceof ScalarFieldType) { ScalarFieldType scalarFieldType = (ScalarFieldType) type; return ITERABLE + "<" + ScalarFieldTypeUtil.getWrapperType(scalarFieldType) + ">"; } if (type instanceof UserType) { UserType userType = (UserType) type; return ITERABLE + "<" + UserTypeUtil.getCanonicalName(userType) + ">"; } throw new IllegalArgumentException(field.toString()); }
Example #10
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns a java wrapper field type for proto scalar field. */ public static String getWrapperFieldType(Field field) { FieldType type = field.getType(); if (type instanceof ScalarFieldType) { ScalarFieldType scalarFieldType = (ScalarFieldType) type; return ScalarFieldTypeUtil.getWrapperType(scalarFieldType); } if (type instanceof UserType) { UserType userType = (UserType) type; return UserTypeUtil.getCanonicalName(userType); } throw new IllegalArgumentException(field.toString()); }
Example #11
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
private static String protostuffIoMethodName(Field field, String operation) { FieldType type = field.getType(); if (!(type instanceof ScalarFieldType)) { throw new IllegalArgumentException(String.valueOf(type)); } ScalarFieldType fieldType = (ScalarFieldType) type; String name = PROTOSTUFF_IO_NAME.get(fieldType); if (name == null) { throw new IllegalArgumentException(String.valueOf(type)); } return operation + name; }
Example #12
Source File: ExtensionsTest.java From protostuff-compiler with Apache License 2.0 | 5 votes |
@Test public void testBasicExtensions() throws Exception { ProtoContext context = importer.importFile(new ClasspathFileReader(), "protostuff_unittest/extensions_sample.proto"); ExtensionRegistry er = context.getExtensionRegistry(); Message a = context.resolve(Message.class, ".protostuff_unittest.A"); Map<String, Field> aFields = er.getExtensionFields(a); assertEquals(2, aFields.size()); Field ay = aFields.get(".protostuff_unittest.ay"); assertEquals(ScalarFieldType.INT32, ay.getType()); assertEquals(42, ay.getTag()); Field az = aFields.get(".protostuff_unittest.az"); assertEquals(ScalarFieldType.INT32, az.getType()); assertEquals(43, az.getTag()); assertEquals(1, a.getExtensionRanges().size()); Range aRange = a.getExtensionRanges().get(0); assertEquals(10, aRange.getFrom()); assertEquals(Field.MAX_TAG_VALUE, aRange.getTo()); Message b = context.resolve(Message.class, ".protostuff_unittest.A.B"); Map<String, Field> bFields = er.getExtensionFields(b); assertEquals(2, bFields.size()); Field by = bFields.get(".protostuff_unittest.A.by"); assertEquals(ScalarFieldType.INT32, by.getType()); assertEquals(52, by.getTag()); Field bz = bFields.get(".protostuff_unittest.bz"); assertEquals(ScalarFieldType.INT32, bz.getType()); assertEquals(53, bz.getTag()); assertEquals(1, b.getExtensionRanges().size()); Range bRange = b.getExtensionRanges().get(0); assertEquals(10, bRange.getFrom()); assertEquals(1000, bRange.getTo()); }
Example #13
Source File: TypeResolverPostProcessor.java From protostuff-compiler with Apache License 2.0 | 5 votes |
private FieldType resolveFieldType(Element source, ProtoContext context, Deque<String> scopeLookupList, String typeName) { ScalarFieldType scalarFieldType = ScalarFieldType.getByName(typeName); if (scalarFieldType != null) { return scalarFieldType; } else { return resolveUserType(source, context, scopeLookupList, typeName); } }
Example #14
Source File: OptionsPostProcessor.java From protostuff-compiler with Apache License 2.0 | 5 votes |
private boolean isAssignableFrom(ScalarFieldType target, DynamicMessage.Value value) { ValueChecker checker = SCALAR_ASSIGNMENT_CHECKS.get(target); if (checker == null) { throw new IllegalStateException("Unknown field type: " + target); } return checker.apply(value); }
Example #15
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns map field key type name. */ public static String getMapFieldKeyType(Field field) { FieldType type = field.getType(); if (!(type instanceof Message)) { throw new IllegalArgumentException(field.toString()); } Message entryType = (Message) type; ScalarFieldType keyType = (ScalarFieldType) entryType.getField(MAP_ENTRY_KEY).getType(); return ScalarFieldTypeUtil.getWrapperType(keyType); }
Example #16
Source File: SerializerSchemaManager.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
protected <T> FieldSchema<T> createScalarField(Field protoField, PropertyDescriptor propertyDescriptor) { if (protoField.getType().isEnum()) { return EnumWriteSchemas.create(protoField, propertyDescriptor); } switch ((ScalarFieldType) protoField.getType()) { case INT32: return Int32WriteSchemas.create(protoField, propertyDescriptor); case UINT32: return UInt32WriteSchemas.create(protoField, propertyDescriptor); case SINT32: return SInt32WriteSchemas.create(protoField, propertyDescriptor); case FIXED32: return Fixed32WriteSchemas.create(protoField, propertyDescriptor); case SFIXED32: return SFixed32WriteSchemas.create(protoField, propertyDescriptor); case INT64: return Int64WriteSchemas.create(protoField, propertyDescriptor); case UINT64: return UInt64WriteSchemas.create(protoField, propertyDescriptor); case SINT64: return SInt64WriteSchemas.create(protoField, propertyDescriptor); case FIXED64: return Fixed64WriteSchemas.create(protoField, propertyDescriptor); case SFIXED64: return SFixed64WriteSchemas.create(protoField, propertyDescriptor); case FLOAT: return FloatWriteSchemas.create(protoField, propertyDescriptor); case DOUBLE: return DoubleWriteSchemas.create(protoField, propertyDescriptor); case BOOL: return BoolWriteSchemas.create(protoField, propertyDescriptor); case STRING: return StringWriteSchemas.create(protoField, propertyDescriptor); case BYTES: return BytesWriteSchemas.create(protoField, propertyDescriptor); default: throw new IllegalStateException("unknown proto field type: " + protoField.getType()); } }
Example #17
Source File: ProtoUtils.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
/** * all supported type, default to packed * @param protoField * @return */ public static boolean isSupportPacked(Field protoField) { if (protoField.getType().isEnum()) { return true; } if (protoField.getType().isScalar()) { ScalarFieldType scalarFieldType = (ScalarFieldType) protoField.getType(); return scalarFieldType != ScalarFieldType.STRING && scalarFieldType != ScalarFieldType.BYTES; } return false; }
Example #18
Source File: DeserializerSchemaManager.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
protected <T> FieldSchema<T> createScalarField(Field protoField, PropertyDescriptor propertyDescriptor) { if (protoField.getType().isEnum()) { return EnumsReadSchemas.create(protoField, propertyDescriptor); } switch ((ScalarFieldType) protoField.getType()) { case INT32: return Int32ReadSchemas.create(protoField, propertyDescriptor); case UINT32: return UInt32ReadSchemas.create(protoField, propertyDescriptor); case SINT32: return SInt32ReadSchemas.create(protoField, propertyDescriptor); case FIXED32: return Fixed32ReadSchemas.create(protoField, propertyDescriptor); case SFIXED32: return SFixed32ReadSchemas.create(protoField, propertyDescriptor); case INT64: return Int64ReadSchemas.create(protoField, propertyDescriptor); case UINT64: return UInt64ReadSchemas.create(protoField, propertyDescriptor); case SINT64: return SInt64ReadSchemas.create(protoField, propertyDescriptor); case FIXED64: return Fixed64ReadSchemas.create(protoField, propertyDescriptor); case SFIXED64: return SFixed64ReadSchemas.create(protoField, propertyDescriptor); case FLOAT: return FloatReadSchemas.create(protoField, propertyDescriptor); case DOUBLE: return DoubleReadSchemas.create(protoField, propertyDescriptor); case BOOL: return BoolReadSchemas.create(protoField, propertyDescriptor); case STRING: return StringReadSchemas.create(protoField, propertyDescriptor); case BYTES: return BytesReadSchemas.create(protoField, propertyDescriptor); default: throw new IllegalStateException("unknown proto field type: " + protoField.getType()); } }
Example #19
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 4 votes |
/** * Check if field type is numeric. */ public static boolean isNumericType(Field field) { FieldType type = field.getType(); boolean scalar = type instanceof ScalarFieldType; return scalar && !(BOOL.equals(type) || STRING.equals(type) || BYTES.equals(type)); }
Example #20
Source File: ScalarFieldTypeUtil.java From protostuff-compiler with Apache License 2.0 | 4 votes |
@Nonnull public static String getDefaultValue(ScalarFieldType type) { return getNonNull(DEFAULT_VALUE, type); }
Example #21
Source File: ScalarFieldTypeUtil.java From protostuff-compiler with Apache License 2.0 | 4 votes |
@Nonnull public static String getPrimitiveType(ScalarFieldType type) { return getNonNull(PRIMITIVE_TYPE, type); }
Example #22
Source File: ScalarFieldTypeUtil.java From protostuff-compiler with Apache License 2.0 | 4 votes |
@Nonnull public static String getWrapperType(ScalarFieldType type) { return getNonNull(WRAPPER_TYPE, type); }
Example #23
Source File: JavaExtensionProvider.java From protostuff-compiler with Apache License 2.0 | 4 votes |
/** * Create new instance of java extension provider. */ public JavaExtensionProvider() { registerProperty(Proto.class, "javaPackage", ProtoUtil::getPackage); registerProperty(Proto.class, "javaPackagePath", ProtoUtil::getPackagePath); registerProperty(ScalarFieldType.class, "javaWrapperType", ScalarFieldTypeUtil::getWrapperType); registerProperty(ScalarFieldType.class, "javaPrimitiveType", ScalarFieldTypeUtil::getPrimitiveType); registerProperty(Message.class, JAVA_NAME, UserTypeUtil::getClassName); registerProperty(Message.class, "javaFullName", UserTypeUtil::getCanonicalName); registerProperty(Message.class, "hasFields", MessageUtil::hasFields); registerProperty(Message.class, "javaBitFieldNames", MessageUtil::bitFieldNames); registerProperty(Field.class, "javaType", MessageFieldUtil::getFieldType); registerProperty(Field.class, "javaRepeatedType", MessageFieldUtil::getRepeatedFieldType); registerProperty(Field.class, "javaIterableType", MessageFieldUtil::getIterableFieldType); registerProperty(Field.class, "javaWrapperType", MessageFieldUtil::getWrapperFieldType); registerProperty(Field.class, JAVA_NAME, MessageFieldUtil::getFieldName); registerProperty(Field.class, "jsonName", MessageFieldUtil::getJsonFieldName); registerProperty(Field.class, "javaGetterName", MessageFieldUtil::getFieldGetterName); registerProperty(Field.class, "javaSetterName", MessageFieldUtil::getFieldSetterName); registerProperty(Field.class, "javaWitherName", MessageFieldUtil::getFieldWitherName); registerProperty(Field.class, "javaCleanerName", MessageFieldUtil::getFieldCleanerName); registerProperty(Field.class, "javaEnumValueGetterName", MessageFieldUtil::getEnumFieldValueGetterName); registerProperty(Field.class, "javaEnumValueSetterName", MessageFieldUtil::getEnumFieldValueSetterName); registerProperty(Field.class, "javaRepeatedGetterName", MessageFieldUtil::getRepeatedFieldGetterName); registerProperty(Field.class, "javaRepeatedEnumConverterName", MessageFieldUtil::getRepeatedEnumConverterName); registerProperty(Field.class, "javaRepeatedSetterName", MessageFieldUtil::getRepeatedFieldSetterName); registerProperty(Field.class, "javaRepeatedAdderName", MessageFieldUtil::getRepeatedFieldAdderName); registerProperty(Field.class, "javaRepeatedAddAllName", MessageFieldUtil::getRepeatedFieldAddAllName); registerProperty(Field.class, "javaRepeatedEnumValueSetterName", MessageFieldUtil::getRepeatedEnumValueSetterName); registerProperty(Field.class, "javaRepeatedEnumValueAdderName", MessageFieldUtil::getRepeatedEnumValueAdderName); registerProperty(Field.class, "javaRepeatedEnumValueAddAllName", MessageFieldUtil::getRepeatedEnumValueAddAllName); registerProperty(Field.class, "javaRepeatedEnumValueGetterName", MessageFieldUtil::getRepeatedEnumFieldValueGetterName); registerProperty(Field.class, "javaRepeatedEnumValueGetterByIndexName", MessageFieldUtil::javaRepeatedEnumValueGetterByIndexName); registerProperty(Field.class, "javaRepeatedGetCountMethodName", MessageFieldUtil::repeatedGetCountMethodName); registerProperty(Field.class, "javaRepeatedGetByIndexMethodName", MessageFieldUtil::repeatedGetByIndexMethodName); registerProperty(Field.class, "javaMapGetterName", MessageFieldUtil::getMapGetterName); registerProperty(Field.class, "javaMapType", MessageFieldUtil::getMapFieldType); registerProperty(Field.class, "javaMapKeyType", MessageFieldUtil::getMapFieldKeyType); registerProperty(Field.class, "javaMapValueType", MessageFieldUtil::getMapFieldValueType); registerProperty(Field.class, "javaMapAdderName", MessageFieldUtil::getMapFieldAdderName); registerProperty(Field.class, "javaMapAddAllName", MessageFieldUtil::getMapFieldAddAllName); registerProperty(Field.class, "javaMapGetByKeyMethodName", MessageFieldUtil::mapGetByKeyMethodName); registerProperty(Field.class, "javaIsMessage", MessageFieldUtil::isMessage); registerProperty(Field.class, "javaHasMethodName", MessageFieldUtil::getHasMethodName); registerProperty(Field.class, "javaBuilderGetterName", MessageFieldUtil::getBuilderGetterName); registerProperty(Field.class, "javaBuilderSetterName", MessageFieldUtil::getBuilderSetterName); registerProperty(Field.class, "javaBuilderRepeatedSetterName", MessageFieldUtil::getRepeatedBuilderSetterName); registerProperty(Field.class, "javaDefaultValue", MessageFieldUtil::getDefaultValue); registerProperty(Field.class, "javaIsNumericType", MessageFieldUtil::isNumericType); registerProperty(Field.class, "javaIsBooleanType", MessageFieldUtil::isBooleanType); registerProperty(Field.class, "javaIsScalarNullableType", MessageFieldUtil::isScalarNullableType); registerProperty(Field.class, "protostuffReadMethod", MessageFieldUtil::protostuffReadMethod); registerProperty(Field.class, "protostuffWriteMethod", MessageFieldUtil::protostuffWriteMethod); registerProperty(Field.class, "toStringPart", MessageFieldUtil::toStringPart); registerProperty(Field.class, "javaBitFieldName", MessageFieldUtil::bitFieldName); registerProperty(Field.class, "javaBitFieldIndex", MessageFieldUtil::bitFieldIndex); registerProperty(Field.class, "javaBitFieldMask", MessageFieldUtil::bitFieldMask); registerProperty(Field.class, "javaOneofConstantName", MessageFieldUtil::javaOneofConstantName); registerProperty(Oneof.class, JAVA_NAME, MessageUtil::getOneofEnumClassName); registerProperty(Oneof.class, "javaNotSetConstantName", MessageUtil::getOneofNotSetConstantName); registerProperty(Oneof.class, "javaCaseGetterName", MessageUtil::getOneofCaseGetterName); registerProperty(Oneof.class, "javaCaseCleanerName", MessageUtil::getOneofCaseCleanerName); registerProperty(Oneof.class, "javaFieldName", MessageUtil::getOneofFieldName); registerProperty(Oneof.class, "javaCaseFieldName", MessageUtil::getOneofCaseFieldName); registerProperty(Enum.class, JAVA_NAME, UserTypeUtil::getClassName); registerProperty(Enum.class, "javaFullName", UserTypeUtil::getCanonicalName); registerProperty(EnumConstant.class, JAVA_NAME, EnumUtil::getName); registerProperty(Service.class, JAVA_NAME, ServiceUtil::getClassName); registerProperty(ServiceMethod.class, JAVA_NAME, ServiceUtil::getMethodName); }
Example #24
Source File: FieldTypeUtils.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
public static FieldType convert(io.protostuff.compiler.model.FieldType fieldType) { if (fieldType.isEnum()) { return FieldType.ENUM; } if (fieldType.isScalar()) { switch ((ScalarFieldType) fieldType) { case INT32: return FieldType.INT32; case INT64: return FieldType.INT64; case UINT32: return FieldType.UINT32; case UINT64: return FieldType.UINT64; case SINT32: return FieldType.SINT32; case SINT64: return FieldType.SINT64; case FIXED32: return FieldType.FIXED32; case FIXED64: return FieldType.FIXED64; case SFIXED32: return FieldType.SFIXED32; case SFIXED64: return FieldType.SFIXED64; case FLOAT: return FieldType.FLOAT; case DOUBLE: return FieldType.DOUBLE; case BOOL: return FieldType.BOOL; case STRING: return FieldType.STRING; case BYTES: return FieldType.BYTES; default: throw new IllegalStateException("bug: miss process of " + fieldType); } } if (fieldType.isMessage()) { return FieldType.MESSAGE; } throw new IllegalStateException("bug: miss process of " + fieldType); }
Example #25
Source File: SerializerSchemaManager.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
@Override protected <T> FieldSchema<T> createRepeatedSchema(Field protoField, PropertyDescriptor propertyDescriptor) { boolean packed = ProtoUtils.isPacked(protoField); if (protoField.getType().isEnum()) { return packed ? EnumPackedWriteSchemas.create(protoField, propertyDescriptor) : EnumNotPackedWriteSchemas.create(protoField, propertyDescriptor); } if (protoField.getType().isScalar()) { switch ((ScalarFieldType) protoField.getType()) { case INT32: return packed ? Int32PackedWriteSchemas.create(protoField, propertyDescriptor) : Int32NotPackedWriteSchemas.create(protoField, propertyDescriptor); case UINT32: return packed ? UInt32PackedWriteSchemas.create(protoField, propertyDescriptor) : UInt32NotPackedWriteSchemas.create(protoField, propertyDescriptor); case SINT32: return packed ? SInt32PackedWriteSchemas.create(protoField, propertyDescriptor) : SInt32NotPackedWriteSchemas.create(protoField, propertyDescriptor); case FIXED32: return packed ? Fixed32PackedWriteSchemas.create(protoField, propertyDescriptor) : Fixed32NotPackedWriteSchemas.create(protoField, propertyDescriptor); case SFIXED32: return packed ? SFixed32PackedWriteSchemas.create(protoField, propertyDescriptor) : SFixed32NotPackedWriteSchemas.create(protoField, propertyDescriptor); case INT64: return packed ? Int64PackedWriteSchemas.create(protoField, propertyDescriptor) : Int64NotPackedWriteSchemas.create(protoField, propertyDescriptor); case UINT64: return packed ? UInt64PackedWriteSchemas.create(protoField, propertyDescriptor) : UInt64NotPackedWriteSchemas.create(protoField, propertyDescriptor); case SINT64: return packed ? SInt64PackedWriteSchemas.create(protoField, propertyDescriptor) : SInt64NotPackedWriteSchemas.create(protoField, propertyDescriptor); case FIXED64: return packed ? Fixed64PackedWriteSchemas.create(protoField, propertyDescriptor) : Fixed64NotPackedWriteSchemas.create(protoField, propertyDescriptor); case SFIXED64: return packed ? SFixed64PackedWriteSchemas.create(protoField, propertyDescriptor) : SFixed64NotPackedWriteSchemas.create(protoField, propertyDescriptor); case FLOAT: return packed ? FloatPackedWriteSchemas.create(protoField, propertyDescriptor) : FloatNotPackedWriteSchemas.create(protoField, propertyDescriptor); case DOUBLE: return packed ? DoublePackedWriteSchemas.create(protoField, propertyDescriptor) : DoubleNotPackedWriteSchemas.create(protoField, propertyDescriptor); case BOOL: return packed ? BoolPackedWriteSchemas.create(protoField, propertyDescriptor) : BoolNotPackedWriteSchemas.create(protoField, propertyDescriptor); case STRING: return StringsRepeatedWriteSchemas.create(protoField, propertyDescriptor); case BYTES: return BytesRepeatedWriteSchemas.create(protoField, propertyDescriptor); } } if (ProtoUtils.isAnyField(protoField)) { FieldSchema<T> anySchema = new AnySchema<>(protoMapper, protoField, propertyDescriptor); return AnyRepeatedWriteSchemas.create(protoField, propertyDescriptor, anySchema); } if (protoField.getType().isMessage()) { JavaType contentType = propertyDescriptor.getJavaType().getContentType(); if (contentType == null) { contentType = ProtoConst.OBJECT_TYPE; } SchemaEx<Object> contentSchema = getOrCreateMessageSchema((Message) protoField.getType(), contentType); if (isWrapProperty((Message) protoField.getType())) { return PropertyWrapperRepeatedWriteSchemas.create(protoField, propertyDescriptor, contentSchema); } return MessagesRepeatedWriteSchemas.create(protoField, propertyDescriptor, contentSchema); } ProtoUtils.throwNotSupportWrite(protoField, propertyDescriptor.getJavaType().getRawClass()); return null; }
Example #26
Source File: DeserializerSchemaManager.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
@Override protected <T> FieldSchema<T> createRepeatedSchema(Field protoField, PropertyDescriptor propertyDescriptor) { boolean packed = ProtoUtils.isPacked(protoField); if (protoField.getType().isEnum()) { return packed ? EnumPackedReadSchemas.create(protoField, propertyDescriptor) : EnumNotPackedReadSchemas.create(protoField, propertyDescriptor); } if (protoField.getType().isScalar()) { switch ((ScalarFieldType) protoField.getType()) { case INT32: return packed ? Int32PackedReadSchemas.create(protoField, propertyDescriptor) : Int32NotPackedReadSchemas.create(protoField, propertyDescriptor); case UINT32: return packed ? UInt32PackedReadSchemas.create(protoField, propertyDescriptor) : UInt32NotPackedReadSchemas.create(protoField, propertyDescriptor); case SINT32: return packed ? SInt32PackedReadSchemas.create(protoField, propertyDescriptor) : SInt32NotPackedReadSchemas.create(protoField, propertyDescriptor); case FIXED32: return packed ? Fixed32PackedReadSchemas.create(protoField, propertyDescriptor) : Fixed32NotPackedReadSchemas.create(protoField, propertyDescriptor); case SFIXED32: return packed ? SFixed32PackedReadSchemas.create(protoField, propertyDescriptor) : SFixed32NotPackedReadSchemas.create(protoField, propertyDescriptor); case INT64: return packed ? Int64PackedReadSchemas.create(protoField, propertyDescriptor) : Int64NotPackedReadSchemas.create(protoField, propertyDescriptor); case UINT64: return packed ? UInt64PackedReadSchemas.create(protoField, propertyDescriptor) : UInt64NotPackedReadSchemas.create(protoField, propertyDescriptor); case SINT64: return packed ? SInt64PackedReadSchemas.create(protoField, propertyDescriptor) : SInt64NotPackedReadSchemas.create(protoField, propertyDescriptor); case FIXED64: return packed ? Fixed64PackedReadSchemas.create(protoField, propertyDescriptor) : Fixed64NotPackedReadSchemas.create(protoField, propertyDescriptor); case SFIXED64: return packed ? SFixed64PackedReadSchemas.create(protoField, propertyDescriptor) : SFixed64NotPackedReadSchemas.create(protoField, propertyDescriptor); case FLOAT: return packed ? FloatPackedReadSchemas.create(protoField, propertyDescriptor) : FloatNotPackedReadSchemas.create(protoField, propertyDescriptor); case DOUBLE: return packed ? DoublePackedReadSchemas.create(protoField, propertyDescriptor) : DoubleNotPackedReadSchemas.create(protoField, propertyDescriptor); case BOOL: return packed ? BoolPackedReadSchemas.create(protoField, propertyDescriptor) : BoolNotPackedReadSchemas.create(protoField, propertyDescriptor); case STRING: return StringRepeatedReadSchemas.create(protoField, propertyDescriptor); case BYTES: return BytesRepeatedReadSchemas.create(protoField, propertyDescriptor); } } if (ProtoUtils.isAnyField(protoField)) { AnyEntrySchema anyEntrySchema = new AnyEntrySchema(protoMapper, null); return AnyRepeatedReadSchemas.create(protoField, propertyDescriptor, anyEntrySchema); } if (protoField.getType().isMessage()) { JavaType contentType = propertyDescriptor.getJavaType().getContentType(); if (contentType == null) { contentType = ProtoConst.OBJECT_TYPE; } SchemaEx<Object> contentSchema = getOrCreateMessageSchema((Message) protoField.getType(), contentType); if (isWrapProperty((Message) protoField.getType())) { return PropertyWrapperRepeatedReadSchemas.create(protoField, propertyDescriptor, contentSchema); } return MessageRepeatedReadSchemas.create(protoField, propertyDescriptor, contentSchema); } ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType()); return null; }