19
19
20
20
#include < type_traits>
21
21
22
- #include < nop/structure.h>
23
22
#include < nop/base/macros.h>
23
+ #include < nop/structure.h>
24
24
#include < nop/types/optional.h>
25
25
#include < nop/utility/sip_hash.h>
26
26
@@ -46,7 +46,7 @@ namespace nop {
46
46
// struct MyTable {
47
47
// Entry<Address, 0> address;
48
48
// Entry<PhoneNumber, 1> phone_number;
49
- // NOP_TABLE("MyTable", MyTable, address, phone_number);
49
+ // NOP_TABLE(MyTable, address, phone_number);
50
50
// };
51
51
//
52
52
// Example of handling empty values:
@@ -62,8 +62,8 @@ namespace nop {
62
62
// HandlePhoneNumber(my_table.phone_number.get());
63
63
//
64
64
// Table entries may be public, private, or protected, depending on how the
65
- // table type will be used. If the entries are non-public, call NOP_TABLE() in a
66
- // private section to avoid exposing member pointers to arbitrary code.
65
+ // table type will be used. If the entries are non-public, call NOP_TABLE* () in
66
+ // a private section to avoid exposing member pointers to arbitrary code.
67
67
//
68
68
// Use the following rules to maximize compatability between different versions
69
69
// of a table type:
@@ -74,10 +74,11 @@ namespace nop {
74
74
// old entry id.
75
75
// 3. Never change the Id for an entry. Doing so will break compatibility with
76
76
// older versions of serialized data.
77
- // 4. Never change the string name passed as the first argument to the macro
78
- // NOP_TABLE. This is used to compute a hash used for sanity checking
79
- // during deserialization. Changing this string will break compatibility
80
- // with older versions of serialized data.
77
+ // 4. Never change the namespace hash or namespace string passed as the first
78
+ // argument to the macros NOP_TABLE_HASH / NOP_TABLE_NS. These values are
79
+ // used for sanity checking during deserialization. Changing these
80
+ // arguments will break compatibility with older versions of serialized
81
+ // data.
81
82
//
82
83
83
84
// Type tags to define used and deprecated entries.
@@ -173,23 +174,34 @@ enum : std::uint64_t {
173
174
kNopTableKey1 = 0x0123456789abcdef ,
174
175
};
175
176
176
- // Defines a table type, its hash, and its members. This macro should be call
177
- // once within a table struct or class to inform the serialization engine about
178
- // the table members and hash value. This is accomplished by befriending several
179
- // key classes and defining an internal type named NOP__ENTRIES that describes
180
- // the table type's Entry<T, Id> members.
181
- #define NOP_TABLE (string_name, type, ... /* entries*/ ) \
182
- template <typename , typename > \
183
- friend struct ::nop::Encoding; \
184
- template <typename , typename > \
185
- friend struct ::nop::HasEntryList; \
186
- template <typename > \
187
- friend struct ::nop::EntryListTraits; \
188
- using NOP__ENTRIES = ::nop::EntryList< \
189
- ::nop::HashValue<::nop::SipHash::Compute( \
190
- string_name, ::nop::kNopTableKey0 , ::nop::kNopTableKey1 )>, \
191
- NOP_MEMBER_LIST (type, __VA_ARGS__)>
177
+ // Defines a table type, its namespace hash, and its members. This macro must be
178
+ // invoked once within a table struct or class to inform the serialization
179
+ // engine about the table members and hash value. This is accomplished by
180
+ // befriending several key classes and defining an internal type named
181
+ // NOP__ENTRIES that describes the table type's Entry<T, Id> members.
182
+ #define NOP_TABLE_HASH (hash, type, ... /* entries*/ ) \
183
+ template <typename , typename > \
184
+ friend struct ::nop::Encoding; \
185
+ template <typename , typename > \
186
+ friend struct ::nop::HasEntryList; \
187
+ template <typename > \
188
+ friend struct ::nop::EntryListTraits; \
189
+ using NOP__ENTRIES = ::nop::EntryList<::nop::HashValue<hash>, \
190
+ NOP_MEMBER_LIST (type, __VA_ARGS__)>
191
+
192
+ // Similar to NOP_TABLE_HASH except that the namespace hash is computed from a
193
+ // compile-time hash of the given string literal that defines the namespace of
194
+ // the table.
195
+ #define NOP_TABLE_NS (string_name, type, ... /* entries*/ ) \
196
+ NOP_TABLE_HASH (::nop::SipHash::Compute(string_name, ::nop::kNopTableKey0 , \
197
+ ::nop::kNopTableKey1 ), \
198
+ type, __VA_ARGS__)
199
+
200
+ // Similar to NOP_TABLE_HASH except that the namespace hash is set to zero,
201
+ // which has a compact encoding compared to average 64bit hash values. This
202
+ // saves space in the encoding when namespace checks are not desired.
203
+ #define NOP_TABLE (type, ... /* entries*/ ) NOP_TABLE_HASH(0 , type, __VA_ARGS__)
192
204
193
205
} // namespace nop
194
206
195
- #endif // LIBNOP_INCLUDE_NOP_TABLE_H_
207
+ #endif // LIBNOP_INCLUDE_NOP_TABLE_H_
0 commit comments