(a []byte)
| 52 | } |
| 53 | |
| 54 | func (b *LimitBuffer) Write(a []byte) (n int, err error) { |
| 55 | l := b.Len() |
| 56 | newL := l + len(a) |
| 57 | if c := b.Cap(); newL > c { |
| 58 | return 0, fmt.Errorf("LimitBuffer Write %d > %d", newL, c) |
| 59 | // panic(fmt.Sprintf("LimitBuffer Write %d > %d", newL, c)) |
| 60 | } else { |
| 61 | b.Buffer = b.Buffer.SubBuf(0, newL) |
| 62 | copy(b.Buffer[l:], a) |
| 63 | } |
| 64 | return len(a), nil |
| 65 | } |
| 66 | |
| 67 | // IBytes 用于区分传入的内存是否是复用内存,例如从网络中读取的数据,如果是复用内存,需要尽早复制 |
| 68 | type IBytes interface { |
no test coverage detected