| 493 | } |
| 494 | |
| 495 | pub(crate) fn chunk_wire_envelopes(envelopes: Vec<pb::WireEnvelope>) -> Vec<Vec<pb::WireEnvelope>> { |
| 496 | let mut chunks: Vec<Vec<pb::WireEnvelope>> = Vec::new(); |
| 497 | let mut current: Vec<pb::WireEnvelope> = Vec::new(); |
| 498 | let mut current_cost = 0usize; |
| 499 | for envelope in envelopes { |
| 500 | let cost = wire_envelope_frame_cost(&envelope); |
| 501 | if !current.is_empty() && current_cost + cost > APPEND_CHUNK_BUDGET_BYTES { |
| 502 | chunks.push(std::mem::take(&mut current)); |
| 503 | current_cost = 0; |
| 504 | } |
| 505 | current_cost += cost; |
| 506 | current.push(envelope); |
| 507 | } |
| 508 | if !current.is_empty() { |
| 509 | chunks.push(current); |
| 510 | } |
| 511 | chunks |
| 512 | } |
| 513 | |
| 514 | // --------------------------------------------------------------------------- |
| 515 | // frozen page reassembly (ported verbatim from the legacy owner client) |