Commit 16fdd33
committed
Implement LengthLimitedRead for &[u8]
We want to slowly phase out the use of Cursor in the codebase, which means we
want to be able to call LengthLimitedRead::read(&mut &slice_of_bytes[..])
instead of wrapping the slice in a Cursor.
However, this breaks the current LengthLimitedRead::total_bytes method because
the underlying Read implementation for slice advances the slice as it is read,
so slice.len() can't be used to get the total bytes after any part of the struct
is read.
Therefore here we also switch the ::total_bytes method to ::remaining_bytes,
which seems like a more sensible method anyway since the reader is being
consumed.1 parent f5fc13b commit 16fdd33
File tree
4 files changed
+17
-8
lines changed- lightning/src
- crypto
- ln
- onion_message
- util
4 files changed
+17
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2324 | 2324 | | |
2325 | 2325 | | |
2326 | 2326 | | |
| 2327 | + | |
| 2328 | + | |
2327 | 2329 | | |
2328 | 2330 | | |
2329 | 2331 | | |
2330 | | - | |
2331 | 2332 | | |
2332 | 2333 | | |
2333 | 2334 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
93 | | - | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
231 | | - | |
232 | | - | |
| 231 | + | |
| 232 | + | |
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
351 | | - | |
352 | | - | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
353 | 361 | | |
354 | 362 | | |
355 | 363 | | |
| |||
0 commit comments