Chunked splits the response into multiple responses, each containing at most maxPeerUpdatesPerMessage peer updates to stay under the DRPC 4 MiB transport limit.
()
| 9 | // at most maxPeerUpdatesPerMessage peer updates to stay under the DRPC |
| 10 | // 4 MiB transport limit. |
| 11 | func (r *CoordinateResponse) Chunked() []*CoordinateResponse { |
| 12 | updates := r.GetPeerUpdates() |
| 13 | if len(updates) <= maxPeerUpdatesPerMessage { |
| 14 | return []*CoordinateResponse{r} |
| 15 | } |
| 16 | var chunks []*CoordinateResponse |
| 17 | for i := 0; i < len(updates); i += maxPeerUpdatesPerMessage { |
| 18 | end := min(i+maxPeerUpdatesPerMessage, len(updates)) |
| 19 | chunks = append(chunks, &CoordinateResponse{PeerUpdates: updates[i:end]}) |
| 20 | } |
| 21 | return chunks |
| 22 | } |