def parse_size_name(type_name):
    """Calculate size and encoding from a type name.

    This method takes a C-style type string like uint8_t[10] and returns
    - the total size in bytes
    - the unit size of each member (if it's an array)
    - the scruct.{pack,unpack} format code for decoding the base type
    - whether it is an array.
    """

    if ' ' in type_name:
        raise ArgumentError("There should not be a space in config variable type specifier", specifier=type_name)

    variable = False
    count = 1
    base_type = type_name

    if type_name[-1] == ']':
        variable = True
        start_index = type_name.find('[')
        if start_index == -1:
            raise ArgumentError("Could not find matching [ for ] character", specifier=type_name)

        count = int(type_name[start_index+1:-1], 0)
        base_type = type_name[:start_index]

    matched_type = TYPE_CODES.get(base_type)
    if matched_type is None:
        raise ArgumentError("Could not find base type name", base_type=base_type, type_string=type_name)

    base_size = struct.calcsize("<%s" % matched_type)
    total_size = base_size*count

    return total_size, base_size, matched_type, variable
def parse_size_name ( type_name ) : if ' ' in type_name : raise ArgumentError ( "There should not be a space in config variable type specifier" , specifier = type_name ) variable = False count = 1 base_type = type_name if type_name [ - 1 ] == ']' : variable = True start_index = type_name . find ( '[' ) if start_index == - 1 : raise ArgumentError ( "Could not find matching [ for ] character" , specifier = type_name ) count = int ( type_name [ start_index + 1 : - 1 ] , 0 ) base_type = type_name [ : start_index ] matched_type = TYPE_CODES . get ( base_type ) if matched_type is None : raise ArgumentError ( "Could not find base type name" , base_type = base_type , type_string = type_name ) base_size = struct . calcsize ( "<%s" % matched_type ) total_size = base_size * count return total_size , base_size , matched_type , variable
Calculate size and encoding from a type name.

    This method takes a C-style type string like uint8_t[10] and returns
    - the total size in bytes
    - the unit size of each member (if it's an array)
    - the scruct.{pack,unpack} format code for decoding the base type
    - whether it is an array.