Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch IceInternal::Buffer underlying type to std::byte #1928

Merged
merged 8 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/include/Ice/AsyncResponseHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace IceInternal
// else we ignore this call.
}

void sendResponse(bool ok, const std::pair<const uint8_t*, const uint8_t*>& encaps) noexcept
void sendResponse(bool ok, const std::pair<const std::byte*, const std::byte*>& encaps) noexcept
{
if (!_responseSent.test_and_set())
{
Expand Down
19 changes: 9 additions & 10 deletions cpp/include/Ice/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace IceInternal
{
public:
Buffer() : i(b.begin()) {}
Buffer(const std::uint8_t* beg, const std::uint8_t* end) : b(beg, end), i(b.begin()) {}
Buffer(const std::vector<std::uint8_t>& v) : b(v), i(b.begin()) {}
Buffer(const std::byte* beg, const std::byte* end) : b(beg, end), i(b.begin()) {}
Buffer(const std::vector<std::byte>& v) : b(v), i(b.begin()) {}
Buffer(Buffer& o, bool adopt) : b(o.b, adopt), i(b.begin()) {}

void swapBuffer(Buffer&);
Expand All @@ -25,14 +25,13 @@ namespace IceInternal
//
// Standard vector-like operations.
//

typedef std::uint8_t value_type;
typedef std::uint8_t* iterator;
typedef const std::uint8_t* const_iterator;
typedef std::uint8_t& reference;
typedef const std::uint8_t& const_reference;
typedef std::uint8_t* pointer;
typedef size_t size_type;
using value_type = std::byte;
using iterator = std::byte*;
using const_iterator = const std::byte*;
using reference = std::byte&;
using const_reference = const std::byte&;
using pointer = std::byte*;
using size_type = size_t;

Container();
Container(const_iterator, const_iterator);
Expand Down
34 changes: 16 additions & 18 deletions cpp/include/Ice/InputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace Ice
* You can supply a communicator later by calling initialize().
* @param bytes The encoded data.
*/
InputStream(const std::vector<std::uint8_t>& bytes);
InputStream(const std::vector<std::byte>& bytes);

/**
* Constructs a stream using the latest encoding version but without a communicator.
Expand All @@ -76,7 +76,7 @@ namespace Ice
* You can supply a communicator later by calling initialize().
* @param bytes The encoded data.
*/
InputStream(const std::pair<const std::uint8_t*, const std::uint8_t*>& bytes);
InputStream(const std::pair<const std::byte*, const std::byte*>& bytes);

/// \cond INTERNAL
InputStream(IceInternal::Buffer&, bool = false);
Expand All @@ -93,16 +93,14 @@ namespace Ice
* @param communicator The communicator to use for unmarshaling tasks.
* @param bytes The encoded data.
*/
InputStream(const CommunicatorPtr& communicator, const std::vector<std::uint8_t>& bytes);
InputStream(const CommunicatorPtr& communicator, const std::vector<std::byte>& bytes);

/**
* Constructs a stream using the communicator's default encoding version.
* @param communicator The communicator to use for unmarshaling tasks.
* @param bytes The encoded data.
*/
InputStream(
const CommunicatorPtr& communicator,
const std::pair<const std::uint8_t*, const std::uint8_t*>& bytes);
InputStream(const CommunicatorPtr& communicator, const std::pair<const std::byte*, const std::byte*>& bytes);

/// \cond INTERNAL
InputStream(const CommunicatorPtr& communicator, IceInternal::Buffer&, bool = false);
Expand All @@ -125,7 +123,7 @@ namespace Ice
* @param version The encoding version used to encode the data to be unmarshaled.
* @param bytes The encoded data.
*/
InputStream(const EncodingVersion& version, const std::vector<std::uint8_t>& bytes);
InputStream(const EncodingVersion& version, const std::vector<std::byte>& bytes);

/**
* Constructs a stream using the given encoding version but without a communicator.
Expand All @@ -135,7 +133,7 @@ namespace Ice
* @param version The encoding version used to encode the data to be unmarshaled.
* @param bytes The encoded data.
*/
InputStream(const EncodingVersion& version, const std::pair<const std::uint8_t*, const std::uint8_t*>& bytes);
InputStream(const EncodingVersion& version, const std::pair<const std::byte*, const std::byte*>& bytes);

/// \cond INTERNAL
InputStream(const EncodingVersion&, IceInternal::Buffer&, bool = false);
Expand All @@ -157,7 +155,7 @@ namespace Ice
InputStream(
const CommunicatorPtr& communicator,
const EncodingVersion& version,
const std::vector<std::uint8_t>& bytes);
const std::vector<std::byte>& bytes);

/**
* Constructs a stream using the given communicator and encoding version.
Expand All @@ -168,7 +166,7 @@ namespace Ice
InputStream(
const CommunicatorPtr& communicator,
const EncodingVersion& version,
const std::pair<const std::uint8_t*, const std::uint8_t*>& bytes);
const std::pair<const std::byte*, const std::byte*>& bytes);

/// \cond INTERNAL
InputStream(const CommunicatorPtr&, const EncodingVersion&, IceInternal::Buffer&, bool = false);
Expand Down Expand Up @@ -473,7 +471,7 @@ namespace Ice
* @param sz The number of bytes in the encapsulation.
* @return encoding The encapsulation's encoding version.
*/
EncodingVersion readEncapsulation(const std::uint8_t*& v, std::int32_t& sz)
EncodingVersion readEncapsulation(const std::byte*& v, std::int32_t& sz)
{
EncodingVersion encoding;
v = i;
Expand Down Expand Up @@ -601,7 +599,7 @@ namespace Ice
{
if (sz > 0)
{
v = reinterpret_cast<std::byte*>(i);
v = i;
if (static_cast<Container::size_type>(b.end() - i) < sz)
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
Expand All @@ -610,7 +608,7 @@ namespace Ice
}
else
{
v = reinterpret_cast<std::byte*>(i);
v = i;
}
}

Expand Down Expand Up @@ -747,7 +745,7 @@ namespace Ice
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
v = static_cast<std::byte>(*i++);
v = *i++;
}

/**
Expand All @@ -760,21 +758,21 @@ namespace Ice
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
v = *i++;
v = static_cast<std::uint8_t>(*i++);
}

/**
* Reads a sequence of bytes from the stream.
* @param v A vector to hold a copy of the bytes.
*/
void read(std::vector<std::uint8_t>& v);
void read(std::vector<std::byte>& v);

/**
* Reads a sequence of bytes from the stream.
* @param v A pair of pointers into the internal marshaling buffer representing the start and end of the
* sequence elements.
*/
void read(std::pair<const std::uint8_t*, const std::uint8_t*>& v);
void read(std::pair<const std::byte*, const std::byte*>& v);

/**
* Reads a bool from the stream.
Expand All @@ -786,7 +784,7 @@ namespace Ice
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
v = (0 != *i++);
v = (std::byte{0} != *i++);
}

/**
Expand Down
18 changes: 8 additions & 10 deletions cpp/include/Ice/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ namespace Ice
* @throws UserException A user exception can be raised directly and the
* run time will marshal it.
*/
virtual bool ice_invoke(
std::vector<std::uint8_t> inEncaps,
std::vector<std::uint8_t>& outEncaps,
const Current& current) = 0;
virtual bool
ice_invoke(std::vector<std::byte> inEncaps, std::vector<std::byte>& outEncaps, const Current& current) = 0;

void dispatch(IncomingRequest&, std::function<void(OutgoingResponse)>) final;
};
Expand All @@ -154,8 +152,8 @@ namespace Ice
* run time will marshal it.
*/
virtual bool ice_invoke(
std::pair<const std::uint8_t*, const std::uint8_t*> inEncaps,
std::vector<std::uint8_t>& outEncaps,
std::pair<const std::byte*, const std::byte*> inEncaps,
std::vector<std::byte>& outEncaps,
const Current& current) = 0;

void dispatch(IncomingRequest&, std::function<void(OutgoingResponse)>) final;
Expand Down Expand Up @@ -183,8 +181,8 @@ namespace Ice
* run time will marshal it.
*/
virtual void ice_invokeAsync(
std::vector<std::uint8_t> inEncaps,
std::function<void(bool, const std::vector<std::uint8_t>&)> response,
std::vector<std::byte> inEncaps,
std::function<void(bool, const std::vector<std::byte>&)> response,
std::function<void(std::exception_ptr)> error,
const Current& current) = 0;

Expand Down Expand Up @@ -213,8 +211,8 @@ namespace Ice
* run time will marshal it.
*/
virtual void ice_invokeAsync(
std::pair<const std::uint8_t*, const std::uint8_t*> inEncaps,
std::function<void(bool, const std::pair<const std::uint8_t*, const std::uint8_t*>&)> response,
std::pair<const std::byte*, const std::byte*> inEncaps,
std::function<void(bool, const std::pair<const std::byte*, const std::byte*>&)> response,
std::function<void(std::exception_ptr)> error,
const Current& current) = 0;

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/Ice/OutgoingAsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace IceInternal
}
void endWriteParams() { _os.endEncapsulation(); }
void writeEmptyParams() { _os.writeEmptyEncapsulation(_encoding); }
void writeParamEncaps(const ::std::uint8_t* encaps, std::int32_t size)
void writeParamEncaps(const ::std::byte* encaps, std::int32_t size)
{
if (size == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/Ice/OutgoingResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace Ice
*/
ICE_API OutgoingResponse makeOutgoingResponse(
bool ok,
const std::pair<const std::uint8_t*, const std::uint8_t*>& encapsulation,
const std::pair<const std::byte*, const std::byte*>& encapsulation,
const Current& current) noexcept;

/**
Expand Down
31 changes: 16 additions & 15 deletions cpp/include/Ice/OutputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace Ice
OutputStream(
const CommunicatorPtr& communicator,
const EncodingVersion& version,
const std::pair<const std::uint8_t*, const std::uint8_t*>& bytes);
const std::pair<const std::byte*, const std::byte*>& bytes);

~OutputStream()
{
Expand Down Expand Up @@ -247,7 +247,7 @@ namespace Ice
* @param v The start of the buffer.
* @param sz The number of bytes to copy.
*/
void writeEncapsulation(const std::uint8_t* v, std::int32_t sz)
void writeEncapsulation(const std::byte* v, std::int32_t sz)
{
if (sz < 6)
{
Expand Down Expand Up @@ -325,12 +325,12 @@ namespace Ice
assert(v >= 0);
if (v > 254)
{
*dest++ = std::uint8_t(255);
*dest++ = std::byte{255};
write(v, dest);
}
else
{
*dest = static_cast<std::uint8_t>(v);
*dest = static_cast<std::byte>(v);
}
}

Expand Down Expand Up @@ -360,12 +360,6 @@ namespace Ice
*/
void writeBlob(const std::vector<std::byte>& v);

/**
* Copies the specified blob of bytes to the stream without modification.
* @param v The bytes to be copied.
*/
void writeBlob(const std::vector<std::uint8_t>& v);

/**
* Copies the specified blob of bytes to the stream without modification.
* @param v The start of the buffer to be copied.
Expand Down Expand Up @@ -537,13 +531,20 @@ namespace Ice
* Writes a byte to the stream.
* @param v The byte to write.
*/
void write(std::byte v) { b.push_back(static_cast<std::uint8_t>(v)); }
void write(std::byte v) { b.push_back(v); }

/**
* Writes a byte to the stream.
* @param v The byte to write.
*/
void write(std::uint8_t v) { b.push_back(v); }
void write(std::uint8_t v) { b.push_back(std::byte{v}); }

/**
* Writes a byte sequence to the stream.
* @param start The beginning of the sequence.
* @param end The end of the sequence.
*/
void write(const std::byte* start, const std::byte* end);

/**
* Writes a byte sequence to the stream.
Expand All @@ -556,7 +557,7 @@ namespace Ice
* Writes a boolean to the stream.
* @param v The boolean to write.
*/
void write(bool v) { b.push_back(static_cast<std::uint8_t>(v)); }
void write(bool v) { b.push_back(static_cast<std::byte>(v)); }

/**
* Writes a boolean sequence to the stream.
Expand Down Expand Up @@ -814,14 +815,14 @@ namespace Ice
* Indicates that marshaling is complete. This function must only be called once.
* @param v Filled with a copy of the encoded data.
*/
void finished(std::vector<std::uint8_t>& v);
void finished(std::vector<std::byte>& v);

/**
* Indicates that marshaling is complete. This function must only be called once.
* @return A pair of pointers into the internal marshaling buffer. These pointers are
* valid for the lifetime of the stream.
*/
std::pair<const std::uint8_t*, const std::uint8_t*> finished();
std::pair<const std::byte*, const std::byte*> finished();

/// \cond INTERNAL
OutputStream(IceInternal::Instance*, const EncodingVersion&);
Expand Down
Loading