Changeset 13823


Ignore:
Timestamp:
Oct 23, 2019 2:52:06 PM (4 weeks ago)
Author:
randersson
Message:

#5819 Updated encode/decode to be able to take lists, and updated set_string(...) accordingly

Location:
PyFMI/trunk/src/pyfmi
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • PyFMI/trunk/src/pyfmi/fmi.pyx

    r13818 r13823  
    16201620                'The length of valueref and values are inconsistent.')
    16211621       
    1622 
     1622        values = encode(values)
    16231623        for i in range(val_ref.size):
    1624             val[i] = decode(values[i])
     1624            val[i] = values[i]
    16251625       
    16261626        status = FMIL.fmi1_import_set_string(self._fmu, <FMIL.fmi1_value_reference_t*>val_ref.data, val_ref.size, val)
     
    41714171                'The length of valueref and values are inconsistent.')
    41724172
     4173        values = encode(values)
    41734174        for i in range(val_ref.size):
    4174             val[i] = decode(values[i])
     4175            val[i] = values[i]
    41754176       
    41764177        status = FMIL.fmi2_import_set_string(self._fmu, <FMIL.fmi2_value_reference_t*>val_ref.data, val_ref.size, val)
  • PyFMI/trunk/src/pyfmi/fmi_util.pyx

    r13348 r13823  
    3737
    3838cpdef decode(x):
    39     if python3_flag:
    40         return x.decode()
     39    if isinstance(x, list):
     40        return [item.decode() if python3_flag else item for item in x]
    4141    else:
    42         return x
     42        return x.decode() if python3_flag else x
    4343
    4444cpdef encode(x):
    45     if python3_flag:
    46         if isinstance(x, str):
    47             return x.encode()
    48         else:
    49             return x
     45    if isinstance(x, str):
     46        return x.encode() if python3_flag else x.encode("utf-8")
     47    elif isinstance(x, list):
     48        return [item.encode() if python3_flag else item.encode("utf-8") for item in x]
    5049    else:
    51         return x.encode("utf-8")
     50        return x if python3_flag else x.encode("utf-8")
    5251
    5352def enable_caching(obj):
Note: See TracChangeset for help on using the changeset viewer.