Flatten returns a flattened copy of this data. This method should not be used in any performance-sensitive paths. It may allocate a fresh byte slice sufficiently large to contain all the data in the buffer. This is principally for debugging. N.B. Tee data still belongs to this Buffer, as if there
()
| 385 | // present, then it will be returned directly. This should be used for |
| 386 | // temporary use only, and a reference to the given slice should not be held. |
| 387 | func (b *Buffer) Flatten() []byte { |
| 388 | if v := b.data.Front(); v == nil { |
| 389 | return nil // No data at all. |
| 390 | } |
| 391 | data := make([]byte, 0, b.size) // Need to flatten. |
| 392 | for v := b.data.Front(); v != nil; v = v.Next() { |
| 393 | // Copy to the allocated slice. |
| 394 | data = append(data, v.AsSlice()...) |
| 395 | } |
| 396 | return data |
| 397 | } |
| 398 | |
| 399 | // Size indicates the total amount of data available in this Buffer. |
| 400 | func (b *Buffer) Size() int64 { |