Skip to content

Commit

Permalink
perf: clean up proto and improve mesgdef (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
muktihari authored Dec 23, 2023
1 parent fda586c commit ec124c4
Show file tree
Hide file tree
Showing 106 changed files with 2,046 additions and 5,964 deletions.
23 changes: 9 additions & 14 deletions internal/cmd/fitgen/profile/mesgdef/mesgdef.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,30 @@ func New{{ .Name }}(mesg *proto.Message) *{{ .Name }} {

// ToMesg converts {{ .Name }} into proto.Message.
func (m *{{ .Name }}) ToMesg(fac Factory) proto.Message {
fieldsPtr := fieldsPool.Get().(*[256]proto.Field)
defer fieldsPool.Put(fieldsPtr)

fields := (*fieldsPtr)[:0] // Create slice from array with zero len.
mesg := fac.CreateMesgOnly(typedef.MesgNum{{ .Name }})
mesg.Fields = make([]proto.Field, 0, m.size())


{{ range .Fields -}}
if {{ .ComparableValue }} != {{ .InvalidValue }} {
field := fac.CreateField(mesg.Num, {{ .Num }})
field.Value = {{ .PrimitiveValue }}
mesg.Fields = append(mesg.Fields, field)
fields = append(fields, field)
}
{{ end }}

mesg.Fields = make([]proto.Field, len(fields))
copy(mesg.Fields, fields)

{{ if and (not (eq .Name "FileId")) (not (eq .Name "DeveloperDataId")) (not (eq .Name "FieldDescription")) }}
mesg.DeveloperFields = m.DeveloperFields
{{ end }}

return mesg
}

// size returns size of {{ .Name }}'s valid fields.
func (m *{{ .Name }}) size() byte {
var size byte
{{ range .Fields -}}
if {{ .ComparableValue }} != {{ .InvalidValue }} {
size++
}
{{ end -}}
return size
}

{{ range .Fields -}}
// Set{{ .Name }} sets {{ $.Name }} value.
//
Expand Down
74 changes: 19 additions & 55 deletions profile/mesgdef/accelerometer_data_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 15 additions & 39 deletions profile/mesgdef/activity_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 12 additions & 27 deletions profile/mesgdef/ant_channel_id_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ec124c4

Please sign in to comment.