本文整理匯總了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
}
}
}
}
}