8 #ifndef FACEBOOK_NETWORK_PACKAGED_SOCKET_H
9 #define FACEBOOK_NETWORK_PACKAGED_SOCKET_H
63 inline const void* data()
const;
75 inline const void* offsetData()
const;
81 inline void* offsetData();
87 inline size_t size()
const;
93 inline size_t remainingBytes()
const;
98 inline void resetOffset();
104 inline void moveOffset(
const size_t delta);
116 inline bool isValid()
const;
157 inline bool isValid()
const;
163 inline size_t size()
const;
171 static constexpr uint64_t oceanTag();
176 uint64_t tag_ = 0ull;
179 uint64_t version_ = 0ull;
182 uint64_t size_ = 0ull;
185 static_assert(
sizeof(
PackageHeader) ==
sizeof(uint64_t) * 3,
"Invalid header!");
198 static constexpr
MessageId invalidMessageId();
204 static constexpr
size_t packageManagmentHeaderSize();
210 static constexpr
size_t maximalPackagedMessageSize();
237 ocean_assert(size_ <= memory_.size());
239 return memory_.data<uint8_t>();
244 ocean_assert(size_ < memory_.size());
245 ocean_assert(offset_ < size_);
247 return memory_.constdata<uint8_t>() + offset_;
252 ocean_assert(size_ <= memory_.size());
253 ocean_assert(offset_ < size_);
255 return memory_.data<uint8_t>() + offset_;
270 ocean_assert(delta <= remainingBytes());
274 ocean_assert(offset_ <= size_);
279 ocean_assert(offset_ <= size_);
280 return size_ - offset_;
285 return bool(memory_);
297 return tag_ == oceanTag() && version_ == 0ull && size_ != 0ull;
302 return size_t(size_);
317 return sizeof(
MessageId) +
sizeof(
unsigned int) +
sizeof(
unsigned int) +
sizeof(
unsigned int) +
sizeof(
unsigned int);
322 return 1024 * 1024 * 1024;
static constexpr unsigned long long string2tag(const char tagString[8])
Converts a string with exactly eight characters to a unique tag value.
Definition: Bitstream.h:409
This class implements an object able to allocate memory.
Definition: base/Memory.h:22
size_t size() const
Returns the size of the memory in bytes.
Definition: base/Memory.h:386
const void * constdata() const
Returns the pointer to the read-only memory which is allocated by this object.
Definition: base/Memory.h:298
This class implements a memory block.
Definition: PackagedSocket.h:38
MemoryBlock(const size_t size)
Creates a new memory block.
void resetOffset()
Resets the memory offset location back to the start.
Definition: PackagedSocket.h:263
size_t size() const
Returns the overall number of bytes in the memory block.
Definition: PackagedSocket.h:258
MemoryBlock(const void *data, const size_t size)
Creates a new memory block and copied memory from source data.
Memory memory_
The actual memory, can be larger than 'size_'.
Definition: PackagedSocket.h:121
void moveOffset(const size_t delta)
Moves the offset within the memory block.
Definition: PackagedSocket.h:268
const void * offsetData() const
Returns the pointer to the offset location within the memory block.
Definition: PackagedSocket.h:242
MemoryBlock()=default
Default constructor creating an empty memory block.
void resize(const size_t size)
Resizes the memory block.
bool isValid() const
Returns whether this memory block holds memory.
Definition: PackagedSocket.h:283
size_t size_
The actual size of the usable memory, in bytes.
Definition: PackagedSocket.h:124
const void * data() const
Returns the pointer to the start of the memory block.
Definition: PackagedSocket.h:228
size_t remainingBytes() const
Returns the number of remaining bytes.
Definition: PackagedSocket.h:277
This class is the base class for all packaged sockets.
Definition: PackagedSocket.h:31
static bool extractNextPackage(MemoryBlockQueue &sourceQueue, MemoryBlock &targetMemory)
Extracts a memory block from a queue with memory block.
PackagedSocket()
Creates a new packaged socket.
static constexpr size_t packageManagmentHeaderSize()
Returns the size of the package management header in bytes.
Definition: PackagedSocket.h:315
uint32_t MessageId
Definition of a message id.
Definition: PackagedSocket.h:185
static constexpr MessageId invalidMessageId()
Returns an invalid message id.
Definition: PackagedSocket.h:310
static constexpr size_t maximalPackagedMessageSize()
Returns the maximal size of a packaged message.
Definition: PackagedSocket.h:320
std::queue< MemoryBlock > MemoryBlockQueue
Definition of a queue holding memory blocks.
Definition: PackagedSocket.h:133
This class is the base class for all sockets.
Definition: Socket.h:31
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15