Skip to content

Commit

Permalink
write to existing buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Feb 7, 2025
1 parent 5def749 commit f299fcb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bitswap/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,12 @@ func write(w io.Writer, m *pb.Message) error {

n := binary.PutUvarint(buf, uint64(size))

b, err := proto.Marshal(m)
opts := proto.MarshalOptions{}
written, err := opts.MarshalAppend(buf[:n], m)
if err != nil {
return err
}
n += copy(buf[n:], b)
n += len(written)

_, err = w.Write(buf[:n])
return err
Expand Down

0 comments on commit f299fcb

Please sign in to comment.