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

Commit 24a20c6b authored by Chris Manton's avatar Chris Manton
Browse files

flatbuffers: Add support for BASE_TYPE_LONG

Bug: 216499488
Tag: #refactor
Test: gd/cert/run
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I95af3c4a3c428c10f8beafa8b2af5464ccdc0576
parent b57af496
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -113,6 +113,9 @@ bool UserPrivacyFilter::FilterField(const reflection::Field* field, flatbuffers:
    case flatbuffers::BASE_TYPE_BOOL:
      return internal::FilterTypeBool(*field, table, privacy_level);
      break;
    case flatbuffers::BASE_TYPE_LONG:
      return internal::FilterTypeLong(*field, table, privacy_level);
      break;
    default:
      LOG_WARN("%s WARN Unsupported base type\n", __func__);
      break;
+26 −0
Original line number Diff line number Diff line
@@ -200,6 +200,32 @@ bool internal::FilterTypeFloat(const reflection::Field& field, flatbuffers::Tabl
  return kFieldHasBeenFiltered;
}

bool internal::FilterTypeLong(const reflection::Field& field, flatbuffers::Table* table, PrivacyLevel privacy_level) {
  ASSERT(table != nullptr);

  const int64_t default_val = flatbuffers::GetFieldDefaultI<int64_t>(field);
  flatbuffers::voffset_t field_offset = field.offset();

  switch (privacy_level) {
    case kPrivate:
      flatbuffers::SetField<int64_t>(table, field, default_val);
      internal::ScrubFromTable(table, field_offset);
      break;
    case kOpaque:
      flatbuffers::SetField<int64_t>(table, field, default_val);
      break;
    case kAnonymized: {
      auto target_field = flatbuffers::GetFieldI<int64_t>(*table, field);
      int64_t new_val = static_cast<int64_t>(std::hash<std::string>{}(std::to_string(target_field)));
      flatbuffers::SetField<int64_t>(table, field, new_val);
    } break;
    default:
    case kAny:
      break;
  }
  return kFieldHasBeenFiltered;
}

bool internal::FilterTypeString(const reflection::Field& field, flatbuffers::Table* table, PrivacyLevel privacy_level) {
  ASSERT(table != nullptr);
  ASSERT(field.type()->base_type() == reflection::BaseType::String);
+2 −1
Original line number Diff line number Diff line
@@ -115,8 +115,9 @@ const reflection::Object* FindReflectionObject(
 * @return true if successfully filtered, false otherwise.
 */
bool FilterTypeBool(const reflection::Field& field, flatbuffers::Table* table, PrivacyLevel privacy_level);
bool FilterTypeInteger(const reflection::Field& field, flatbuffers::Table* table, PrivacyLevel privacy_level);
bool FilterTypeFloat(const reflection::Field& field, flatbuffers::Table* table, PrivacyLevel privacy_level);
bool FilterTypeInteger(const reflection::Field& field, flatbuffers::Table* table, PrivacyLevel privacy_level);
bool FilterTypeLong(const reflection::Field& field, flatbuffers::Table* table, PrivacyLevel privacy_level);
bool FilterTypeString(const reflection::Field& field, flatbuffers::Table* table, PrivacyLevel privacy_level);
bool FilterTypeStruct(const reflection::Field& field, flatbuffers::Table* table, PrivacyLevel privacy_level);