Skip to content

Commit

Permalink
Switch IceInternal::Buffer underlying type to std::byte
Browse files Browse the repository at this point in the history
  • Loading branch information
externl committed Mar 13, 2024
1 parent 94ed832 commit 0053054
Show file tree
Hide file tree
Showing 98 changed files with 908 additions and 896 deletions.
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
8 changes: 6 additions & 2 deletions cpp/include/Ice/Incoming.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace IceInternal
Ice::OutputStream* startWriteParams();
void endWriteParams();
void writeEmptyParams();
void writeParamEncaps(const std::uint8_t*, std::int32_t, bool ok);
void writeParamEncaps(const std::byte*, std::int32_t, bool ok);
void setMarshaledResult(Ice::MarshaledResult&&);

void setFormat(Ice::FormatType format) { _format = format; }
Expand All @@ -49,6 +49,7 @@ namespace IceInternal

// Inlined for speed optimization.
void skipReadParams() { _current.encoding = _is->skipEncapsulation(); }

Ice::InputStream* startReadParams()
{
//
Expand All @@ -58,9 +59,12 @@ namespace IceInternal
_current.encoding = _is->startEncapsulation();
return _is;
}

void endReadParams() const { _is->endEncapsulation(); }

void readEmptyParams() { _current.encoding = _is->skipEmptyEncapsulation(); }
void readParamEncaps(const std::uint8_t*& v, std::int32_t& sz)

void readParamEncaps(const std::byte*& v, std::int32_t& sz)
{
_current.encoding = _is->readEncapsulation(v, sz);
}
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 @@ -109,10 +109,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;

/// \cond INTERNAL
bool _iceDispatch(IceInternal::Incoming&) final;
Expand Down Expand Up @@ -140,8 +138,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;

/// \cond INTERNAL
Expand Down Expand Up @@ -171,8 +169,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 @@ -203,8 +201,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;
/// \cond INTERNAL
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
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

0 comments on commit 0053054

Please sign in to comment.