factory

package
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: BSD-3-Clause Imports: 8 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 (
	// ErrRegisterForbidden occurs when trying to create manufacturer specific message outside available range.
	ErrRegisterForbidden = errorString("register is forbidden")

	// NameUnknown is the name of an unknown message or an unknown field.
	NameUnknown string = "unknown"
)

Variables

This section is empty.

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.

The returned field contains a pointer reference to FieldBase defined in the factory, so changing any value declared in FieldBase is prohibited (except in the case of unknown field).

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 proto.Message{Num: num}.

This will create a shallow copy of the Fields, so changing any value declared in Field's FieldBase is prohibited (except in case of unknown field).

NOTE: This method is not used by either the Decoder or the Encoder, and the data will only be populated once upon the first invocation. Unless you need most of the returned fields, it's recommended create an empty proto.Message{Num: num} then fill only the necessary fields using CreateField method.

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 predefined messages in the factory, you can only edit the messages you have registered. Please note, we don't use mutex for efficiency, since this is intended to be used on instantiation.

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.

The returned field contains a pointer reference to FieldBase defined in the factory, so changing any value declared in FieldBase is prohibited (except in the case of unknown field).

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 proto.Message{Num: num}.

This will create a shallow copy of the Fields, so changing any value declared in Field's FieldBase is prohibited (except in case of unknown field).

NOTE: This method is not used by either the Decoder or the Encoder, and the data will only be populated once upon the first invocation. Unless you need most of the returned fields, it's recommended create an empty proto.Message{Num: num} then fill only the necessary fields using CreateField method.

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 predefined messages in the factory, you can only edit the messages you have registered. Please note, we don't use mutex for efficiency, since this is intended to be used on instantiation.

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