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

Commit 1bdec93e authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "PDL: Use little_endian in CustomFieldCheck"

parents 58ced168 d8b53681
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -57,7 +57,8 @@ void CustomFieldDef::GenUsing(std::ostream& s) const {
  s << GetTypeName() << ";";
}

void CustomFieldDef::GenCustomFieldCheck(std::ostream& s) const {
  s << "static_assert(CustomTypeChecker<" << name_ << ">::value, \"";
void CustomFieldDef::GenCustomFieldCheck(std::ostream& s, bool little_endian) const {
  s << "static_assert(CustomTypeChecker<" << name_ << ", ";
  s << (little_endian ? "" : "!") << "kLittleEndian>::value, \"";
  s << name_ << " is not a valid custom field type. Please see README for more details.\");";
}
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ class CustomFieldDef : public TypeDef {

  void GenUsing(std::ostream& s) const;

  void GenCustomFieldCheck(std::ostream& s) const;
  void GenCustomFieldCheck(std::ostream& s, bool little_endian) const;

  const std::string include_;
};
+7 −12
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
namespace bluetooth {
namespace packet {
// Checks a custom type has all the necessary functions with the correct signatures.
template <typename T>
template <typename T, bool packet_little_endian>
class CustomTypeChecker {
 public:
  template <class C, void (C::*)(BitInserter&) const>
@@ -33,22 +33,17 @@ class CustomTypeChecker {
  template <class C, size_t (C::*)() const>
  struct SizeChecker {};

  template <class C, Iterator<true> (*)(C* vec, Iterator<true> it)>
  template <class C, bool little_endian, Iterator<little_endian> (*)(C* vec, Iterator<little_endian> it)>
  struct ParseChecker {};

  template <class C, Iterator<false> (*)(C* vec, Iterator<false> it)>
  struct ParseCheckerBigEndian {};
  template <class C, bool little_endian>
  static int Test(SerializeChecker<C, &C::Serialize>*, SizeChecker<C, &C::size>*,
                  ParseChecker<C, little_endian, &C::Parse>*);

  template <class C>
  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>*);

  template <class C>
  template <class C, bool little_endian>
  static char Test(...);

  static constexpr bool value = (sizeof(Test<T>(0, 0, 0)) == sizeof(int));
  static constexpr bool value = (sizeof(Test<T, packet_little_endian>(0, 0, 0)) == sizeof(int));
};
}  // namespace packet
}  // namespace bluetooth
+1 −1
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ bool parse_one_file(std::filesystem::path input_file, std::filesystem::path incl

  for (const auto& c : decls.type_defs_queue_) {
    if (c.second->GetDefinitionType() == TypeDef::Type::CUSTOM && c.second->size_ == -1 /* Variable Size */) {
      ((CustomFieldDef*)c.second)->GenCustomFieldCheck(out_file);
      ((CustomFieldDef*)c.second)->GenCustomFieldCheck(out_file, decls.is_little_endian);
    }
  }
  out_file << "\n";
+0 −19
Original line number Diff line number Diff line
@@ -42,25 +42,6 @@ void Variable::Serialize(BitInserter& bi) const {
size_t Variable::size() const {
  return data.size() + 1;
}

Iterator<true> Variable::Parse(Variable* instance, Iterator<true> it) {
  if (it.NumBytesRemaining() < 1) {
    return it;
  }
  size_t data_length = it.extract<uint8_t>();
  if (data_length > 255) {
    return it + it.NumBytesRemaining();
  }
  if (it.NumBytesRemaining() < data_length) {
    return it + it.NumBytesRemaining();
  }
  std::stringstream ss;
  for (size_t i = 0; i < data_length; i++) {
    ss << it.extract<char>();
  }
  *instance = ss.str();
  return it;
}
}  // namespace test
}  // namespace parser
}  // namespace packet
Loading