Skip to content

Commit

Permalink
fix: encoder only compress timestamp when value is valid (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
muktihari authored Sep 13, 2024
1 parent 00d9dd2 commit 62f3314
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions encoder/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/muktihari/fit/kit/hash"
"github.com/muktihari/fit/kit/hash/crc16"
"github.com/muktihari/fit/profile"
"github.com/muktihari/fit/profile/basetype"
"github.com/muktihari/fit/profile/typedef"
"github.com/muktihari/fit/profile/untyped/mesgnum"
"github.com/muktihari/fit/proto"
Expand Down Expand Up @@ -502,16 +503,11 @@ func (e *Encoder) encodeMessage(mesg *proto.Message) (err error) {
}

func (e *Encoder) compressTimestampIntoHeader(mesg *proto.Message) {
field := mesg.FieldByNum(proto.FieldNumTimestamp)
if field == nil {
return
}

if field.Value.Type() != proto.TypeUint32 {
timestamp := mesg.FieldValueByNum(proto.FieldNumTimestamp).Uint32()
if timestamp == basetype.Uint32Invalid {
return // not supported
}

timestamp := field.Value.Uint32()
if timestamp < uint32(typedef.DateTimeMin) {
return
}
Expand Down

0 comments on commit 62f3314

Please sign in to comment.