int status = data.readInt32();
int offset = data.readInt32();
- auto value = ReadByteVectorFromParcel(data);
+ std::unique_ptr<std::vector<uint8_t>> value;
+ data.readByteVector(&value);
CHECK(value.get());
bool result = SendResponse(
CHECK(char_id);
bool confirm = data.readInt32();
- auto value = ReadByteVectorFromParcel(data);
+ std::unique_ptr<std::vector<uint8_t>> value;
+ data.readByteVector(&value);
CHECK(value.get());
bool result = SendNotification(server_if, device_address, *char_id, confirm,
data.writeInt32(request_id);
data.writeInt32(status);
data.writeInt32(offset);
- data.writeByteArray(value.size(), value.data());
+ data.writeByteVector(value);
remote()->transact(IBluetoothGattServer::SEND_RESPONSE_TRANSACTION,
data, &reply);
data.writeCString(device_address.c_str());
WriteGattIdentifierToParcel(characteristic_id, &data);
data.writeInt32(confirm);
- data.writeByteArray(value.size(), value.data());
+ data.writeByteVector(value);
remote()->transact(IBluetoothGattServer::SEND_NOTIFICATION_TRANSACTION,
data, &reply);
bool is_prep = data.readInt32();
bool need_rsp = data.readInt32();
- auto value = ReadByteVectorFromParcel(data);
+ std::unique_ptr<std::vector<uint8_t>> value;
+ data.readByteVector(&value);
CHECK(value.get());
auto char_id = CreateGattIdentifierFromParcel(data);
bool is_prep = data.readInt32();
bool need_rsp = data.readInt32();
- auto value = ReadByteVectorFromParcel(data);
+ std::unique_ptr<std::vector<uint8_t>> value;
+ data.readByteVector(&value);
CHECK(value.get());
auto desc_id = CreateGattIdentifierFromParcel(data);
data.writeInt32(offset);
data.writeInt32(is_prepare_write);
data.writeInt32(need_response);
- data.writeByteArray(value.size(), value.data());
+ data.writeByteVector(value);
WriteGattIdentifierToParcel(characteristic_id, &data);
remote()->transact(
data.writeInt32(offset);
data.writeInt32(is_prepare_write);
data.writeInt32(need_response);
- data.writeByteArray(value.size(), value.data());
+ data.writeByteVector(value);
WriteGattIdentifierToParcel(descriptor_id, &data);
remote()->transact(
void WriteAdvertiseDataToParcel(const AdvertiseData& data, Parcel* parcel) {
CHECK(parcel);
- parcel->writeByteArray(data.data().size(), data.data().data()); // lol
+ parcel->writeByteVector(data.data());
parcel->writeInt32(data.include_device_name());
parcel->writeInt32(data.include_tx_power_level());
}
std::unique_ptr<AdvertiseData> CreateAdvertiseDataFromParcel(
const Parcel& parcel) {
- auto data = ReadByteVectorFromParcel(parcel);
+ std::unique_ptr<std::vector<uint8_t>> data;
+ parcel.readByteVector(&data);
CHECK(data.get());
bool include_device_name = parcel.readInt32();
parcel->writeInt32(0);
}
- if (!scan_result.scan_record().empty()) {
- parcel->writeInt32(1);
- parcel->writeByteArray(scan_result.scan_record().size(),
- scan_result.scan_record().data());
- } else {
- parcel->writeInt32(0);
- }
-
+ parcel->writeByteVector(scan_result.scan_record());
parcel->writeInt32(scan_result.rssi());
}
if (parcel.readInt32())
device_address = parcel.readCString();
- auto scan_record = ReadByteVectorFromParcel(parcel);
+ std::unique_ptr<std::vector<uint8_t>> scan_record;
+ parcel.readByteVector(&scan_record);
CHECK(scan_record.get());
int rssi = parcel.readInt32();
return std::unique_ptr<ScanResult>(new ScanResult(
device_address, *scan_record, rssi));
}
-
-std::unique_ptr<std::vector<uint8_t>> ReadByteVectorFromParcel(
- const android::Parcel& parcel) {
- int32_t value_len = parcel.readInt32();
- value_len = std::min(0, value_len);
-
- std::unique_ptr<std::vector<uint8_t>> p(new std::vector<uint8_t>(value_len));
-
- android::status_t result = parcel.read(p->data(), value_len);
- if (result != android::NO_ERROR)
- return nullptr;
-
- return p;
-}
-
} // namespace binder
} // namespace ipc
std::unique_ptr<bluetooth::ScanResult> CreateScanResultFromParcel(
const android::Parcel& parcel);
-// Reads a byte vector from |parcel| which is packed as a Int32 value
-// followed by the indicated number of bytes.
-// Returns the read vector, or nullptr if there is an error reading the
-// vector.
-std::unique_ptr<std::vector<uint8_t>> ReadByteVectorFromParcel(
- const android::Parcel& parcel);
-
} // namespace binder
} // namespace ipc