5#ifndef NDS2_CLIENT_BASIC_IO_HH
6#define NDS2_CLIENT_BASIC_IO_HH
25 template <
typename BufferedReader >
40 r_.read_exactly( result.data( ),
41 result.data( ) + result.size( ) );
54 std::array< char, 8 > buf;
55 r_.read_exactly( buf.data( ), buf.data( ) + buf.size( ) );
56 for (
const auto byte : buf )
72 return *
reinterpret_cast< float*
>( &tmp );
81 if ( nibble >=
'0' && nibble <=
'9' )
85 if ( nibble >=
'a' && nibble <=
'f' )
87 return ( nibble -
'a' ) + 10;
89 if ( nibble >=
'A' && nibble <=
'F' )
91 return ( nibble -
'A' ) + 10;
93 throw std::invalid_argument(
94 "Unknown input found while converting a hex value" );
105#ifdef _NDS_IMPL_ENABLE_CATCH_TESTS_
112TEST_CASE(
"You should be able to create a basic_io object",
113 "[nds2,basic_io,create]" )
120 sock_type buf_s( s );
124TEST_CASE(
"You should be able to read a nds1 status code",
"[nds1]" )
132 sock_type buf_s1( s1 );
135 REQUIRE( b.read_status_code( ) == STATUS_DAQD_OK );
136 REQUIRE( b.read_status_code( ) == STATUS_DAQD_NOT_FOUND );
139TEST_CASE(
"You should be able to read a 32bit ascii/hex value",
140 "[nds1,basic_io,hex]" )
146 sock_type buf_s1( s1 );
149 REQUIRE( b.read_uint32_hex( ) == 0x340 );
150 REQUIRE( b.read_uint32_hex( ) == 0x0 );
151 REQUIRE( b.read_uint32_hex( ) == 0xf7f8f9ab );
154TEST_CASE(
"Exceptions are thrown when reading a bad 32bit ascii/hex value",
155 "[nds1,basic_io,hex]" )
163 sock_type buf_s1( s1 );
166 REQUIRE_THROWS_AS( b.read_uint32_hex( ), std::invalid_argument );
167 REQUIRE_THROWS( b.read_uint32_hex( ) );
170TEST_CASE(
"You should be able to read a 32bit float ascii/hex value",
171 "[nds1,basic_io,hex]" )
177 sock_type buf_s1( s1 );
180 REQUIRE( b.read_float32_hex( ) == 1.0f );
184 "Exceptions are thrown when reading a bad 32bit float ascii/hex value",
185 "[nds1,basic_io,hex]" )
193 sock_type buf_s1( s1 );
196 REQUIRE_THROWS_AS( b.read_float32_hex( ), std::invalid_argument );
197 REQUIRE_THROWS( b.read_float32_hex( ) );
Definition buffered_reader.hh:18
Definition basic_io.hh:27
int from_hex_nibble(int nibble)
Definition basic_io.hh:79
Basic_IO(BufferedReader &r)
Definition basic_io.hh:29
BufferedReader & r_
Definition basic_io.hh:76
nds_impl::common::status_code read_status_code()
Definition basic_io.hh:37
float read_float32_hex()
Definition basic_io.hh:69
std::uint32_t read_uint32_hex()
Definition basic_io.hh:51
Definition span_reader.hh:16
std::array< char, 4 > status_code
Definition status_codes.hh:14
Definition span_reader.hh:14
Definition dummy_socket.hh:13
Definition dummy_socket.hh:46
TEST_CASE("daq_strlcpy copies strings safely when buffers are sufficiently large")
Definition test_bsd_string.cc:9