MCPcopy Create free account
hub / github.com/chronoxor/FastBinaryEncoding / receive

Method receive

proto/fbe_protocol.cpp:27–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27void Receiver::receive(const void* data, size_t size)
28{
29 if (size == 0)
30 return;
31
32 assert((data != nullptr) && "Invalid buffer!");
33 if (data == nullptr)
34 return;
35
36 // Storage buffer
37 uint8_t* buffer1 = _buffer->data();
38 size_t offset0 = _buffer->offset();
39 size_t offset1 = _buffer->size();
40 size_t size1 = _buffer->size();
41
42 // Receive buffer
43 const uint8_t* buffer2 = (const uint8_t*)data;
44 size_t offset2 = 0;
45 size_t size2 = size;
46
47 // While receive buffer is available to handle...
48 while (offset2 < size2)
49 {
50 const uint8_t* message_buffer = nullptr;
51 size_t message_size = 0;
52
53 // Try to receive message size
54 bool message_size_copied = false;
55 bool message_size_found = false;
56 while (!message_size_found)
57 {
58 // Look into the storage buffer
59 if (offset0 < size1)
60 {
61 size_t count = std::min(size1 - offset0, (size_t)4);
62 if (count == 4)
63 {
64 message_size_copied = true;
65 message_size_found = true;
66 message_size = (size_t)(*((const uint32_t*)(buffer1 + offset0)));
67 offset0 += 4;
68 break;
69 }
70 else
71 {
72 // Fill remaining data from the receive buffer
73 if (offset2 < size2)
74 {
75 count = std::min(size2 - offset2, 4 - count);
76
77 // Allocate and refresh the storage buffer
78 _buffer->allocate(count);
79 buffer1 = _buffer->data();
80 size1 += count;
81
82 memcpy(buffer1 + offset1, buffer2 + offset2, count);
83 offset1 += count;
84 offset2 += count;

Callers 4

receiver.cppFile · 0.45
SendAndReceiveFunction · 0.45
SendAndReceiveFinalFunction · 0.45
mainFunction · 0.45

Calls 6

minFunction · 0.85
dataMethod · 0.45
offsetMethod · 0.45
sizeMethod · 0.45
allocateMethod · 0.45
resetMethod · 0.45

Tested by 2

SendAndReceiveFunction · 0.36
SendAndReceiveFinalFunction · 0.36