本文整理汇总了Golang中github.com/bemasher/rtlamr/parse.LogMessage类的典型用法代码示例。如果您正苦于以下问题:Golang LogMessage类的具体用法?Golang LogMessage怎么用?Golang LogMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LogMessage类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
}
}
}
}
示例2: 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)
}
in, out := io.Pipe()
go func() {
tcpBlock := make([]byte, 16384)
for {
n, err := rcvr.Read(tcpBlock)
if err != nil {
return
}
out.Write(tcpBlock[:n])
}
}()
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 := io.ReadFull(in, 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 !rcvr.fc.Match(pkt) {
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
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 {
if len(meterID.UintMap) == 0 {
break
} else {
delete(meterID.UintMap, uint(pkt.MeterID()))
}
}
}
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 && len(meterID.UintMap) == 0 {
return
}
}
}
}
}