8#ifndef FACEBOOK_NETWORK_PACKAGED_SOCKET_H
9#define FACEBOOK_NETWORK_PACKAGED_SOCKET_H
67 inline const void* data()
const;
79 inline const void* offsetData()
const;
85 inline void* offsetData();
91 inline size_t size()
const;
97 inline size_t remainingBytes()
const;
102 inline void resetOffset();
108 inline void moveOffset(
const size_t delta);
120 inline bool isValid()
const;
180 inline bool isValid()
const;
186 inline size_t size()
const;
194 static constexpr uint64_t oceanTag();
199 uint64_t tag_ = 0ull;
202 uint64_t version_ = 0ull;
205 uint64_t size_ = 0ull;
208 static_assert(
sizeof(
PackageHeader) ==
sizeof(uint64_t) * 3,
"Invalid header!");
221 static constexpr MessageId invalidMessageId();
246 static constexpr size_t packageManagmentHeaderSize();
252 static constexpr size_t maximalPackagedMessageSize();
279 ocean_assert(size_ <= memory_.size());
281 return memory_.data<uint8_t>();
286 ocean_assert(size_ < memory_.size());
287 ocean_assert(offset_ < size_);
289 return memory_.constdata<uint8_t>() + offset_;
294 ocean_assert(size_ <= memory_.size());
295 ocean_assert(offset_ < size_);
297 return memory_.data<uint8_t>() + offset_;
312 ocean_assert(delta <= remainingBytes());
316 ocean_assert(offset_ <= size_);
321 ocean_assert(offset_ <= size_);
322 return size_ - offset_;
327 return bool(memory_);
339 return tag_ == oceanTag() && version_ == 0ull && size_ != 0ull;
359 return sizeof(
MessageId) +
sizeof(
unsigned int) +
sizeof(
unsigned int) +
sizeof(
unsigned int) +
sizeof(
unsigned int);
364 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:455
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:42
MemoryBlock(const size_t size)
Creates a new memory block.
void resetOffset()
Resets the memory offset location back to the start.
Definition PackagedSocket.h:305
size_t size() const
Returns the overall number of bytes in the memory block.
Definition PackagedSocket.h:300
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:125
void moveOffset(const size_t delta)
Moves the offset within the memory block.
Definition PackagedSocket.h:310
const void * offsetData() const
Returns the pointer to the offset location within the memory block.
Definition PackagedSocket.h:284
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:325
size_t size_
The actual size of the usable memory, in bytes.
Definition PackagedSocket.h:128
const void * data() const
Returns the pointer to the start of the memory block.
Definition PackagedSocket.h:270
size_t remainingBytes() const
Returns the number of remaining bytes.
Definition PackagedSocket.h:319
This class is the base class for all packaged sockets.
Definition PackagedSocket.h:35
static bool extractNextPackage(MemoryBlockQueue &sourceQueue, MemoryBlock &targetMemory)
Extracts a memory block from a queue with memory block.
PackagedSocket()
Creates a new packaged socket.
std::queue< MemoryBlock > MemoryBlockQueue
Definition of a queue holding memory blocks.
Definition PackagedSocket.h:137
static constexpr size_t packageManagmentHeaderSize()
Returns the size of the package management header in bytes.
Definition PackagedSocket.h:357
static constexpr MessageId invalidMessageId()
Returns an invalid message id.
Definition PackagedSocket.h:352
uint32_t MessageId
Definition of a message id.
Definition PackagedSocket.h:215
static constexpr size_t maximalPackagedMessageSize()
Returns the maximal size of a packaged message.
Definition PackagedSocket.h:362
This class is the base class for all sockets.
Definition Socket.h:31
The namespace covering the entire Ocean framework.
Definition Accessor.h:15