refactor
This commit is contained in:
parent
dbf4a58807
commit
9af77225f2
@ -36,8 +36,8 @@ void packet::clear() {
|
||||
}
|
||||
|
||||
auto packet::decode(std::string &data) -> packet::error_type {
|
||||
const auto *str = reinterpret_cast<const char *>(&buffer_[decode_offset_]);
|
||||
const auto length = strnlen(str, buffer_.size() - decode_offset_);
|
||||
const auto *str = reinterpret_cast<const char *>(&buffer_.at(decode_offset_));
|
||||
auto length = strnlen(str, buffer_.size() - decode_offset_);
|
||||
data = std::string(str, length);
|
||||
decode_offset_ += (length + 1);
|
||||
|
||||
@ -46,7 +46,7 @@ auto packet::decode(std::string &data) -> packet::error_type {
|
||||
|
||||
auto packet::decode(std::wstring &data) -> packet::error_type {
|
||||
std::string utf8_string;
|
||||
const auto ret = decode(utf8_string);
|
||||
auto ret = decode(utf8_string);
|
||||
if (ret == 0) {
|
||||
data = utils::string::from_utf8(utf8_string);
|
||||
}
|
||||
@ -60,7 +60,7 @@ auto packet::decode(void *&ptr) -> packet::error_type {
|
||||
|
||||
auto packet::decode(void *buffer, std::size_t size) -> packet::error_type {
|
||||
if (size != 0U) {
|
||||
const auto read_size =
|
||||
auto read_size =
|
||||
utils::calculate_read_size(buffer_.size(), size, decode_offset_);
|
||||
if (read_size == size) {
|
||||
memcpy(buffer, &buffer_[decode_offset_], size);
|
||||
@ -76,7 +76,7 @@ auto packet::decode(void *buffer, std::size_t size) -> packet::error_type {
|
||||
}
|
||||
|
||||
auto packet::decode(std::int8_t &val) -> packet::error_type {
|
||||
const auto ret = decode(&val, sizeof(val));
|
||||
auto ret = decode(&val, sizeof(val));
|
||||
if (ret == 0) {
|
||||
boost::endian::big_to_native_inplace(val);
|
||||
}
|
||||
@ -84,7 +84,7 @@ auto packet::decode(std::int8_t &val) -> packet::error_type {
|
||||
}
|
||||
|
||||
auto packet::decode(std::uint8_t &val) -> packet::error_type {
|
||||
const auto ret = decode(&val, sizeof(val));
|
||||
auto ret = decode(&val, sizeof(val));
|
||||
if (ret == 0) {
|
||||
boost::endian::big_to_native_inplace(val);
|
||||
}
|
||||
@ -92,7 +92,7 @@ auto packet::decode(std::uint8_t &val) -> packet::error_type {
|
||||
}
|
||||
|
||||
auto packet::decode(std::int16_t &val) -> packet::error_type {
|
||||
const auto ret = decode(&val, sizeof(val));
|
||||
auto ret = decode(&val, sizeof(val));
|
||||
if (ret == 0) {
|
||||
boost::endian::big_to_native_inplace(val);
|
||||
}
|
||||
@ -100,7 +100,7 @@ auto packet::decode(std::int16_t &val) -> packet::error_type {
|
||||
}
|
||||
|
||||
auto packet::decode(std::uint16_t &val) -> packet::error_type {
|
||||
const auto ret = decode(&val, sizeof(val));
|
||||
auto ret = decode(&val, sizeof(val));
|
||||
if (ret == 0) {
|
||||
boost::endian::big_to_native_inplace(val);
|
||||
}
|
||||
@ -108,7 +108,7 @@ auto packet::decode(std::uint16_t &val) -> packet::error_type {
|
||||
}
|
||||
|
||||
auto packet::decode(std::int32_t &val) -> packet::error_type {
|
||||
const auto ret = decode(&val, sizeof(val));
|
||||
auto ret = decode(&val, sizeof(val));
|
||||
if (ret == 0) {
|
||||
boost::endian::big_to_native_inplace(val);
|
||||
}
|
||||
@ -116,7 +116,7 @@ auto packet::decode(std::int32_t &val) -> packet::error_type {
|
||||
}
|
||||
|
||||
auto packet::decode(std::uint32_t &val) -> packet::error_type {
|
||||
const auto ret = decode(&val, sizeof(val));
|
||||
auto ret = decode(&val, sizeof(val));
|
||||
if (ret == 0) {
|
||||
boost::endian::big_to_native_inplace(val);
|
||||
}
|
||||
@ -124,7 +124,7 @@ auto packet::decode(std::uint32_t &val) -> packet::error_type {
|
||||
}
|
||||
|
||||
auto packet::decode(std::int64_t &val) -> packet::error_type {
|
||||
const auto ret = decode(&val, sizeof(val));
|
||||
auto ret = decode(&val, sizeof(val));
|
||||
if (ret == 0) {
|
||||
boost::endian::big_to_native_inplace(val);
|
||||
}
|
||||
@ -132,7 +132,7 @@ auto packet::decode(std::int64_t &val) -> packet::error_type {
|
||||
}
|
||||
|
||||
auto packet::decode(std::uint64_t &val) -> packet::error_type {
|
||||
const auto ret = decode(&val, sizeof(val));
|
||||
auto ret = decode(&val, sizeof(val));
|
||||
if (ret == 0) {
|
||||
boost::endian::big_to_native_inplace(val);
|
||||
}
|
||||
@ -140,7 +140,7 @@ auto packet::decode(std::uint64_t &val) -> packet::error_type {
|
||||
}
|
||||
|
||||
auto packet::decode(remote::setattr_x &val) -> packet::error_type {
|
||||
const auto ret = decode(&val, sizeof(val));
|
||||
auto ret = decode(&val, sizeof(val));
|
||||
if (ret == 0) {
|
||||
boost::endian::big_to_native_inplace(val.acctime);
|
||||
boost::endian::big_to_native_inplace(val.bkuptime);
|
||||
@ -159,7 +159,7 @@ auto packet::decode(remote::setattr_x &val) -> packet::error_type {
|
||||
}
|
||||
|
||||
auto packet::decode(remote::stat &val) -> packet::error_type {
|
||||
const auto ret = decode(&val, sizeof(val));
|
||||
auto ret = decode(&val, sizeof(val));
|
||||
if (ret == 0) {
|
||||
boost::endian::big_to_native_inplace(val.st_mode);
|
||||
boost::endian::big_to_native_inplace(val.st_nlink);
|
||||
@ -179,7 +179,7 @@ auto packet::decode(remote::stat &val) -> packet::error_type {
|
||||
}
|
||||
|
||||
auto packet::decode(remote::statfs &val) -> packet::error_type {
|
||||
const auto ret = decode(&val, sizeof(val));
|
||||
auto ret = decode(&val, sizeof(val));
|
||||
if (ret == 0) {
|
||||
boost::endian::big_to_native_inplace(val.f_bavail);
|
||||
boost::endian::big_to_native_inplace(val.f_bfree);
|
||||
@ -200,7 +200,7 @@ auto packet::decode(remote::statfs_x &val) -> packet::error_type {
|
||||
}
|
||||
|
||||
auto packet::decode(remote::file_info &val) -> packet::error_type {
|
||||
const auto ret = decode(&val, sizeof(val));
|
||||
auto ret = decode(&val, sizeof(val));
|
||||
if (ret == 0) {
|
||||
boost::endian::big_to_native_inplace(val.AllocationSize);
|
||||
boost::endian::big_to_native_inplace(val.ChangeTime);
|
||||
@ -268,7 +268,7 @@ void packet::encode(const void *buffer, std::size_t size, bool should_reserve) {
|
||||
}
|
||||
|
||||
void packet::encode(std::string_view str) {
|
||||
const auto len = str.size();
|
||||
auto len = str.size();
|
||||
buffer_.reserve(len + 1 + buffer_.size());
|
||||
encode(str.data(), len, false);
|
||||
buffer_.emplace_back(0);
|
||||
@ -401,7 +401,7 @@ void packet::encode_top(const void *buffer, std::size_t size,
|
||||
}
|
||||
|
||||
void packet::encode_top(std::string_view str) {
|
||||
const auto len = str.size();
|
||||
auto len = str.size();
|
||||
buffer_.reserve(len + 1U + buffer_.size());
|
||||
encode_top(str.data(), len, false);
|
||||
buffer_.insert(buffer_.begin() + static_cast<std::int32_t>(len), 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user