use of org.apache.servicecomb.foundation.protobuf.internal.schema.any.AnyEntrySchema in project java-chassis by ServiceComb.
the class DeserializerSchemaManager method createRootDeserializer.
@SuppressWarnings({ "rawtypes", "unchecked" })
public <T> RootDeserializer<T> createRootDeserializer(Message message, Type type) {
if (ProtoUtils.isAnyMessage(message)) {
SchemaEx<Object> messageSchema = new AnyEntrySchema(protoMapper, type);
return new RootDeserializer(messageSchema);
}
JavaType javaType = TypeFactory.defaultInstance().constructType(type);
SchemaEx<T> messageSchema = getOrCreateMessageSchema(message, javaType);
return new RootDeserializer<>(messageSchema);
}
use of org.apache.servicecomb.foundation.protobuf.internal.schema.any.AnyEntrySchema in project java-chassis by ServiceComb.
the class DeserializerSchemaManager method createRepeatedSchema.
@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;
}
use of org.apache.servicecomb.foundation.protobuf.internal.schema.any.AnyEntrySchema in project incubator-servicecomb-java-chassis by apache.
the class SerializerSchemaManager method createRootSerializer.
public RootSerializer createRootSerializer(Message message, Type type) {
if (ProtoUtils.isAnyMessage(message)) {
SchemaEx<Object> messageSchema = new AnyEntrySchema(protoMapper, type);
return new RootSerializer(messageSchema);
}
JavaType javaType = TypeFactory.defaultInstance().constructType(type);
SchemaEx<Object> messageSchema = getOrCreateMessageSchema(message, javaType);
return new RootSerializer(messageSchema);
}
use of org.apache.servicecomb.foundation.protobuf.internal.schema.any.AnyEntrySchema in project java-chassis by ServiceComb.
the class SerializerSchemaManager method createRootSerializer.
public RootSerializer createRootSerializer(Message message, Type type) {
if (ProtoUtils.isAnyMessage(message)) {
SchemaEx<Object> messageSchema = new AnyEntrySchema(protoMapper, type);
return new RootSerializer(messageSchema);
}
JavaType javaType = TypeFactory.defaultInstance().constructType(type);
SchemaEx<Object> messageSchema = getOrCreateMessageSchema(message, javaType);
return new RootSerializer(messageSchema);
}
use of org.apache.servicecomb.foundation.protobuf.internal.schema.any.AnyEntrySchema in project incubator-servicecomb-java-chassis by apache.
the class DeserializerSchemaManager method createRepeatedSchema.
@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;
}
Aggregations