-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unknown: refactor handling of unknown fields and messages
Must now be enabled using DecodeOptions. Updates #6.
- Loading branch information
Showing
3 changed files
with
91 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package fit | ||
|
||
type unknownField struct { | ||
mesgNum MesgNum | ||
fieldNum byte | ||
} | ||
|
||
// UnknownField represents an unknown FIT message field for a known message | ||
// found in the official profile. It contains the message and field number, in | ||
// addition to how many times the field for a specific message was encountered | ||
// during decoding. | ||
type UnknownField struct { | ||
MesgNum MesgNum | ||
FieldNum byte | ||
Count int | ||
} | ||
|
||
type unknownFieldSlice []UnknownField | ||
|
||
func (p unknownFieldSlice) Len() int { return len(p) } | ||
func (p unknownFieldSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } | ||
func (p unknownFieldSlice) Less(i, j int) bool { | ||
if p[i].MesgNum < p[j].MesgNum { | ||
return true | ||
} else if p[i].MesgNum < p[j].MesgNum { | ||
return false | ||
} | ||
return p[i].FieldNum < p[j].FieldNum | ||
} | ||
|
||
// UnknownMessage represents an unknown FIT message not found in the official | ||
// profile. It contains the message number and how many times the was | ||
// encountered during decoding. | ||
type UnknownMessage struct { | ||
MesgNum MesgNum | ||
Count int | ||
} | ||
|
||
type unknownMessageSlice []UnknownMessage | ||
|
||
func (p unknownMessageSlice) Len() int { return len(p) } | ||
func (p unknownMessageSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } | ||
func (p unknownMessageSlice) Less(i, j int) bool { | ||
return p[i].MesgNum < p[j].MesgNum | ||
} |