void add_field(pbf_tag_type tag, pbf_wire_type type) {
protozero_assert(((tag > 0 && tag < 19000) || (tag > 19999 && tag <= ((1U << 29U) - 1))) && "tag out of range");
- const uint32_t b = (tag << 3U) | uint32_t(type);
+ const uint32_t b = (tag << 3U) | static_cast<uint32_t>(type);
add_varint(b);
}
}
template <typename T, typename It>
- void add_packed_fixed(pbf_tag_type tag, It first, It last, std::input_iterator_tag /*unused*/) {
+ void add_packed_fixed(pbf_tag_type tag, It first, It last, std::input_iterator_tag /*unused*/) { // NOLINT(performance-unnecessary-value-param)
if (first == last) {
return;
}
}
template <typename T, typename It>
- void add_packed_fixed(pbf_tag_type tag, It first, It last, std::forward_iterator_tag /*unused*/) {
+ void add_packed_fixed(pbf_tag_type tag, It first, It last, std::forward_iterator_tag /*unused*/) { // NOLINT(performance-unnecessary-value-param)
if (first == last) {
return;
}
}
template <typename It>
- void add_packed_varint(pbf_tag_type tag, It first, It last) {
+ void add_packed_varint(pbf_tag_type tag, It first, It last) { // NOLINT(performance-unnecessary-value-param)
if (first == last) {
return;
}
}
template <typename It>
- void add_packed_svarint(pbf_tag_type tag, It first, It last) {
+ void add_packed_svarint(pbf_tag_type tag, It first, It last) { // NOLINT(performance-unnecessary-value-param)
if (first == last) {
return;
}
// a length-delimited field. The length has to fit into pbf_length_type,
// and a varint needs 8 bit for every 7 bit.
enum : int {
- reserve_bytes = sizeof(pbf_length_type) * 8 / 7 + 1
+ reserve_bytes = (sizeof(pbf_length_type) * 8 / 7) + 1
};
// If m_rollpack_pos is set to this special value, it means that when
buffer_customization<TBuffer>::append_zeros(m_data, std::size_t(reserve_bytes));
} else {
m_rollback_pos = size_is_known;
- add_length_varint(tag, pbf_length_type(size));
+ add_length_varint(tag, static_cast<pbf_length_type>(size));
reserve(size);
}
m_pos = buffer_customization<TBuffer>::size(m_data);
add_field(tag, pbf_wire_type::varint);
protozero_assert(m_pos == 0 && "you can't add fields to a parent basic_pbf_writer if there is an existing basic_pbf_writer for a submessage");
protozero_assert(m_data);
- m_data->push_back(char(value));
+ m_data->push_back(static_cast<char>(value));
}
/**
* @param value Value to be written
*/
void add_enum(pbf_tag_type tag, int32_t value) {
- add_tagged_varint(tag, uint64_t(value));
+ add_tagged_varint(tag, static_cast<uint64_t>(value));
}
/**
* @param value Value to be written
*/
void add_int32(pbf_tag_type tag, int32_t value) {
- add_tagged_varint(tag, uint64_t(value));
+ add_tagged_varint(tag, static_cast<uint64_t>(value));
}
/**
* @param value Value to be written
*/
void add_int64(pbf_tag_type tag, int64_t value) {
- add_tagged_varint(tag, uint64_t(value));
+ add_tagged_varint(tag, static_cast<uint64_t>(value));
}
/**
protozero_assert(m_pos == 0 && "you can't add fields to a parent basic_pbf_writer if there is an existing basic_pbf_writer for a submessage");
protozero_assert(m_data);
protozero_assert(size <= std::numeric_limits<pbf_length_type>::max());
- add_length_varint(tag, pbf_length_type(size));
+ add_length_varint(tag, static_cast<pbf_length_type>(size));
buffer_customization<TBuffer>::append(m_data, value, size);
}
size_t sum_size = 0;
(void)std::initializer_list<size_t>{sum_size += values.size()...};
protozero_assert(sum_size <= std::numeric_limits<pbf_length_type>::max());
- add_length_varint(tag, pbf_length_type(sum_size));
+ add_length_varint(tag, static_cast<pbf_length_type>(sum_size));
buffer_customization<TBuffer>::reserve_additional(m_data, sum_size);
(void)std::initializer_list<int>{(buffer_customization<TBuffer>::append(m_data, values.data(), values.size()), 0)...};
}
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_bool(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_bool(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_varint(tag, first, last);
}
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_enum(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_enum(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_varint(tag, first, last);
}
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_int32(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_int32(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_varint(tag, first, last);
}
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_sint32(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_sint32(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_svarint(tag, first, last);
}
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_uint32(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_uint32(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_varint(tag, first, last);
}
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_int64(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_int64(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_varint(tag, first, last);
}
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_sint64(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_sint64(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_svarint(tag, first, last);
}
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_uint64(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_uint64(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_varint(tag, first, last);
}
* @param last Iterator pointing one past the end of data
*/
template <typename ValueType, typename InputIterator>
- void add_packed_fixed(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_fixed(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
static_assert(std::is_same<ValueType, uint32_t>::value ||
std::is_same<ValueType, int32_t>::value ||
std::is_same<ValueType, int64_t>::value ||
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_fixed32(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_fixed32(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_fixed<uint32_t, InputIterator>(tag, first, last,
typename std::iterator_traits<InputIterator>::iterator_category{});
}
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_sfixed32(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_sfixed32(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_fixed<int32_t, InputIterator>(tag, first, last,
typename std::iterator_traits<InputIterator>::iterator_category{});
}
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_fixed64(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_fixed64(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_fixed<uint64_t, InputIterator>(tag, first, last,
typename std::iterator_traits<InputIterator>::iterator_category{});
}
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_sfixed64(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_sfixed64(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_fixed<int64_t, InputIterator>(tag, first, last,
typename std::iterator_traits<InputIterator>::iterator_category{});
}
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_float(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_float(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_fixed<float, InputIterator>(tag, first, last,
typename std::iterator_traits<InputIterator>::iterator_category{});
}
* @param last Iterator pointing one past the end of data
*/
template <typename InputIterator>
- void add_packed_double(pbf_tag_type tag, InputIterator first, InputIterator last) {
+ void add_packed_double(pbf_tag_type tag, InputIterator first, InputIterator last) { // NOLINT(performance-unnecessary-value-param)
add_packed_fixed<double, InputIterator>(tag, first, last,
typename std::iterator_traits<InputIterator>::iterator_category{});
}
/**
* The maximum length of a 64 bit varint.
*/
-constexpr const int8_t max_varint_length = sizeof(uint64_t) * 8 / 7 + 1;
+constexpr const int8_t max_varint_length = (sizeof(uint64_t) * 8 / 7) + 1;
namespace detail {
if (iend - begin >= max_varint_length) { // fast path
do {
int64_t b = *p++;
- val = ((uint64_t(b) & 0x7fU) ); if (b >= 0) { break; }
- b = *p++; val |= ((uint64_t(b) & 0x7fU) << 7U); if (b >= 0) { break; }
- b = *p++; val |= ((uint64_t(b) & 0x7fU) << 14U); if (b >= 0) { break; }
- b = *p++; val |= ((uint64_t(b) & 0x7fU) << 21U); if (b >= 0) { break; }
- b = *p++; val |= ((uint64_t(b) & 0x7fU) << 28U); if (b >= 0) { break; }
- b = *p++; val |= ((uint64_t(b) & 0x7fU) << 35U); if (b >= 0) { break; }
- b = *p++; val |= ((uint64_t(b) & 0x7fU) << 42U); if (b >= 0) { break; }
- b = *p++; val |= ((uint64_t(b) & 0x7fU) << 49U); if (b >= 0) { break; }
- b = *p++; val |= ((uint64_t(b) & 0x7fU) << 56U); if (b >= 0) { break; }
- b = *p++; val |= ((uint64_t(b) & 0x01U) << 63U); if (b >= 0) { break; }
+ val = ((static_cast<uint64_t>(b) & 0x7fU) ); if (b >= 0) { break; }
+ b = *p++; val |= ((static_cast<uint64_t>(b) & 0x7fU) << 7U); if (b >= 0) { break; }
+ b = *p++; val |= ((static_cast<uint64_t>(b) & 0x7fU) << 14U); if (b >= 0) { break; }
+ b = *p++; val |= ((static_cast<uint64_t>(b) & 0x7fU) << 21U); if (b >= 0) { break; }
+ b = *p++; val |= ((static_cast<uint64_t>(b) & 0x7fU) << 28U); if (b >= 0) { break; }
+ b = *p++; val |= ((static_cast<uint64_t>(b) & 0x7fU) << 35U); if (b >= 0) { break; }
+ b = *p++; val |= ((static_cast<uint64_t>(b) & 0x7fU) << 42U); if (b >= 0) { break; }
+ b = *p++; val |= ((static_cast<uint64_t>(b) & 0x7fU) << 49U); if (b >= 0) { break; }
+ b = *p++; val |= ((static_cast<uint64_t>(b) & 0x7fU) << 56U); if (b >= 0) { break; }
+ b = *p++; val |= ((static_cast<uint64_t>(b) & 0x01U) << 63U); if (b >= 0) { break; }
throw varint_too_long_exception{};
} while (false);
} else {
unsigned int shift = 0;
while (p != iend && *p < 0) {
- val |= (uint64_t(*p++) & 0x7fU) << shift;
+ val |= (static_cast<uint64_t>(*p++) & 0x7fU) << shift;
shift += 7;
}
if (p == iend) {
throw end_of_buffer_exception{};
}
- val |= uint64_t(*p++) << shift;
+ val |= static_cast<uint64_t>(*p++) << shift;
}
*data = reinterpret_cast<const char*>(p);
int n = 1;
while (value >= 0x80U) {
- *data++ = char((value & 0x7fU) | 0x80U);
+ *data++ = static_cast<char>((value & 0x7fU) | 0x80U);
value >>= 7U;
++n;
}
- *data = char(value);
+ *data = static_cast<char>(value);
return n;
}
* @tparam TBuffer A buffer type.
* @param buffer Output buffer the varint will be written to.
* @param value The integer that will be encoded.
- * @returns the number of bytes written
* @throws Any exception thrown by calling the buffer_push_back() function.
*/
template <typename TBuffer>
inline void add_varint_to_buffer(TBuffer* buffer, uint64_t value) {
while (value >= 0x80U) {
- buffer_customization<TBuffer>::push_back(buffer, char((value & 0x7fU) | 0x80U));
+ buffer_customization<TBuffer>::push_back(buffer, static_cast<char>((value & 0x7fU) | 0x80U));
value >>= 7U;
}
- buffer_customization<TBuffer>::push_back(buffer, char(value));
+ buffer_customization<TBuffer>::push_back(buffer, static_cast<char>(value));
}
/**
int n = 1;
while (value >= 0x80U) {
- *data++ = char((value & 0x7fU) | 0x80U);
+ *data++ = static_cast<char>((value & 0x7fU) | 0x80U);
value >>= 7U;
++n;
}
- *data = char(value);
+ *data = static_cast<char>(value);
return n;
}
/**
* ZigZag encodes a 32 bit integer.
*/
-inline constexpr uint32_t encode_zigzag32(int32_t value) noexcept {
+constexpr uint32_t encode_zigzag32(int32_t value) noexcept {
return (static_cast<uint32_t>(value) << 1U) ^ static_cast<uint32_t>(-static_cast<int32_t>(static_cast<uint32_t>(value) >> 31U));
}
/**
* ZigZag encodes a 64 bit integer.
*/
-inline constexpr uint64_t encode_zigzag64(int64_t value) noexcept {
+constexpr uint64_t encode_zigzag64(int64_t value) noexcept {
return (static_cast<uint64_t>(value) << 1U) ^ static_cast<uint64_t>(-static_cast<int64_t>(static_cast<uint64_t>(value) >> 63U));
}
/**
* Decodes a 32 bit ZigZag-encoded integer.
*/
-inline constexpr int32_t decode_zigzag32(uint32_t value) noexcept {
+constexpr int32_t decode_zigzag32(uint32_t value) noexcept {
return static_cast<int32_t>((value >> 1U) ^ static_cast<uint32_t>(-static_cast<int32_t>(value & 1U)));
}
/**
* Decodes a 64 bit ZigZag-encoded integer.
*/
-inline constexpr int64_t decode_zigzag64(uint64_t value) noexcept {
+constexpr int64_t decode_zigzag64(uint64_t value) noexcept {
return static_cast<int64_t>((value >> 1U) ^ static_cast<uint64_t>(-static_cast<int64_t>(value & 1U)));
}