Skip to content

Commit ce5d0e7

Browse files
committed
ADD: Add operator to convert FlagSet to Repr
1 parent dc67bbc commit ce5d0e7

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

include/databento/compat.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ static constexpr std::size_t kSymbolCstrLenV1 = 22;
1414
static constexpr std::size_t kSymbolCstrLenV2 = kSymbolCstrLen;
1515

1616
constexpr std::size_t VersionSymbolCstrLen(std::uint8_t version) {
17-
if (version < 2) {
18-
return kSymbolCstrLenV1;
19-
}
20-
return kSymbolCstrLenV2;
17+
return version < 2 ? kSymbolCstrLenV1 : kSymbolCstrLenV2;
2118
}
2219

2320
using InstrumentDefMsgV2 = InstrumentDefMsg;
@@ -111,7 +108,8 @@ struct InstrumentDefMsgV1 {
111108
// padding for alignment
112109
std::array<char, 3> dummy;
113110
};
114-
static_assert(sizeof(InstrumentDefMsgV1) == 360);
111+
static_assert(sizeof(InstrumentDefMsgV1) == 360, "Size must match Rust");
112+
static_assert(alignof(InstrumentDefMsgV1) == 8, "Must have 8-byte alignment");
115113

116114
/// A symbol mapping message.
117115
struct SymbolMappingMsgV1 {
@@ -129,7 +127,8 @@ struct SymbolMappingMsgV1 {
129127
UnixNanos start_ts;
130128
UnixNanos end_ts;
131129
};
132-
static_assert(sizeof(SymbolMappingMsgV1) == 80);
130+
static_assert(sizeof(SymbolMappingMsgV1) == 80, "Size must match Rust");
131+
static_assert(alignof(SymbolMappingMsgV1) == 8, "Must have 8-byte alignment");
133132

134133
bool operator==(const InstrumentDefMsgV1& lhs, const InstrumentDefMsgV1& rhs);
135134
inline bool operator!=(const InstrumentDefMsgV1& lhs,

include/databento/flag_set.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class FlagSet {
3434
std::uint8_t repr)
3535
: repr_{repr} {}
3636

37+
explicit constexpr operator std::uint8_t() const { return repr_; }
38+
3739
constexpr FlagSet operator~() const {
3840
return FlagSet{static_cast<Repr>(~repr_)};
3941
}

include/databento/record.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct MboMsg {
8787
std::uint32_t sequence;
8888
};
8989
static_assert(sizeof(MboMsg) == 56, "MboMsg size must match Rust");
90-
static_assert(alignof(MboMsg) == 8);
90+
static_assert(alignof(MboMsg) == 8, "Must have 8-byte alignment");
9191

9292
struct BidAskPair {
9393
std::int64_t bid_px;
@@ -98,7 +98,7 @@ struct BidAskPair {
9898
std::uint32_t ask_ct;
9999
};
100100
static_assert(sizeof(BidAskPair) == 32, "BidAskPair size must match Rust");
101-
static_assert(alignof(BidAskPair) == 8);
101+
static_assert(alignof(BidAskPair) == 8, "Must have 8-byte alignment");
102102

103103
namespace detail {
104104
template <std::size_t N>
@@ -144,14 +144,14 @@ struct TradeMsg {
144144
std::uint32_t sequence;
145145
};
146146
static_assert(sizeof(TradeMsg) == 48, "TradeMsg size must match Rust");
147-
static_assert(alignof(TradeMsg) == 8);
147+
static_assert(alignof(TradeMsg) == 8, "Must have 8-byte alignment");
148148

149149
using Mbp1Msg = detail::MbpMsg<1>;
150150
using TbboMsg = Mbp1Msg;
151151
using Mbp10Msg = detail::MbpMsg<10>;
152152

153-
static_assert(alignof(Mbp1Msg) == 8);
154-
static_assert(alignof(Mbp10Msg) == 8);
153+
static_assert(alignof(Mbp1Msg) == 8, "Must have 8-byte alignment");
154+
static_assert(alignof(Mbp10Msg) == 8, "Must have 8-byte alignment");
155155
static_assert(sizeof(Mbp1Msg) == sizeof(TradeMsg) + sizeof(BidAskPair),
156156
"Mbp1Msg size must match Rust");
157157
static_assert(sizeof(Mbp10Msg) == sizeof(TradeMsg) + sizeof(BidAskPair) * 10,
@@ -182,7 +182,7 @@ struct OhlcvMsg {
182182
std::uint64_t volume;
183183
};
184184
static_assert(sizeof(OhlcvMsg) == 56, "OhlcvMsg size must match Rust");
185-
static_assert(alignof(OhlcvMsg) == 8);
185+
static_assert(alignof(OhlcvMsg) == 8, "Must have 8-byte alignment");
186186

187187
// Instrument definition.
188188
struct InstrumentDefMsg {
@@ -269,7 +269,7 @@ struct InstrumentDefMsg {
269269
};
270270
static_assert(sizeof(InstrumentDefMsg) == 400,
271271
"InstrumentDefMsg size must match Rust");
272-
static_assert(alignof(InstrumentDefMsg) == 8);
272+
static_assert(alignof(InstrumentDefMsg) == 8, "Must have 8-byte alignment");
273273

274274
// An order imbalance message.
275275
struct ImbalanceMsg {
@@ -302,7 +302,7 @@ struct ImbalanceMsg {
302302
std::array<char, 1> dummy;
303303
};
304304
static_assert(sizeof(ImbalanceMsg) == 112, "ImbalanceMsg size must match Rust");
305-
static_assert(alignof(ImbalanceMsg) == 8);
305+
static_assert(alignof(ImbalanceMsg) == 8, "Must have 8-byte alignment");
306306

307307
/// A statistics message. A catchall for various data disseminated by
308308
/// publishers. The `stat_type` indicates the statistic contained in the
@@ -326,7 +326,7 @@ struct StatMsg {
326326
std::array<char, 6> dummy;
327327
};
328328
static_assert(sizeof(StatMsg) == 64, "StatMsg size must match Rust");
329-
static_assert(alignof(StatMsg) == 8);
329+
static_assert(alignof(StatMsg) == 8, "Must have 8-byte alignment");
330330

331331
// An error message from the Live Subscription Gateway (LSG). This will never
332332
// be present in historical data.
@@ -340,7 +340,7 @@ struct ErrorMsg {
340340
std::array<char, 64> err;
341341
};
342342
static_assert(sizeof(ErrorMsg) == 80, "ErrorMsg size must match Rust");
343-
static_assert(alignof(ErrorMsg) == 8);
343+
static_assert(alignof(ErrorMsg) == 8, "Must have 8-byte alignment");
344344

345345
/// A symbol mapping message.
346346
struct SymbolMappingMsg {
@@ -360,7 +360,7 @@ struct SymbolMappingMsg {
360360
};
361361
static_assert(sizeof(SymbolMappingMsg) == 176,
362362
"SymbolMappingMsg size must match Rust");
363-
static_assert(alignof(SymbolMappingMsg) == 8);
363+
static_assert(alignof(SymbolMappingMsg) == 8, "Must have 8-byte alignment");
364364

365365
struct SystemMsg {
366366
static bool HasRType(RType rtype) { return rtype == RType::System; }
@@ -375,7 +375,7 @@ struct SystemMsg {
375375
std::array<char, 64> msg;
376376
};
377377
static_assert(sizeof(SystemMsg) == 80, "SystemMsg size must match Rust");
378-
static_assert(alignof(SystemMsg) == 8);
378+
static_assert(alignof(SystemMsg) == 8, "Must have 8-byte alignment");
379379

380380
inline bool operator==(const RecordHeader& lhs, const RecordHeader& rhs) {
381381
return lhs.length == rhs.length && lhs.rtype == rhs.rtype &&

test/src/flag_set_tests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,11 @@ TEST(FlagSetTests, TestToString) {
6060
ss << kFlagSet;
6161
ASSERT_EQ(ss.str(), "0b00010000");
6262
}
63+
64+
TEST(FlagSetTests, TestConversionOperator) {
65+
constexpr FlagSet kFlagSet = FlagSet::kMbp | FlagSet::kTob;
66+
const auto raw = std::uint8_t{kFlagSet};
67+
ASSERT_EQ(raw, 0b01010000);
68+
}
6369
} // namespace test
6470
} // namespace databento

0 commit comments

Comments
 (0)