本文整理汇总了Golang中github.com/bemasher/rtlamr/parse.LogMessage.StringNoOffset方法的典型用法代码示例。如果您正苦于以下问题:Golang LogMessage.StringNoOffset方法的具体用法?Golang LogMessage.StringNoOffset怎么用?Golang LogMessage.StringNoOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bemasher/rtlamr/parse.LogMessage
的用法示例。
在下文中一共展示了LogMessage.StringNoOffset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (rcvr *Receiver) Run() {
// Setup signal channel for interruption.
sigint := make(chan os.Signal, 1)
signal.Notify(sigint, os.Kill, os.Interrupt)
// Setup time limit channel
tLimit := make(<-chan time.Time, 1)
if *timeLimit != 0 {
tLimit = time.After(*timeLimit)
}
block := make([]byte, rcvr.p.Cfg().BlockSize2)
start := time.Now()
for {
// Exit on interrupt or time limit, otherwise receive.
select {
case <-sigint:
return
case <-tLimit:
fmt.Println("Time Limit Reached:", time.Since(start))
return
default:
// Read new sample block.
_, err := rcvr.Read(block)
if err != nil {
log.Fatal("Error reading samples: ", err)
}
pktFound := false
indices := rcvr.p.Dec().Decode(block)
for _, pkt := range rcvr.p.Parse(indices) {
if len(meterID) > 0 && !meterID[uint(pkt.MeterID())] {
continue
}
if len(meterType) > 0 && !meterType[uint(pkt.MeterType())] {
continue
}
var msg parse.LogMessage
msg.Time = time.Now()
msg.Offset, _ = sampleFile.Seek(0, os.SEEK_CUR)
msg.Length = rcvr.p.Cfg().BufferLength << 1
msg.Message = pkt
if encoder == nil {
// A nil encoder is just plain-text output.
if *sampleFilename == os.DevNull {
fmt.Fprintln(logFile, msg.StringNoOffset())
} else {
fmt.Fprintln(logFile, msg)
}
} else {
err = encoder.Encode(msg)
if err != nil {
log.Fatal("Error encoding message: ", err)
}
// The XML encoder doesn't write new lines after each
// element, add them.
if _, ok := encoder.(*xml.Encoder); ok {
fmt.Fprintln(logFile)
}
}
pktFound = true
if *single {
break
}
}
if pktFound {
if *sampleFilename != os.DevNull {
_, err = sampleFile.Write(rcvr.p.Dec().IQ)
if err != nil {
log.Fatal("Error writing raw samples to file:", err)
}
}
if *single {
return
}
}
}
}
}