@@ -126,6 +126,8 @@ def read_to_str(data):
126126 """
127127 return '' .join (chr (char ) for char in data )
128128
129+ unichr = chr
130+
129131else :
130132 # Python 2 interpreter : str & unicode
131133 def to_str (data , encoding = "UTF-8" ):
@@ -1078,10 +1080,7 @@ def _read_value(self, field_type, ident, name=""):
10781080 elif field_type == self .TYPE_BYTE :
10791081 (res ,) = self ._readStruct (">b" )
10801082 elif field_type == self .TYPE_CHAR :
1081- # TYPE_CHAR is defined by the serialization specification
1082- # but not used in the implementation, so this is
1083- # a hypothetical code
1084- res = bytes (self ._readStruct (">bb" )).decode ("utf-16-be" )
1083+ res = unichr (self ._readStruct (">H" )[0 ])
10851084 elif field_type == self .TYPE_SHORT :
10861085 (res ,) = self ._readStruct (">h" )
10871086 elif field_type == self .TYPE_INTEGER :
@@ -1531,6 +1530,8 @@ def _write_value(self, field_type, value):
15311530 self ._writeStruct (">B" , 1 , (1 if value else 0 ,))
15321531 elif field_type == self .TYPE_BYTE :
15331532 self ._writeStruct (">b" , 1 , (value ,))
1533+ elif field_type == self .TYPE_CHAR :
1534+ self ._writeStruct (">H" , 1 , (ord (value ),))
15341535 elif field_type == self .TYPE_SHORT :
15351536 self ._writeStruct (">h" , 1 , (value ,))
15361537 elif field_type == self .TYPE_INTEGER :
0 commit comments