本文整理匯總了Golang中github.com/mozilla-services/heka/client.StreamEncoder.EncodeMessageStream方法的典型用法代碼示例。如果您正苦於以下問題:Golang StreamEncoder.EncodeMessageStream方法的具體用法?Golang StreamEncoder.EncodeMessageStream怎麽用?Golang StreamEncoder.EncodeMessageStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mozilla-services/heka/client.StreamEncoder
的用法示例。
在下文中一共展示了StreamEncoder.EncodeMessageStream方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: makeVariableMessage
func makeVariableMessage(encoder client.StreamEncoder, items int,
rdm *randomDataMaker) [][]byte {
ma := make([][]byte, items)
hostname, _ := os.Hostname()
pid := int32(os.Getpid())
var cnt int
for x := 0; x < items; x++ {
msg := &message.Message{}
msg.SetUuid(uuid.NewRandom())
msg.SetTimestamp(time.Now().UnixNano())
msg.SetType("hekabench")
msg.SetLogger("flood")
msg.SetEnvVersion("0.2")
msg.SetPid(pid)
msg.SetHostname(hostname)
cnt = (rand.Int() % 3) * 1024
msg.SetPayload(makePayload(uint64(cnt), rdm))
cnt = rand.Int() % 5
for c := 0; c < cnt; c++ {
field, _ := message.NewField(fmt.Sprintf("string%d", c), fmt.Sprintf("value%d", c), "")
msg.AddField(field)
}
cnt = rand.Int() % 5
for c := 0; c < cnt; c++ {
b := byte(c)
field, _ := message.NewField(fmt.Sprintf("bytes%d", c), []byte{b, b, b, b, b, b, b, b}, "")
msg.AddField(field)
}
cnt = rand.Int() % 5
for c := 0; c < cnt; c++ {
field, _ := message.NewField(fmt.Sprintf("int%d", c), c, "")
msg.AddField(field)
}
cnt = rand.Int() % 5
for c := 0; c < cnt; c++ {
field, _ := message.NewField(fmt.Sprintf("double%d", c), float64(c), "")
msg.AddField(field)
}
cnt = rand.Int() % 5
for c := 0; c < cnt; c++ {
field, _ := message.NewField(fmt.Sprintf("bool%d", c), true, "")
msg.AddField(field)
}
cnt = (rand.Int() % 60) * 1024
buf := make([]byte, cnt)
field, _ := message.NewField("filler", buf, "")
msg.AddField(field)
var stream []byte
if err := encoder.EncodeMessageStream(msg, &stream); err != nil {
log.Println(err)
}
ma[x] = stream
}
return ma
}
示例2: makeFixedMessage
func makeFixedMessage(encoder client.StreamEncoder, size uint64,
rdm *randomDataMaker) [][]byte {
ma := make([][]byte, 1)
hostname, _ := os.Hostname()
pid := int32(os.Getpid())
msg := &message.Message{}
msg.SetType("hekabench")
msg.SetTimestamp(time.Now().UnixNano())
msg.SetUuid(uuid.NewRandom())
msg.SetSeverity(int32(6))
msg.SetEnvVersion("0.8")
msg.SetPid(pid)
msg.SetHostname(hostname)
msg.SetPayload(makePayload(size, rdm))
var stream []byte
if err := encoder.EncodeMessageStream(msg, &stream); err != nil {
client.LogError.Println(err)
}
ma[0] = stream
return ma
}