std::string get_string(Range &r) { boost::uint16_t const len = detail::get_2byte_size(r); std::string ret; std::copy(r.begin(), detail::get_nth_iterator(r, len), std::back_inserter(ret)); r.advance_begin(len); return ret; }
binary_t get_binary(Range &r) { boost::uint32_t const len = detail::get_size(r); binary_t ret; ret.reserve(len); std::copy(r.begin(), detail::get_nth_iterator(r, len), std::back_inserter(ret)); r.advance_begin(len); return ret; }
atom_t get_atom(Range &r) { boost::uint16_t const len = detail::get_2byte_size(r); assert(r.size() >= len); atom_t ret; std::copy(r.begin(), detail::get_nth_iterator(r, len), std::back_inserter(ret)); r.advance_begin(len); return ret; }
real_t x_get_new_float(Range &r) { char buf[8]; std::copy(r.begin(), detail::get_nth_iterator(r, 8), buf); #ifndef LIBBERT_BIGENDIAN std::reverse(buf, buf+8); #endif r.advance_begin(8); return *reinterpret_cast<real_t*>(buf); }
boost::uint16_t get_2byte_size(Range &r) { assert_bytes_remaining(r,2); #ifdef LIBBERT_BIGENDIAN boost::uint16_t const len = (static_cast<boost::uint16_t>(r[1]) << 8) + r[0]; #else boost::uint16_t const len = (static_cast<boost::uint16_t>(r[0]) << 8) + r[1]; #endif r.advance_begin(2); return len; }
real_t get_float(Range &r) { char buf[32]; std::copy(r.begin(), detail::get_nth_iterator(r, 32), buf); r.advance_begin(32); buf[31] = '\0'; real_t ret; /* yuck! should actually use NEW_FLOAT_EXT but that is not part of the BERT spec. But should be added as an extension! */ std::sscanf(buf, "%lf", &ret); return ret; }
boost::int32_t get_integer(Range &r) { detail::assert_bytes_remaining(r,4); #ifdef LIBBERT_BIGENDIAN boost::int32_t const ret = (static_cast<boost::int32_t>(r[3]) << 24) + (static_cast<boost::int32_t>(r[2]) << 16) + (static_cast<boost::int32_t>(r[1]) << 8) + (r[0]); #else boost::int32_t const ret = (static_cast<boost::int32_t>(r[0]) << 24) + (static_cast<boost::int32_t>(r[1]) << 16) + (static_cast<boost::int32_t>(r[2]) << 8) + (r[3]); #endif r.advance_begin(4); return ret; }
boost::int32_t get_integer(Range &r) { assert(r && r.size() >= 4); #ifdef LIBBERT_BIGENDIAN boost::int32_t const ret = (static_cast<boost::int32_t>(r[3]) << 24) + (static_cast<boost::int32_t>(r[2]) << 16) + (static_cast<boost::int32_t>(r[1]) << 8) + (r[0]); #else boost::int32_t const ret = (static_cast<boost::int32_t>(r[0]) << 24) + (static_cast<boost::int32_t>(r[1]) << 16) + (static_cast<boost::int32_t>(r[2]) << 8) + (r[3]); #endif r.advance_begin(4); return ret; }
byte_t extract_one_byte(Range &r) { assert_bytes_remaining(r,1); byte_t const b = r.front(); r.advance_begin(1); return b; }
byte_t extract_one_byte(Range &r) { assert(r); byte_t const b = r.front(); r.advance_begin(1); return b; }