Browse Source

Update utf16 string read func

Justin 2 years ago
parent
commit
5d425f1c6e
1 changed files with 4 additions and 13 deletions
  1. 4 13
      lib/us/vid_us_data_reader.dart

+ 4 - 13
lib/us/vid_us_data_reader.dart

@@ -27,19 +27,10 @@ class VidUsDataReader {
 
   ///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() ~/ 2;
-      var stringData = _buffer.asUint16List(index, dataLength);
-      _index += dataLength;
-      //return utf8.decode(stringData);
-      return String.fromCharCodes(stringData);
-    } else {
-      var dataLength = readInt(index) ~/ 2;
-      var stringData = _buffer.asUint16List(_index, dataLength);
-      _index += dataLength;
-      //return utf8.decode(stringData);
-      return String.fromCharCodes(stringData);
-    }
+    var dataLength = index == -1 ? readInt() : readInt(index);
+    var stringData = _buffer.asUint8List(_index, dataLength);
+    _index += dataLength;
+    return String.fromCharCodes(stringData.buffer.asInt16List());
   }
 
   ///Read int16 value from binary data(little endian)