make timestamp integer
This commit is contained in:
parent
61dbc7765c
commit
04308611ff
|
@ -82,7 +82,7 @@ func ToCanFrame(p Packet) (id uint32, data []byte, err error) {
|
||||||
|
|
||||||
// internal structure for partially decoding json object.
|
// internal structure for partially decoding json object.
|
||||||
type jsonRawEvent struct {
|
type jsonRawEvent struct {
|
||||||
Timestamp float64
|
Timestamp uint32
|
||||||
Id uint32
|
Id uint32
|
||||||
Name string
|
Name string
|
||||||
Data json.RawMessage
|
Data json.RawMessage
|
||||||
|
@ -90,10 +90,10 @@ type jsonRawEvent struct {
|
||||||
|
|
||||||
// BusEvent is a timestamped Skylab packet
|
// BusEvent is a timestamped Skylab packet
|
||||||
type BusEvent struct {
|
type BusEvent struct {
|
||||||
Timestamp float64 `json:"ts"`
|
Timestamp uint32 `json:"ts"`
|
||||||
Id uint64 `json:"id"`
|
Id uint32 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Data Packet `json:"data"`
|
Data Packet `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *BusEvent) MarshalJSON() (b []byte, err error) {
|
func (e *BusEvent) MarshalJSON() (b []byte, err error) {
|
||||||
|
@ -123,7 +123,7 @@ func (e *BusEvent) UnmarshalJSON(b []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Timestamp = jRaw.Timestamp
|
e.Timestamp = jRaw.Timestamp
|
||||||
e.Id = uint64(jRaw.Id)
|
e.Id = jRaw.Id
|
||||||
e.Data, err = FromJson(jRaw.Id, jRaw.Data)
|
e.Data, err = FromJson(jRaw.Id, jRaw.Data)
|
||||||
e.Name = e.Data.String()
|
e.Name = e.Data.String()
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ func (e *BusEvent) UnmarshalMsg(b []byte) ([]byte, error) {
|
||||||
return remain, err
|
return remain, err
|
||||||
}
|
}
|
||||||
e.Timestamp = rawEv.Timestamp
|
e.Timestamp = rawEv.Timestamp
|
||||||
e.Id = uint64(rawEv.Id)
|
e.Id = rawEv.Id
|
||||||
e.Data, err = FromCanFrame(rawEv.Id, rawEv.Data)
|
e.Data, err = FromCanFrame(rawEv.Id, rawEv.Data)
|
||||||
e.Name = e.Data.String()
|
e.Name = e.Data.String()
|
||||||
|
|
||||||
|
@ -164,7 +164,6 @@ func (e *BusEvent) UnmarshalMsg(b []byte) ([]byte, error) {
|
||||||
// we need to be able to parse the JSON as well. this is done using the
|
// we need to be able to parse the JSON as well. this is done using the
|
||||||
// generator since we can use the switch/case thing since it's the fastest
|
// generator since we can use the switch/case thing since it's the fastest
|
||||||
|
|
||||||
|
|
||||||
type UnknownIdError struct {
|
type UnknownIdError struct {
|
||||||
id uint64
|
id uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ package skylab
|
||||||
|
|
||||||
// internal structure for handling
|
// internal structure for handling
|
||||||
type msgpRawEvent struct {
|
type msgpRawEvent struct {
|
||||||
Timestamp float64 `msg:"ts"`
|
Timestamp uint32 `msg:"ts"`
|
||||||
Id uint32 `msg:"id"`
|
Id uint32 `msg:"id"`
|
||||||
Data []byte `msg:"data"`
|
Data []byte `msg:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal structure to represent a raw can packet over the network.
|
// internal structure to represent a raw can packet over the network.
|
||||||
|
|
|
@ -25,7 +25,7 @@ func (z *msgpRawEvent) DecodeMsg(dc *msgp.Reader) (err error) {
|
||||||
}
|
}
|
||||||
switch msgp.UnsafeString(field) {
|
switch msgp.UnsafeString(field) {
|
||||||
case "ts":
|
case "ts":
|
||||||
z.Timestamp, err = dc.ReadFloat64()
|
z.Timestamp, err = dc.ReadUint32()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = msgp.WrapError(err, "Timestamp")
|
err = msgp.WrapError(err, "Timestamp")
|
||||||
return
|
return
|
||||||
|
@ -61,7 +61,7 @@ func (z *msgpRawEvent) EncodeMsg(en *msgp.Writer) (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = en.WriteFloat64(z.Timestamp)
|
err = en.WriteUint32(z.Timestamp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = msgp.WrapError(err, "Timestamp")
|
err = msgp.WrapError(err, "Timestamp")
|
||||||
return
|
return
|
||||||
|
@ -95,7 +95,7 @@ func (z *msgpRawEvent) MarshalMsg(b []byte) (o []byte, err error) {
|
||||||
// map header, size 3
|
// map header, size 3
|
||||||
// string "ts"
|
// string "ts"
|
||||||
o = append(o, 0x83, 0xa2, 0x74, 0x73)
|
o = append(o, 0x83, 0xa2, 0x74, 0x73)
|
||||||
o = msgp.AppendFloat64(o, z.Timestamp)
|
o = msgp.AppendUint32(o, z.Timestamp)
|
||||||
// string "id"
|
// string "id"
|
||||||
o = append(o, 0xa2, 0x69, 0x64)
|
o = append(o, 0xa2, 0x69, 0x64)
|
||||||
o = msgp.AppendUint32(o, z.Id)
|
o = msgp.AppendUint32(o, z.Id)
|
||||||
|
@ -124,7 +124,7 @@ func (z *msgpRawEvent) UnmarshalMsg(bts []byte) (o []byte, err error) {
|
||||||
}
|
}
|
||||||
switch msgp.UnsafeString(field) {
|
switch msgp.UnsafeString(field) {
|
||||||
case "ts":
|
case "ts":
|
||||||
z.Timestamp, bts, err = msgp.ReadFloat64Bytes(bts)
|
z.Timestamp, bts, err = msgp.ReadUint32Bytes(bts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = msgp.WrapError(err, "Timestamp")
|
err = msgp.WrapError(err, "Timestamp")
|
||||||
return
|
return
|
||||||
|
@ -155,7 +155,7 @@ func (z *msgpRawEvent) UnmarshalMsg(bts []byte) (o []byte, err error) {
|
||||||
|
|
||||||
// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
|
// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
|
||||||
func (z *msgpRawEvent) Msgsize() (s int) {
|
func (z *msgpRawEvent) Msgsize() (s int) {
|
||||||
s = 1 + 3 + msgp.Float64Size + 3 + msgp.Uint32Size + 5 + msgp.BytesPrefixSize + len(z.Data)
|
s = 1 + 3 + msgp.Uint32Size + 3 + msgp.Uint32Size + 5 + msgp.BytesPrefixSize + len(z.Data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue