factory

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package factory contains predefined messages based on messages in [Profile.xlsx] provided in the Official Fit SDK. This package handles message and field creation, as well as registering manufacturer specific messages to be used for certain manufacturer's generated Fit file. You can always generate your own custom SDK using cmd/fitgen, but for those who prefer using this SDK as it is, what this package provides might be sufficient.

Index

Constants

View Source
const (
	// NameUnknown is unknown message or field name
	NameUnknown string = "unknown"
)

Variables

View Source
var (
	// ErrRegisterForbidden occurs when trying to create manufacturer specific message outside available range.
	ErrRegisterForbidden = errors.New("register is forbidden")
)

Functions

func CreateField

func CreateField(mesgNum typedef.MesgNum, num byte) proto.Field

CreateField creates new field based on defined messages in the factory. If not found, it returns new field with "unknown" name.

Returned Field's FieldBase is a pointer, referencing a value in this factory to reduce unnecessary malloc or runtime duffcopy since the content should not be changed.

func CreateMesg

func CreateMesg(num typedef.MesgNum) proto.Message

CreateMesg creates new message based on defined messages in the factory. If not found, it returns new message with "unknown" name.

func CreateMesgOnly

func CreateMesgOnly(num typedef.MesgNum) proto.Message

CreateMesgOnly is similar to CreateMesg, but it sets Fields and DeveloperFields to nil. This is useful when we plan to fill these values ourselves to avoid unnecessary malloc when cloning them, as they will be removed anyway. For example, the decoding process will populate them with decoded data.

func RegisterMesg

func RegisterMesg(mesg proto.Message) error

RegisterMesg registers a new message that is not defined in the profile.xlsx. You can not edit or replace existing message in the factory, including the messages you have registered. If you intend to edit your own messages, create a new factory instance using New() and define the new message definitions on it.

By registering, any Fit file containing these messages can be recognized instead of returning "unknown" message.

Types

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory handles creation and registration for Fit's message and field.

func New

func New() *Factory

New creates new Factory with predefined messages. Use this if you work with multiple manufacturers that have different manufacturer specific messages, Otherwise, use StandardFactory().

New is not receiving messages on purpose: to comply with Fit term and conditions which is not allowing edit on existing messages. Receiving messages through here means we need to validate all of it, while RegisterMesg is already exist for that purpose.

func StandardFactory

func StandardFactory() *Factory

StandardFactory returns standard factory.

func (*Factory) CreateField

func (f *Factory) CreateField(mesgNum typedef.MesgNum, num byte) proto.Field

CreateField creates new field based on defined messages in the factory. If not found, it returns new field with "unknown" name.

Returned Field's FieldBase is a pointer, referencing a value in this factory to reduce unnecessary malloc or runtime duffcopy since the content should not be changed.

func (*Factory) CreateMesg

func (f *Factory) CreateMesg(num typedef.MesgNum) proto.Message

CreateMesg creates new message based on defined messages in the factory. If not found, it returns new message with "unknown" name.

func (*Factory) CreateMesgOnly

func (f *Factory) CreateMesgOnly(num typedef.MesgNum) proto.Message

CreateMesgOnly is similar to CreateMesg, but it sets Fields and DeveloperFields to nil. This is useful when we plan to fill these values ourselves to avoid unnecessary malloc when cloning them, as they will be removed anyway. For example, the decoding process will populate them with decoded data.

func (*Factory) RegisterMesg

func (f *Factory) RegisterMesg(mesg proto.Message) error

RegisterMesg registers a new message that is not defined in the profile.xlsx. You can not edit or replace existing message in the factory, including the messages you have registered. If you intend to edit your own messages, create a new factory instance using New() and define the new message definitions on it.

By registering, any Fit file containing these messages can be recognized instead of returning "unknown" message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL