Skip to content

Commit

Permalink
Apply gofmt to everything.
Browse files Browse the repository at this point in the history
  • Loading branch information
bemasher committed Jun 7, 2015
1 parent 04d73e4 commit 8f3cb52
Showing 1 changed file with 78 additions and 78 deletions.
156 changes: 78 additions & 78 deletions parse/parse.go
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
package parse

import (
"fmt"
"strconv"
"time"

"github.com/bemasher/rtlamr/decode"

"github.com/bemasher/rtlamr/csv"
)

const (
TimeFormat = "2006-01-02T15:04:05.000"
)

type Data struct {
Bits string
Bytes []byte
}

func NewDataFromBytes(data []byte) (d Data) {
d.Bytes = data
for _, b := range data {
d.Bits += fmt.Sprintf("%08b", b)
}

return
}

func NewDataFromBits(data string) (d Data) {
d.Bits = data
d.Bytes = make([]byte, (len(data)+7)>>3)
for idx := 0; idx < len(data); idx += 8 {
b, _ := strconv.ParseUint(d.Bits[idx:idx+8], 2, 8)
d.Bytes[idx>>3] = uint8(b)
}
return
}

type Parser interface {
Parse([]int) []Message
Dec() decode.Decoder
Cfg() decode.PacketConfig
Log()
}

type Message interface {
csv.Recorder
MsgType() string
MeterID() uint32
MeterType() uint8
}

type LogMessage struct {
Time time.Time
Offset int64
Length int
Message
}

func (msg LogMessage) String() string {
return fmt.Sprintf("{Time:%s Offset:%d Length:%d %s:%s}",
msg.Time.Format(TimeFormat), msg.Offset, msg.Length, msg.MsgType(), msg.Message,
)
}

func (msg LogMessage) StringNoOffset() string {
return fmt.Sprintf("{Time:%s %s:%s}", msg.Time.Format(TimeFormat), msg.MsgType(), msg.Message)
}

func (msg LogMessage) Record() (r []string) {
r = append(r, msg.Time.Format(time.RFC3339Nano))
r = append(r, strconv.FormatInt(msg.Offset, 10))
r = append(r, strconv.FormatInt(int64(msg.Length), 10))
r = append(r, msg.Message.Record()...)
return r
}
package parse

import (
"fmt"
"strconv"
"time"

"github.com/bemasher/rtlamr/decode"

"github.com/bemasher/rtlamr/csv"
)

const (
TimeFormat = "2006-01-02T15:04:05.000"
)

type Data struct {
Bits string
Bytes []byte
}

func NewDataFromBytes(data []byte) (d Data) {
d.Bytes = data
for _, b := range data {
d.Bits += fmt.Sprintf("%08b", b)
}

return
}

func NewDataFromBits(data string) (d Data) {
d.Bits = data
d.Bytes = make([]byte, (len(data)+7)>>3)
for idx := 0; idx < len(data); idx += 8 {
b, _ := strconv.ParseUint(d.Bits[idx:idx+8], 2, 8)
d.Bytes[idx>>3] = uint8(b)
}
return
}

type Parser interface {
Parse([]int) []Message
Dec() decode.Decoder
Cfg() decode.PacketConfig
Log()
}

type Message interface {
csv.Recorder
MsgType() string
MeterID() uint32
MeterType() uint8
}

type LogMessage struct {
Time time.Time
Offset int64
Length int
Message
}

func (msg LogMessage) String() string {
return fmt.Sprintf("{Time:%s Offset:%d Length:%d %s:%s}",
msg.Time.Format(TimeFormat), msg.Offset, msg.Length, msg.MsgType(), msg.Message,
)
}

func (msg LogMessage) StringNoOffset() string {
return fmt.Sprintf("{Time:%s %s:%s}", msg.Time.Format(TimeFormat), msg.MsgType(), msg.Message)
}

func (msg LogMessage) Record() (r []string) {
r = append(r, msg.Time.Format(time.RFC3339Nano))
r = append(r, strconv.FormatInt(msg.Offset, 10))
r = append(r, strconv.FormatInt(int64(msg.Length), 10))
r = append(r, msg.Message.Record()...)
return r
}

0 comments on commit 8f3cb52

Please sign in to comment.