Permalink
Browse files

Fix encoder of messagepack to keep in pool

  • Loading branch information...
daichirata committed Dec 15, 2017
1 parent d0cdf96 commit 2620523219a24ad483ee54883cf1f60d86e6ef0e
Showing with 7 additions and 5 deletions.
  1. +1 −4 logger.go
  2. +6 −1 message.go
View
@@ -6,8 +6,6 @@ import (
"strings"
"sync"
"time"
"gopkg.in/vmihailenco/msgpack.v2"
)
var (
@@ -65,8 +63,7 @@ func (logger *Logger) PostWithTime(tag string, t time.Time, obj interface{}) err
}
m := getMessage()
enc := msgpack.NewEncoder(m.buf)
if err := enc.Encode(record); err != nil {
if err := m.enc.Encode(record); err != nil {
return err
}
logger.buf.Add(m)
View
@@ -3,10 +3,13 @@ package fluent
import (
"bytes"
"sync"
"gopkg.in/vmihailenco/msgpack.v2"
)
type Message struct {
buf *bytes.Buffer
enc *msgpack.Encoder
}
var messagePool = sync.Pool{
@@ -26,7 +29,9 @@ func putMessage(message *Message) {
}
func newMessage() *Message {
buf := bytes.NewBuffer([]byte{})
return &Message{
buf: bytes.NewBuffer([]byte{}),
buf: buf,
enc: msgpack.NewEncoder(buf),
}
}

0 comments on commit 2620523

Please sign in to comment.