Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit addd4761 authored by Myles Watson's avatar Myles Watson Committed by Jakub Pawlowski
Browse files

PDL: Add non-static methods to checkers

Test: bluetooth_packet_parser_test
Change-Id: I2c753bce46226b6bd1597293d8077c2cbacc83b1
parent 2760273c
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -44,16 +44,16 @@ static const uint16_t crctab[256] = {
namespace bluetooth {
namespace l2cap {

void Fcs::Initialize(Fcs& s) {
  s.crc = 0;
void Fcs::Initialize() {
  crc = 0;
}

void Fcs::AddByte(Fcs& s, uint8_t byte) {
  s.crc = ((s.crc >> 8) & 0x00ff) ^ crctab[(s.crc & 0x00ff) ^ byte];
void Fcs::AddByte(uint8_t byte) {
  crc = ((crc >> 8) & 0x00ff) ^ crctab[(crc & 0x00ff) ^ byte];
}

uint16_t Fcs::GetChecksum(const Fcs& s) {
  return s.crc;
uint16_t Fcs::GetChecksum() const {
  return crc;
}

}  // namespace l2cap
+3 −3
Original line number Diff line number Diff line
@@ -24,11 +24,11 @@ namespace l2cap {
// Frame Check Sequence from the L2CAP spec.
class Fcs {
 public:
  static void Initialize(Fcs& s);
  void Initialize();

  static void AddByte(Fcs& s, uint8_t byte);
  void AddByte(uint8_t byte);

  static uint16_t GetChecksum(const Fcs& s);
  uint16_t GetChecksum() const;

 private:
  uint16_t crc;
+3 −3
Original line number Diff line number Diff line
@@ -28,13 +28,13 @@ namespace parser {
template <typename T, typename TRET>
class ChecksumTypeChecker {
 public:
  template <class C, void (*)(C&)>
  template <class C, void (C::*)()>
  struct InitializeChecker {};

  template <class C, void (*)(C&, uint8_t byte)>
  template <class C, void (C::*)(uint8_t byte)>
  struct AddByteChecker {};

  template <class C, typename CRET, CRET (*)(const C&)>
  template <class C, typename CRET, CRET (C::*)() const>
  struct GetChecksumChecker {};

  // If all the methods are defined, this one matches
+5 −5
Original line number Diff line number Diff line
@@ -23,14 +23,14 @@

namespace bluetooth {
namespace packet {
// Checks a custom type has all the necessary static functions with the correct signatures.
// Checks a custom type has all the necessary functions with the correct signatures.
template <typename T>
class CustomTypeChecker {
 public:
  template <class C, void (*)(const C&, BitInserter&)>
  template <class C, void (C::*)(BitInserter&) const>
  struct SerializeChecker {};

  template <class C, size_t (*)(const C&)>
  template <class C, size_t (C::*)() const>
  struct SizeChecker {};

  template <class C, Iterator<true> (*)(std::vector<C>& vec, Iterator<true> it)>
@@ -40,10 +40,10 @@ class CustomTypeChecker {
  struct ParseCheckerBigEndian {};

  template <class C>
  static int Test(SerializeChecker<C, &C::Serialize>*, SizeChecker<C, &C::Size>*, ParseChecker<C, &C::Parse>*);
  static int Test(SerializeChecker<C, &C::Serialize>*, SizeChecker<C, &C::size>*, ParseChecker<C, &C::Parse>*);

  template <class C>
  static int Test(SerializeChecker<C, &C::Serialize>*, SizeChecker<C, &C::Size>*, ParseCheckerBigEndian<C, &C::Parse>*);
  static int Test(SerializeChecker<C, &C::Serialize>*, SizeChecker<C, &C::size>*, ParseCheckerBigEndian<C, &C::Parse>*);

  template <class C>
  static char Test(...);
+1 −1
Original line number Diff line number Diff line
@@ -192,7 +192,7 @@ void ArrayField::GenInserter(std::ostream& s) const {
    s << "insert(static_cast<" << util::GetTypeForSize(type_def_->size_) << ">(val), i, " << type_def_->size_ << ");";
  } else if (IsCustomFieldArray()) {
    if (type_def_->size_ == -1) {
      s << type_def_->name_ << "::Serialize(val, i);";
      s << "val.Serialize(i);";
    } else {
      s << "insert(val, i);";
    }
Loading