OutMessage.AppendString

geesefs-0-30-9
Aaron Jacobs 2015-07-28 16:29:09 +10:00
parent bb88db68e0
commit a25c297e41
1 changed files with 10 additions and 2 deletions

View File

@ -103,8 +103,16 @@ func (b *OutMessage) Append(src []byte) {
// Equivalent to growing by the length of s, then copying s over the new
// segment. Panics if there is not enough room available.
func (b *OutMessage) AppendString(s string) {
panic("TODO")
func (b *OutMessage) AppendString(src string) {
p := b.GrowNoZero(uintptr(len(src)))
if p == nil {
panic(fmt.Sprintf("Can't grow %d bytes", len(src)))
}
sh := (*reflect.StringHeader)(unsafe.Pointer(&src))
memmove(p, unsafe.Pointer(sh.Data), uintptr(sh.Len))
return
}
// Return the current size of the buffer.