Skip to content

Commit 7f39978

Browse files
committed
FIX: Fix setting ts_event during DBNv2 upgrade
1 parent 769ae66 commit 7f39978

File tree

7 files changed

+31
-21
lines changed

7 files changed

+31
-21
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 0.17.1 - TBD
4+
5+
### Bug fixes
6+
- Added missing copying of `ts_event` when upgrading structs from DBNv1 to DBNv2
7+
- Fixed setting of compiler warnings and warnings that had accumulated
8+
39
## 0.17.0 - 2024-04-01
410

511
### Enhancements

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ message(STATUS "Added all header and implementation files.")
102102

103103
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
104104
include(cmake/CompilerWarnings.cmake)
105-
set_project_warnings(${PROJECT_NAME})
105+
set_target_warnings(${PROJECT_NAME})
106106
include(cmake/Sanitizers.cmake)
107107

108108
# Ensure std::string debug info is included

cmake/CompilerWarnings.cmake

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# from here:
22
#
3-
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Avai
4-
# lable.md
3+
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md
54
# Courtesy of Jason Turner
65

7-
function(set_project_warnings project_name)
6+
function(set_target_warnings target)
87
set(MSVC_WARNINGS
98
/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss
109
# of data
@@ -89,9 +88,5 @@ function(set_project_warnings project_name)
8988
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
9089
endif()
9190

92-
add_compile_options(${PROJECT_WARNINGS})
93-
94-
if(NOT TARGET ${project_name})
95-
message(AUTHOR_WARNING "${project_name} is not a target, thus no compiler warning were added.")
96-
endif()
91+
target_compile_options(${target} PRIVATE ${PROJECT_WARNINGS})
9792
endfunction()

cmake/Utils.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ function(add_example_target name file)
5555
databento::databento
5656
)
5757
target_compile_features(${name} PUBLIC cxx_std_11)
58+
set_target_warnings(${name})
5859
endfunction()

src/compat.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace databento {
1111
InstrumentDefMsgV2 InstrumentDefMsgV1::ToV2() const {
1212
InstrumentDefMsgV2 ret{
1313
RecordHeader{sizeof(InstrumentDefMsgV2) / RecordHeader::kLengthMultiplier,
14-
RType::InstrumentDef, hd.publisher_id, hd.instrument_id},
14+
RType::InstrumentDef, hd.publisher_id, hd.instrument_id,
15+
hd.ts_event},
1516
ts_recv,
1617
min_price_increment,
1718
display_factor,
@@ -72,7 +73,7 @@ InstrumentDefMsgV2 InstrumentDefMsgV1::ToV2() const {
7273
contract_multiplier_unit,
7374
flow_schedule_type,
7475
tick_rule,
75-
};
76+
{}};
7677
std::copy(currency.begin(), currency.end(), ret.currency.begin());
7778
std::copy(settl_currency.begin(), settl_currency.end(),
7879
ret.settl_currency.begin());
@@ -95,7 +96,8 @@ InstrumentDefMsgV2 InstrumentDefMsgV1::ToV2() const {
9596
ErrorMsgV2 ErrorMsgV1::ToV2() const {
9697
ErrorMsgV2 ret{
9798
RecordHeader{sizeof(ErrorMsgV2) / RecordHeader::kLengthMultiplier,
98-
RType::Error, hd.publisher_id, hd.instrument_id},
99+
RType::Error, hd.publisher_id, hd.instrument_id,
100+
hd.ts_event},
99101
{},
100102
std::numeric_limits<std::uint8_t>::max(),
101103
std::numeric_limits<std::uint8_t>::max()};
@@ -106,7 +108,8 @@ ErrorMsgV2 ErrorMsgV1::ToV2() const {
106108
SymbolMappingMsgV2 SymbolMappingMsgV1::ToV2() const {
107109
SymbolMappingMsgV2 ret{
108110
RecordHeader{sizeof(SymbolMappingMsgV2) / RecordHeader::kLengthMultiplier,
109-
RType::SymbolMapping, hd.publisher_id, hd.instrument_id},
111+
RType::SymbolMapping, hd.publisher_id, hd.instrument_id,
112+
hd.ts_event},
110113
// invalid
111114
static_cast<SType>(std::numeric_limits<std::uint8_t>::max()),
112115
{},
@@ -125,7 +128,8 @@ SymbolMappingMsgV2 SymbolMappingMsgV1::ToV2() const {
125128
SystemMsgV2 SystemMsgV1::ToV2() const {
126129
SystemMsgV2 ret{
127130
RecordHeader{sizeof(SystemMsgV2) / RecordHeader::kLengthMultiplier,
128-
RType::System, hd.publisher_id, hd.instrument_id},
131+
RType::System, hd.publisher_id, hd.instrument_id,
132+
hd.ts_event},
129133
{},
130134
std::numeric_limits<std::uint8_t>::max()};
131135
std::copy(msg.begin(), msg.end(), ret.msg.begin());

src/dbn_decoder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ std::string Consume(std::vector<std::uint8_t>::const_iterator& byte_it,
5252
const std::ptrdiff_t num_bytes, const char* context) {
5353
const auto cstr = Consume(byte_it, num_bytes);
5454
// strnlen isn't portable
55-
const std::size_t str_len = std::find(cstr, cstr + num_bytes, '\0') - cstr;
55+
const auto str_len = std::find(cstr, cstr + num_bytes, '\0') - cstr;
5656
if (str_len == num_bytes) {
5757
throw databento::DbnResponseError{std::string{"Invalid "} + context +
5858
" missing null terminator"};
5959
}
60-
return std::string{cstr, str_len};
60+
return std::string{cstr, static_cast<std::size_t>(str_len)};
6161
}
6262
} // namespace
6363

test/src/dbn_decoder_tests.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,17 @@ TEST_F(DbnDecoderTests, TestUpgradeSymbolMappingWithTsOut) {
157157
DbnDecoder::DecodeRecordCompat(1, VersionUpgradePolicy::Upgrade, true,
158158
&compat_buffer, Record{&orig.rec.hd});
159159
const auto& upgraded = res.Get<WithTsOut<SymbolMappingMsgV2>>();
160-
ASSERT_EQ(orig.ts_out, upgraded.ts_out);
161-
ASSERT_STREQ(orig.rec.STypeInSymbol(), upgraded.rec.STypeInSymbol());
162-
ASSERT_STREQ(orig.rec.STypeOutSymbol(), upgraded.rec.STypeOutSymbol());
160+
EXPECT_EQ(orig.rec.hd.rtype, upgraded.rec.hd.rtype);
161+
EXPECT_EQ(orig.rec.hd.instrument_id, upgraded.rec.hd.instrument_id);
162+
EXPECT_EQ(orig.rec.hd.publisher_id, upgraded.rec.hd.publisher_id);
163+
EXPECT_EQ(orig.rec.hd.ts_event, upgraded.rec.hd.ts_event);
164+
EXPECT_EQ(orig.ts_out, upgraded.ts_out);
165+
EXPECT_STREQ(orig.rec.STypeInSymbol(), upgraded.rec.STypeInSymbol());
166+
EXPECT_STREQ(orig.rec.STypeOutSymbol(), upgraded.rec.STypeOutSymbol());
163167
// `length` properly set
164-
ASSERT_EQ(upgraded.rec.hd.Size(), sizeof(upgraded));
168+
EXPECT_EQ(upgraded.rec.hd.Size(), sizeof(upgraded));
165169
// used compat buffer
166-
ASSERT_EQ(reinterpret_cast<const std::uint8_t*>(&upgraded),
170+
EXPECT_EQ(reinterpret_cast<const std::uint8_t*>(&upgraded),
167171
compat_buffer.data());
168172
}
169173

0 commit comments

Comments
 (0)