Browse Source

Change read string codec from utf8 to utf16 which is unicode in C#.

Justin 2 years ago
parent
commit
41bb47f243
1 changed files with 9 additions and 7 deletions
  1. 9 7
      lib/us/vid_us_data_reader.dart

+ 9 - 7
lib/us/vid_us_data_reader.dart

@@ -25,18 +25,20 @@ class VidUsDataReader {
     }
   }
 
-  ///Read string from the binary data, the string format is utf8
+  ///Read string from the binary data, the string format is utf-16, which is unicode in C#
   String readString([int index = -1]) {
     if (index == -1) {
-      var dataLength = readInt();
-      var stringData = _buffer.asUint8List(_index, dataLength);
+      var dataLength = readInt() ~/ 2;
+      var stringData = _buffer.asUint16List(index, dataLength);
       _index += dataLength;
-      return utf8.decode(stringData);
+      //return utf8.decode(stringData);
+      return String.fromCharCodes(stringData);
     } else {
-      var dataLength = readInt(index);
-      var stringData = _buffer.asUint8List(_index, dataLength);
+      var dataLength = readInt(index) ~/ 2;
+      var stringData = _buffer.asUint16List(_index, dataLength);
       _index += dataLength;
-      return utf8.decode(stringData);
+      //return utf8.decode(stringData);
+      return String.fromCharCodes(stringData);
     }
   }