【发布时间】:2018-12-22 16:46:15
【问题描述】:
我试图从数据中获取 int,short,从 websocket 获取数据,但是有些事情是错误的,当我从 UInt8List -> Byte Data -> UInt8List 转换时,它在我的数组中添加了 2 个新的 uint8。任何人都建议我如何从字节数组中获取 int 的正确方法。 (这是大端,我在 Swift 中的代码和在 Dart 中的基本写入数据仍然正确)。感谢大家阅读本文。
我正在使用 'dart:typed_data';并从 WebSocket (dart:io) 获取数据
print(responseData); // UInt8List: [0, 1, 0, 1, 0, 1, 49]
var byteData = responseData.buffer.asByteData();
var array = byteData.buffer.asUint8List();
print(array); // UInt8List: [130, 7, 0, 1, 0, 1, 0, 1, 49]
var shortValue = responseData.buffer.asByteData().getInt16(0);
print(shortValue); // -32249 ( 2 first byte: [0 ,1] so it must be 1 )
【问题讨论】: