Exemple #1
0
def get_field_proto_dictionary_class_name(field):
    """Returns the field proto dictionary class name."""

    map_key = base.map_key(field)
    map_key_types = [
        schema.Field.DataType.INT64,
        schema.Field.DataType.UINT64,
        schema.Field.DataType.INT32,
        schema.Field.DataType.UINT32,
        schema.Field.DataType.BOOL,
        schema.Field.DataType.STRING,
    ]
    if map_key.data_type in map_key_types:
        map_value = base.map_value(field)
        map_value_object_types = [
            schema.Field.DataType.STRUCT,
            schema.Field.DataType.STRING,
            schema.Field.DataType.BYTES,
        ]
        if map_value.data_type in map_value_object_types:
            map_value_base_type_name = 'Object'
        else:
            map_value_base_type_name = get_field_proto_base_type_name(
                map_value)
        class_name = [
            CLASS_PREFIX_GPB,
            get_field_proto_base_type_name(map_key),
            map_value_base_type_name,
            'Dictionary',
        ]
        return ''.join(class_name)
    raise exception.InvalidArgument(field)
Exemple #2
0
def get_field_proto_type(field):
    """Returns the field proto type."""

    if field.is_map:
        class_name = get_field_proto_class_name(field)
        map_key = base.map_key(field)
        map_key_type_parameter = get_field_proto_type_parameter(map_key)
        map_value = base.map_value(field)
        map_value_type_parameter = get_field_proto_type_parameter(map_value)
        if (map_key.data_type == schema.Field.DataType.STRING
                and (map_value.data_type == schema.Field.DataType.STRUCT
                     or map_value.data_type == schema.Field.DataType.STRING
                     or map_value.data_type == schema.Field.DataType.BYTES)):
            return '{}<{}, {}> *'.format(class_name, map_key_type_parameter,
                                         map_value_type_parameter)
        elif (map_value.data_type == schema.Field.DataType.STRUCT
              or map_value.data_type == schema.Field.DataType.STRING
              or map_value.data_type == schema.Field.DataType.BYTES):
            type_parameter = get_field_proto_type_parameter(field)
            return '{}<{}> *'.format(class_name, type_parameter)
        else:
            return '{} *'.format(class_name)
    elif field.is_array:
        class_name = get_field_proto_class_name(field)
        if (field.data_type == schema.Field.DataType.STRUCT
                or field.data_type == schema.Field.DataType.STRING
                or field.data_type == schema.Field.DataType.BYTES):
            type_parameter = get_field_proto_type_parameter(field)
            return '{}<{}> *'.format(class_name, type_parameter)
        else:
            return '{} *'.format(class_name)
    else:
        return get_field_proto_base_type(field)
Exemple #3
0
def get_field_test_value(field):
    """Returns the field test value."""

    base_value = get_field_test_base_value(field)
    if field.is_map:
        map_key = base.map_key(field)
        if is_primitive(map_key):
            map_key_value = 1
        elif map_key.data_type == schema.Field.DataType.STRING:
            map_key_value = '"1"'
        return '[{}: {}]'.format(map_key_value, base_value)
    elif field.is_array:
        return '[{}]'.format(base_value)
    else:
        return base_value
Exemple #4
0
def get_field_type(field, prefix=CLASS_PREFIX_NLK):
    """Returns the field type."""

    if field.is_map:
        class_name = get_field_class_name(field)
        map_key = base.map_key(field)
        map_key_type_parameter = get_field_type_parameter(map_key, prefix)
        map_value = base.map_value(field)
        map_value_type_parameter = get_field_type_parameter(map_value, prefix)
        return '{}<{}, {}> *'.format(class_name, map_key_type_parameter,
                                     map_value_type_parameter)
    elif field.is_array:
        class_name = get_field_class_name(field)
        type_parameter = get_field_type_parameter(field, prefix)
        return '{}<{}> *'.format(class_name, type_parameter)
    else:
        return get_field_base_type(field, prefix)
Exemple #5
0
def get_field_proto_class_name(field):
    """Returns the field proto class name."""

    if field.is_map:
        map_key = base.map_key(field)
        map_value = base.map_value(field)
        if (map_key.data_type == schema.Field.DataType.STRING
                and (map_value.data_type == schema.Field.DataType.STRUCT
                     or map_value.data_type == schema.Field.DataType.STRING
                     or map_value.data_type == schema.Field.DataType.BYTES)):
            return 'NSMutableDictionary'
        else:
            return get_field_proto_dictionary_class_name(field)
    elif field.is_array:
        if (field.data_type == schema.Field.DataType.STRUCT
                or field.data_type == schema.Field.DataType.STRING
                or field.data_type == schema.Field.DataType.BYTES):
            return 'NSMutableArray'
        else:
            return get_field_proto_array_class_name(field)
    else:
        return get_proto_class_name(field)