Prefer std::byte to std::uint8_t in persistency
The following discussion from !3268 (merged) should be addressed:
-
@chasse started a discussion: (+2 comments)
There is also
std::byte
which would probably be a safer choice if all this buffer is supposed to represent is a buffer of uninterpreted bytes.
- Show closed items
Blocks
Activity
-
Newest first Oldest first
-
Show all activity Show comments only Show history only
- Rosen Matev added Persistency label
added Persistency label
- Rosen Matev mentioned in issue #206 (closed)
mentioned in issue #206 (closed)
- Rosen Matev marked this issue as related to #206 (closed)
marked this issue as related to #206 (closed)
- Contributor
@graven What do you think about this?
Collapse replies - Developer
There are some places where
std::byte
is appropriate, but also some where it is not, eg. when loading the version ID, the returned value is not just a number of bits, but it satisfies an ordering, hence code like:auto packingVersion = buf.template load<uint8_t>();
should remain as is. On the other hand, in
ByteBuffer
, it does make sense to usestd::byte
. So this is not a matter of blindly search-and-replaceuint8_t
withstd::byte
... - Developer
... and if I look for the use of
uint8_t
, and veto those that get assigned to a version, basically what is left is:diff --git a/Event/EventPacker/include/Event/PackedDataBuffer.h b/Event/EventPacker/include/Event/PackedDataBuffer.h index f91f50dc10..a154b85a0d 100644 --- a/Event/EventPacker/include/Event/PackedDataBuffer.h +++ b/Event/EventPacker/include/Event/PackedDataBuffer.h @@ -67,7 +67,7 @@ namespace LHCb::Hlt::PackedData { */ class ByteBuffer { public: - using buffer_type = std::vector<uint8_t>; + using buffer_type = std::vector<std::byte>; /// Return the current position in the buffer. std::size_t pos() const { return m_pos; } @@ -143,11 +143,11 @@ namespace LHCb::Hlt::PackedData { m_pos += x.size(); } /// Take requested part of the buffer - LHCb::span<uint8_t const> subspan( size_t offset, size_t size = gsl::dynamic_extent ) const { + LHCb::span<std::byte const> subspan( size_t offset, size_t size = gsl::dynamic_extent ) const { return LHCb::span{m_buffer}.subspan( offset, size ); } /// Add sub span of a buffer to a new buffer - void assign( LHCb::span<uint8_t const> data ) { + void assign( LHCb::span<std::byte const> data ) { m_buffer.assign( data.begin(), data.end() ); m_pos = 0; } @@ -266,7 +266,7 @@ namespace LHCb::Hlt::PackedData { void clear() { m_buffer.clear(); } /// Return a reference to the internal buffer. - const std::vector<uint8_t>& buffer() const { return m_buffer.buffer(); } + const std::vector<std::byte>& buffer() const { return m_buffer.buffer(); } /// Compress the buffer bool compress( Compression compression, int level, ByteBuffer::buffer_type& output ) const { return m_buffer.compress( compression, level, output );
I'll try this out, and if it seems to be OK make a MR for it.
- Developer
also, there is some use of
long long
which should probably be replaced withstd::int64_t
...
- Gerhard Raven mentioned in merge request !3524 (merged)
mentioned in merge request !3524 (merged)
- Gerhard Raven assigned to @graven
assigned to @graven
- Rosen Matev closed with merge request !3524 (merged)
closed with merge request !3524 (merged)
- Rosen Matev mentioned in commit 51723ba3
mentioned in commit 51723ba3