-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <jb/pitch2/unit_clear_message.hpp> | ||
|
||
#include <ostream> | ||
|
||
namespace jb { | ||
namespace pitch2 { | ||
|
||
std::ostream& operator<<(std::ostream& os, unit_clear_message const& x) { | ||
return os << "length=" << static_cast<int>(x.length.value()) | ||
<< ",message_type=" << static_cast<int>(x.message_type.value()) | ||
<< ",time_offset=" << x.time_offset.value(); | ||
} | ||
|
||
} // namespace pitch2 | ||
} // namespace jb | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef jb_pitch2_unit_clear_message_hpp | ||
#define jb_pitch2_unit_clear_message_hpp | ||
|
||
#include <boost/endian/buffers.hpp> | ||
|
||
#include <iosfwd> | ||
#include <utility> | ||
|
||
namespace jb { | ||
namespace pitch2 { | ||
|
||
/** | ||
* Represent the 'Unit Clear' message in the PITCH-2.X protocol. | ||
* | ||
* A full description of the fields can be found in the BATS PITCH-2.X | ||
* specification: | ||
* https://www.batstrading.com/resources/membership/BATS_MC_PITCH_Specification.pdf | ||
*/ | ||
struct unit_clear_message { | ||
/// Define the messsage type | ||
constexpr static int type = 0x97; | ||
|
||
boost::endian::little_uint8_buf_t length; | ||
boost::endian::little_uint8_buf_t message_type; | ||
boost::endian::little_int32_buf_t time_offset; | ||
}; | ||
|
||
/// Streaming operator for jb::pitch2::unit_clear_message. | ||
std::ostream& operator<<(std::ostream& os, unit_clear_message const& x); | ||
|
||
} // namespace pitch2 | ||
} // namespace jb | ||
|
||
#endif // jb_pitch2_unit_clear_message_hpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <jb/pitch2/unit_clear_message.hpp> | ||
|
||
#include <boost/test/unit_test.hpp> | ||
#include <type_traits> | ||
|
||
/** | ||
* @test Verify that jb::pitch2::unit_clear_message works as expected. | ||
*/ | ||
BOOST_AUTO_TEST_CASE(unit_clear_message_basic) { | ||
using namespace jb::pitch2; | ||
BOOST_CHECK_EQUAL(true, std::is_pod<unit_clear_message>::value); | ||
BOOST_CHECK_EQUAL(sizeof(unit_clear_message), std::size_t(6)); | ||
|
||
char const buf[] = | ||
u8"\x06" // Length (6) | ||
"\x97" // Message Type (0x97) | ||
"\x18\xD2\x06\x00" // Time Offset (447,000 ns) | ||
; | ||
unit_clear_message msg; | ||
BOOST_REQUIRE_EQUAL(sizeof(buf) - 1, sizeof(msg)); | ||
std::memcpy(&msg, buf, sizeof(msg)); | ||
BOOST_CHECK_EQUAL(int(msg.length.value()), 6); | ||
BOOST_CHECK_EQUAL(int(msg.message_type.value()), 0x97); | ||
BOOST_CHECK_EQUAL(msg.time_offset.value(), 447000); | ||
|
||
std::ostringstream os; | ||
os << msg; | ||
BOOST_CHECK_EQUAL( | ||
os.str(), std::string("length=6,message_type=151,time_offset=447000")); | ||
} |