mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-04-23 13:04:50 +00:00
haze: improve WriteVariableLengthData readability
This commit is contained in:
parent
9c922e4774
commit
0b5b63b9d8
1 changed files with 17 additions and 6 deletions
|
@ -107,23 +107,34 @@ namespace haze {
|
|||
|
||||
template <typename F>
|
||||
Result WriteVariableLengthData(PtpUsbBulkContainer &request, F &&func) {
|
||||
HAZE_ASSERT(m_offset == 0 && m_transmitted_size == 0);
|
||||
|
||||
/* Declare how many bytes the data will require to write. */
|
||||
size_t data_size = 0;
|
||||
{
|
||||
/* Temporarily disable writing to calculate the size.*/
|
||||
m_disabled = true;
|
||||
ON_SCOPE_EXIT { m_disabled = false; };
|
||||
|
||||
ON_SCOPE_EXIT {
|
||||
/* Report how many bytes were required. */
|
||||
data_size = m_transmitted_size;
|
||||
|
||||
/* On exit, enable writing and reset sizes. */
|
||||
m_transmitted_size = 0;
|
||||
m_disabled = false;
|
||||
m_offset = 0;
|
||||
};
|
||||
|
||||
R_TRY(func());
|
||||
R_TRY(this->Commit());
|
||||
}
|
||||
|
||||
const size_t data_size = m_transmitted_size;
|
||||
|
||||
m_transmitted_size = 0;
|
||||
m_offset = 0;
|
||||
|
||||
/* Actually copy and write the data. */
|
||||
R_TRY(this->AddDataHeader(request, data_size));
|
||||
R_TRY(func());
|
||||
R_TRY(this->Commit());
|
||||
|
||||
/* We succeeded. */
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue