-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
parsing_utils.h
80 lines (57 loc) · 2.93 KB
/
parsing_utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_ATTRIBUTION_REPORTING_PARSING_UTILS_H_
#define COMPONENTS_ATTRIBUTION_REPORTING_PARSING_UTILS_H_
#include <stdint.h>
#include <string>
#include "base/component_export.h"
#include "base/strings/string_piece_forward.h"
#include "base/values.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace absl {
class uint128;
} // namespace absl
namespace attribution_reporting {
COMPONENT_EXPORT(ATTRIBUTION_REPORTING)
absl::optional<absl::uint128> StringToAggregationKeyPiece(const std::string& s);
COMPONENT_EXPORT(ATTRIBUTION_REPORTING)
std::string HexEncodeAggregationKey(absl::uint128);
COMPONENT_EXPORT(ATTRIBUTION_REPORTING)
bool AggregationKeyIdHasValidLength(const std::string& key);
// Returns false if `dict` contains `key` but the value is invalid (e.g. not a
// string, negative), returns true otherwise.
[[nodiscard]] COMPONENT_EXPORT(ATTRIBUTION_REPORTING) bool ParseUint64(
const base::Value::Dict& dict,
base::StringPiece key,
absl::optional<uint64_t>& out);
// Returns false if `dict` contains `key` but the value is invalid (e.g. not a
// string, int64 overflow), returns true otherwise.
[[nodiscard]] COMPONENT_EXPORT(ATTRIBUTION_REPORTING) bool ParseInt64(
const base::Value::Dict& dict,
base::StringPiece key,
absl::optional<int64_t>& out);
// Returns false if `dict` contains `priority` key but the value is invalid,
// returns true otherwise.
[[nodiscard]] bool ParsePriority(const base::Value::Dict& dict,
absl::optional<int64_t>& out);
// Returns `debug_key` value as we do not need to fail the source registration
// if the value is invalid, see
// https://github.com/WICG/attribution-reporting-api/issues/793 for context.
absl::optional<uint64_t> ParseDebugKey(const base::Value::Dict& dict);
// Returns false if `dict` contains `debug_reporting` key but the value is
// invalid, returns true otherwise.
[[nodiscard]] bool ParseDebugReporting(const base::Value::Dict& dict);
// Returns false if `dict` contains `deduplication_key` key but the value is
// invalid, returns true otherwise.
[[nodiscard]] bool ParseDeduplicationKey(const base::Value::Dict& dict,
absl::optional<uint64_t>& out);
void SerializeUint64(base::Value::Dict&, base::StringPiece key, uint64_t value);
void SerializeInt64(base::Value::Dict&, base::StringPiece key, int64_t value);
void SerializePriority(base::Value::Dict&, int64_t priority);
void SerializeDebugKey(base::Value::Dict&, absl::optional<uint64_t> debug_key);
void SerializeDebugReporting(base::Value::Dict&, bool debug_reporting);
void SerializeDeduplicationKey(base::Value::Dict&,
absl::optional<uint64_t> dedup_key);
} // namespace attribution_reporting
#endif // COMPONENTS_ATTRIBUTION_REPORTING_PARSING_UTILS_H_