iterator_range<const_fixed_iterator<T>> packed_fixed() { protozero_assert(tag() != 0 && "call next() before accessing field value"); const auto len = get_len_and_skip(); protozero_assert(len % sizeof(T) == 0); return iterator_range<const_fixed_iterator<T>>{const_fixed_iterator<T>(m_data - len, m_data), const_fixed_iterator<T>(m_data, m_data)}; }
bool pbf_reader::get_bool() { protozero_assert(tag() != 0 && "call next() before accessing field value"); protozero_assert(has_wire_type(pbf_wire_type::varint) && "not a varint"); protozero_assert((*m_data & 0x80) == 0 && "not a 1 byte varint"); skip_bytes(1); return m_data[-1] != 0; // -1 okay because we incremented m_data the line before }
std::pair<const char*, pbf_length_type> pbf_reader::get_data() { protozero_assert(tag() != 0 && "call next() before accessing field value"); protozero_assert(has_wire_type(pbf_wire_type::length_delimited) && "not of type string, bytes or message"); auto len = get_len_and_skip(); return std::make_pair(m_data-len, len); }
double pbf_reader::get_double() { protozero_assert(tag() != 0 && "call next() before accessing field value"); protozero_assert(has_wire_type(pbf_wire_type::fixed64) && "not a 64-bit fixed"); return get_fixed<double>(); }
float pbf_reader::get_float() { protozero_assert(tag() != 0 && "call next() before accessing field value"); protozero_assert(has_wire_type(pbf_wire_type::fixed32) && "not a 32-bit fixed"); return get_fixed<float>(); }
T pbf_reader::get_svarint() { protozero_assert((has_wire_type(pbf_wire_type::varint) || has_wire_type(pbf_wire_type::length_delimited)) && "not a varint"); return static_cast<T>(decode_zigzag64(decode_varint(&m_data, m_end))); }
std::pair<pbf_reader::const_sint64_iterator, pbf_reader::const_sint64_iterator> pbf_reader::get_packed_sint64() { protozero_assert(tag() != 0 && "call next() before accessing field value"); auto len = get_len_and_skip(); return std::make_pair(pbf_reader::const_sint64_iterator(m_data-len, m_data), pbf_reader::const_sint64_iterator(m_data, m_data)); }
iterator_range<T> get_packed() { protozero_assert(tag() != 0 && "call next() before accessing field value"); const auto len = get_len_and_skip(); return iterator_range<T>{T{m_data - len, m_data}, T{m_data, m_data}}; }