Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(proto): update documentation #7

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions proto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (m Message) Clone() Message {
}

// FieldBase acts as a fundamental representation of a field as defined in the Global Fit Profile.
// The value of this representation should not be altered,except in the case of an unknown field.
// The value of this representation should not be altered, except in the case of an unknown field.
type FieldBase struct {
Name string // Defined in the Global FIT profile for the specified FIT message, otherwise its a manufaturer specific name (defined by manufacturer).
Num byte // Defined in the Global FIT profile for the specified FIT message, otherwise its a manufaturer specific number (defined by manufacturer). (255 == invalid)
Expand All @@ -239,9 +239,22 @@ type FieldBase struct {

// Field represents the full representation of a field, as specified in the Global Fit Profile.
type Field struct {
*FieldBase // PERF: Embedding the struct as a pointer to avoid runtime duffcopy when creating a field since FieldBase should not be altered.
Value any // The decoded value, should always be any of these: any, []any, []byte. The underlying value of any will always a primitive-types: int8, uint16, etc.
IsExpandedField bool // A flag to detect whether this field is generated through component expansion.
// PERF: Embedding the struct as a pointer to avoid runtime duffcopy when creating a field since FieldBase should not be altered.
*FieldBase

// The decoded value, composed by decoder, will always in a form of a primitive-type (or a slice of primitive types):
// - int8, uint8, int16, uint16, int32, uint32, int64, uint64, float32, float64 and string.
// - []int8, []uint8, []int16, []uint16, []int32, []uint32, []int64, []uint64, []float32 and []float64.
// (there is no []string)
//
// When the field is manually composed, you may use type-defined value as long as it refer to any of primitive-types
// (e.g. typedef.FileActivity). However, please note that marshaling type-defined value requires reflection.
//
// NOTE: You can not use distinct types such as int and uint.
Value any

// A flag to detect whether this field is generated through component expansion.
IsExpandedField bool
}

// WithValue returns a Field containing v value.
Expand All @@ -254,7 +267,7 @@ func (f Field) WithValue(v any) Field {
func (f *Field) SubFieldSubtitution(mesgRef *Message) (*SubField, bool) {
for i := range f.SubFields {
subField := &f.SubFields[i]
for j := 0; j < len(subField.Maps); j++ {
for j := range subField.Maps {
smap := &subField.Maps[j]
fieldRef, ok := mesgRef.FieldByNum(smap.RefFieldNum)
if !ok {
Expand Down