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

Method Receive

projects/Go/proto/fbe/Receiver.go:89–303  ·  view source on GitHub ↗

Receive bytes memory buffer

(buffer []byte)

Source from the content-addressed store, hash-verified

87
88// Receive bytes memory buffer
89func (r *Receiver) Receive(buffer []byte) error {
90 size := len(buffer)
91 if size <= 0 {
92 return nil
93 }
94
95 // Storage buffer
96 offset0 := r.buffer.offset
97 offset1 := r.buffer.size
98 size1 := r.buffer.size
99
100 // Receive buffer
101 offset2 := 0
102 size2 := size
103
104 // While receive buffer is available to handle...
105 for offset2 < size2 {
106 var messageBuffer []byte = nil
107 messageOffset := 0
108 messageSize := 0
109
110 // Try to receive message size
111 messageSizeCopied := false
112 messageSizeFound := false
113 for !messageSizeFound {
114 // Look into the storage buffer
115 if offset0 < size1 {
116 count := min(size1 - offset0, 4)
117 if count == 4 {
118 messageSizeCopied = true
119 messageSizeFound = true
120 messageSize = int(ReadUInt32(r.buffer.data, r.buffer.offset + offset0))
121 offset0 += 4
122 break
123 } else {
124 // Fill remaining data from the receive buffer
125 if offset2 < size2 {
126 count := min(size2 - offset2, 4 - count)
127
128 // Allocate and refresh the storage buffer
129 r.buffer.Allocate(count)
130 size1 += count
131
132 copy(r.buffer.data[offset1:offset1 + count], buffer[offset2:offset2 + count])
133
134 offset1 += count
135 offset2 += count
136 continue
137 } else {
138 break
139 }
140 }
141 }
142
143 // Look into the receive buffer
144 if offset2 < size2 {
145 count := min(size2 - offset2, 4)
146 if count == 4 {

Callers 3

ReceiveBufferMethod · 0.95
SendAndReceiveFunction · 0.45
SendAndReceiveFinalFunction · 0.45

Calls 6

minFunction · 0.85
ReadUInt32Function · 0.85
WriteUInt32Function · 0.85
OnReceiveMethod · 0.65
AllocateMethod · 0.45
ResetMethod · 0.45

Tested by 2

SendAndReceiveFunction · 0.36
SendAndReceiveFinalFunction · 0.36