Updated the read method for Bluetooth classic

PiperOrigin-RevId: 487595432
This commit is contained in:
Guogang Li
2022-11-10 11:37:22 -08:00
committed by Copybara-Service
parent dba1deab3c
commit 8c8e5d7e6f
@@ -150,9 +150,16 @@ ExceptionOr<ByteArray> BluetoothSocket::BluetoothInputStream::Read(
}
Buffer buffer = Buffer(size);
winrt_stream_.ReadAsync(buffer, size, InputStreamOptions::Partial).get();
DataReader dataReader = DataReader::FromBuffer(buffer);
ByteArray data((char*)buffer.data(), buffer.Length());
auto ibuffer =
winrt_stream_.ReadAsync(buffer, size, InputStreamOptions::None).get();
if (ibuffer.Length() != size) {
NEARBY_LOGS(WARNING) << __func__ << ": Got " << ibuffer.Length()
<< " bytes of total " << size << " bytes.";
}
ByteArray data((char*)ibuffer.data(), ibuffer.Length());
return ExceptionOr(data);
} catch (std::exception exception) {
NEARBY_LOGS(ERROR) << __func__ << ": Exception: " << exception.what();