private void fieldMapToString(Field field, StringBuilder sb) { Message entryMessage = (Message) field.getType(); Field keyField = entryMessage.getField(1); Field valueField = entryMessage.getField(2); // map<string, string> name = 1; appendLine(sb, "map<%s, %s> %s = %d;", keyField.getTypeName(), valueField.getTypeName(), field.getName(), field.getTag()); } }
private FieldMapEx<T> createPropertyWrapperFields(JavaType javaType) { Field protoField = message.getField(1); PropertyDescriptor propertyDescriptor = new PropertyDescriptor(); propertyDescriptor.setName(protoField.getName()); propertyDescriptor.setJavaType(javaType); FieldSchema<T> fieldSchema = protoMapper.getSerializerSchemaManager() .createSchemaField(protoField, propertyDescriptor); return FieldMapEx.createFieldMap(Arrays.asList(fieldSchema)); }
private void createFieldMap() { DeserializerSchemaManager deserializerSchemaManager = protoMapper.getDeserializerSchemaManager(); BeanDescriptor beanDescriptor = protoMapper.getBeanDescriptorManager().getOrCreateBeanDescriptor(javaType); List<FieldSchema<T>> fieldSchemas = new ArrayList<>(); for (PropertyDescriptor propertyDescriptor : beanDescriptor.getPropertyDescriptors().values()) { Field protoField = message.getField(propertyDescriptor.getName()); if (protoField == null) { LOGGER.info("java field {}:{} not exist in proto message {}, ignore it.", beanDescriptor.getJavaType().getRawClass().getName(), propertyDescriptor.getName(), message.getCanonicalName()); continue; } if (propertyDescriptor.getSetter() == null) { LOGGER.info("no setter for java field {}:{} in proto message {}, ignore it.", beanDescriptor.getJavaType().getRawClass().getName(), propertyDescriptor.getName(), message.getCanonicalName()); continue; } FieldSchema<T> fieldSchema = deserializerSchemaManager.createSchemaField(protoField, propertyDescriptor); fieldSchemas.add(fieldSchema); } this.fieldMap = FieldMapEx.createFieldMap(fieldSchemas); }
@Override protected <T> SchemaEx<T> newMessageSchema(Message message, JavaType javaType) { if (ProtoUtils.isWrapProperty(message) && javaType.getRawClass() != PropertyWrapper.class) { Field protoField = message.getField(1); if (javaType.isJavaLangObject()) { javaType = protoField.isRepeated() && protoField.getType().isMessage() && !protoField.isMap() ? ProtoConst.LIST_TYPE : ProtoConst.MAP_TYPE; } javaType = TypeFactory.defaultInstance().constructParametricType(PropertyWrapper.class, javaType); } if (javaType.isJavaLangObject()) { javaType = ProtoConst.MAP_TYPE; } return new MessageReadSchema<>(protoMapper, message, javaType); }
private String getMapKeyType(Field field) { Message message = (Message) field.getType(); Field key = message.getField("key"); return key.getType().getCanonicalName(); }
private String getMapValueType(Field field) { Message message = (Message) field.getType(); Field value = message.getField("value"); return value.getType().getCanonicalName(); }
/** * 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); }
private void fieldMapToString(Field field, StringBuilder sb) { Message entryMessage = (Message) field.getType(); Field keyField = entryMessage.getField(1); Field valueField = entryMessage.getField(2); // map<string, string> name = 1; appendLine(sb, "map<%s, %s> %s = %d;", keyField.getTypeName(), valueField.getTypeName(), field.getName(), field.getTag()); } }
private String getMapValueType(Field field) { Message message = (Message) field.getType(); Field value = message.getField("value"); return value.getType().getCanonicalName(); }
private String getMapKeyType(Field field) { Message message = (Message) field.getType(); Field key = message.getField("key"); return key.getType().getCanonicalName(); }
/** * 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); }
private void processStandardOptions(ProtoContext context, Message sourceMessage, Descriptor owningDescriptor, DynamicMessage options) { for (Map.Entry<DynamicMessage.Key, DynamicMessage.Value> entry : options.getFields()) { DynamicMessage.Key key = entry.getKey(); DynamicMessage.Value value = entry.getValue(); if (key.isExtension()) { continue; } // check standard option String fieldName = key.getName(); Field field = sourceMessage.getField(fieldName); if (DEFAULT.equals(fieldName)) { // TODO: check value of default option } else { if (field == null) { throw new ParserException(value, "Unknown option: '%s'", fieldName); } checkFieldValue(context, owningDescriptor, field, value); } } }
private void processStandardOptions(ProtoContext context, Message sourceMessage, Descriptor owningDescriptor, DynamicMessage options) { for (Map.Entry<DynamicMessage.Key, DynamicMessage.Value> entry : options.getFields()) { DynamicMessage.Key key = entry.getKey(); DynamicMessage.Value value = entry.getValue(); if (key.isExtension()) { continue; } // check standard option String fieldName = key.getName(); Field field = sourceMessage.getField(fieldName); if (DEFAULT.equals(fieldName)) { // TODO: check value of default option } else { if (field == null) { throw new ParserException(value, "Unknown option: '%s'", fieldName); } checkFieldValue(context, owningDescriptor, field, value); } } }
/** * 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; }
/** * 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; }
Field protoField = message.getField(propertyDescriptor.getName()); if (protoField == null) { LOGGER.info("java field {}:{} not exist in proto message {}, ignore it.",
protected FieldSchema createSchemaField(SchemaCreateContext context, Field protoField, boolean repeated) { if (protoField.isMap()) { Message entryMessage = (Message) protoField.getType(); FieldSchema keySchema = createSchemaField(context, entryMessage.getField(1), false); FieldSchema valueSchema = createSchemaField(context, entryMessage.getField(2), false); return new MapSchema(protoField, keySchema, valueSchema);
if (protoField.isMap()) { Message entryMessage = (Message) protoField.getType(); FieldSchema keySchema = createSchemaField(context, javaType.getKeyType(), entryMessage.getField(1), false); FieldSchema valueSchema = createSchemaField(context, javaType.getContentType(), entryMessage.getField(2), false); return new MapSchema(protoField, keySchema, valueSchema);