Browse Source

cleanup 3

- no need in template when size set as constexpr
- remove size param completely, deduce size based on buffer
mcspr-patch-1
Maxim Prokhorov 4 years ago
parent
commit
11f815fc69
1 changed files with 4 additions and 7 deletions
  1. +4
    -7
      code/espurna/rfbridge.cpp

+ 4
- 7
code/espurna/rfbridge.cpp View File

@ -276,12 +276,10 @@ struct RfbMessage {
RfbMessage(const RfbMessage&) = default; RfbMessage(const RfbMessage&) = default;
RfbMessage(RfbMessage&&) = default; RfbMessage(RfbMessage&&) = default;
template <size_t Size>
explicit RfbMessage(uint8_t (&data)[Size], unsigned char repeats_) :
explicit RfbMessage(uint8_t (&data)[RfbParser::PayloadSizeBasic], unsigned char repeats_) :
repeats(repeats_) repeats(repeats_)
{ {
static_assert(Size == RfbParser::PayloadSizeBasic, "");
std::copy(data, data + Size, code);
std::copy(data, data + sizeof(data), code);
} }
uint8_t code[RfbParser::PayloadSizeBasic] { 0u }; uint8_t code[RfbParser::PayloadSizeBasic] { 0u };
@ -747,8 +745,7 @@ void _rfbSendImpl(const RfbMessage& message) {
// since it's original intent was to be used with 16bit ints // since it's original intent was to be used with 16bit ints
// TODO: both 'protocol' and 'bitlength' fit in a byte, despite being declared as 'unsigned int' // TODO: both 'protocol' and 'bitlength' fit in a byte, despite being declared as 'unsigned int'
template <size_t Size>
size_t _rfbModemPack(uint8_t(&out)[Size], RfbMessage::code_type code, unsigned int protocol, unsigned int timing, unsigned int bits) {
size_t _rfbModemPack(uint8_t (&out)[RfbMessage::BufferSize], RfbMessage::code_type code, unsigned int protocol, unsigned int timing, unsigned int bits) {
static_assert((sizeof(decltype(code)) == 4) || (sizeof(decltype(code)) == 8), ""); static_assert((sizeof(decltype(code)) == 4) || (sizeof(decltype(code)) == 8), "");
size_t index = 0; size_t index = 0;
@ -759,7 +756,7 @@ size_t _rfbModemPack(uint8_t(&out)[Size], RfbMessage::code_type code, unsigned i
out[index++] = static_cast<uint8_t>(bits); out[index++] = static_cast<uint8_t>(bits);
auto bytes = _rfb_bits_for_bytes(bits); auto bytes = _rfb_bits_for_bytes(bits);
if (bytes > (Size - index)) {
if (bytes > (sizeof(out) - index)) {
return 0; return 0;
} }


Loading…
Cancel
Save