allow writing primitives to static buffers

This commit is contained in:
aler9
2022-05-11 14:52:20 +02:00
parent ee6d7a87a3
commit c1b10a80be
19 changed files with 662 additions and 786 deletions

View File

@@ -35,11 +35,16 @@ func (b *body) read(header Header, rb *bufio.Reader) error {
return nil
}
func (b body) write(w io.Writer) error {
if len(b) == 0 {
return nil
}
_, err := w.Write(b)
return err
func (b body) writeSize() int {
return len(b)
}
func (b body) writeTo(buf []byte) int {
return copy(buf, b)
}
func (b body) write() []byte {
buf := make([]byte, b.writeSize())
b.writeTo(buf)
return buf
}