proto

package
v0.16.4 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package proto defines the abstraction for FIT Protocol.

FIT Protocol is the core of a FIT file and it's the fundamental building block for decoding and encoding FIT files.

Index

Constants

View Source
const (
	MesgDefinitionMask         = 0b01000000 // Mask for determining if the message type is a message definition.
	MesgNormalHeaderMask       = 0b00000000 // Mask for determining if the message type is a normal message data .
	MesgCompressedHeaderMask   = 0b10000000 // Mask for determining if the message type is a compressed timestamp message data.
	LocalMesgNumMask           = 0b00001111 // Mask for mapping normal message data to the message definition.
	CompressedLocalMesgNumMask = 0b01100000 // Mask for mapping compressed timestamp message data to the message definition. Used with CompressedBitShift.
	CompressedTimeMask         = 0b00011111 // Mask for measuring time offset value from header. Compressed timestamp is using 5 least significant bits (lsb) of header
	DevDataMask                = 0b00100000 // Mask for determining if a message contains developer fields.

	CompressedBitShift = 5 // Used for right-shifting the 5 least significant bits (lsb) of compressed time.

	DefaultFileHeaderSize byte   = 14     // The preferred size is 14
	DataTypeFIT           string = ".FIT" // FIT is a constant string ".FIT"

	FieldNumTimestamp = 253 // Field Num for timestamp across all defined messages in the profile.
)
View Source
const (
	MajorVersionShift = 4
	MajorVersionMask  = 0x0F << MajorVersionShift
	MinorVersionMask  = 0x0F

	V1   Version = 1 << MajorVersionShift // V1 is Version 1.0
	V2   Version = 2 << MajorVersionShift // V2 is Version 2.0
	Vmax         = V2                     // Vmax is an alias for the current latest version.
)
View Source
const MaxBytesPerMessage = 1 + (255*255)*2

Header + ((max n Fields) * (n value)) + ((max n DeveloperFields) * (n value))

View Source
const MaxBytesPerMessageDefinition = 5 + 1 + (255 * 3) + 1 + (255 * 3)

Header + Reserved + Architecture + MesgNum (2 bytes) + n Fields + (Max n Fields * 3) + n DevFields + (Max n DevFields * 3).

Variables

View Source
var ErrProtocolVersionNotSupported = errors.New("protocol version not supported")
View Source
var ErrProtocolViolation = errors.New("protocol violation")
View Source
var (
	ErrTypeNotSupported = errors.New("type is not supported")
)

Functions

func CreateMessageDefinitionTo added in v0.8.4

func CreateMessageDefinitionTo(target *MessageDefinition, mesg *Message)

CreateMessageDefinitionTo create MessageDefinition base on given Message and put it at target object to avoid allocation. It will panic if either target or mesg is nil. And mesg must be validated first, for instance if field.Value's size is more than 255 bytes, overflow will occurs.

func LocalMesgNum

func LocalMesgNum(header byte) byte

LocalMesgNum extracts LocalMesgNum from message header.

func Sizeof added in v0.12.0

func Sizeof(val Value, baseType basetype.BaseType) int

Sizeof returns the size of val in bytes. For every string in Value, if the last index of the string is not '\x00', size += 1.

func Validate

func Validate(version byte) error

Validate checks whether given version is a valid version.

func VersionMajor

func VersionMajor(version byte) byte

VersionMajor returns major value of given version

func VersionMinor

func VersionMinor(version byte) byte

VersionMinor returns minor value of given version

Types

type Component

type Component struct {
	FieldNum   byte
	Accumulate bool
	Bits       byte // bit value max 32
	Scale      float64
	Offset     float64
}

Component is a way of compressing one or more fields into a bit field expressed in a single containing field. The component can be expanded as a main Field in a Message or to update the value of the destination main Field.

type DeveloperField

type DeveloperField struct {
	Num                byte
	DeveloperDataIndex byte
	Size               byte
	NativeMesgNum      typedef.MesgNum
	NativeFieldNum     byte
	BaseType           basetype.BaseType
	Name               string
	Units              string
	Value              Value
}

Developer Field is a way to add custom data fields to existing messages. Developer Data Fields can be added to any message at runtime by providing a self-describing field definition. Developer Data Fields are also used by the Connect IQ FIT Contributor library, allowing Connect IQ apps and data fields to include custom data in FIT Activity files during the recording of activities. [Added since protocol version 2.0]

NOTE: If Developer Field contains a valid NativeMesgNum and NativeFieldNum, the value should be treated as native value (scale, offset, etc shall apply).

func (DeveloperField) Clone

func (f DeveloperField) Clone() DeveloperField

Clone clones DeveloperField

type DeveloperFieldDefinition

type DeveloperFieldDefinition struct {
	Num                byte // Map to the `field_definition_number` of a `field_description` Message.
	Size               byte // Size (in bytes) of the specified FIT message’s field
	DeveloperDataIndex byte // Maps to the `developer_data_index“ of a `developer_data_id` Message
}

FieldDefinition is the definition of the upcoming developer field within the message's structure.

type FIT added in v0.12.0

type FIT struct {
	FileHeader FileHeader // File Header contains either 12 or 14 bytes
	Messages   []Message  // Messages.
	CRC        uint16     // Cyclic Redundancy Check 16-bit value to ensure the integrity of the messages.
}

FIT represents a structure for FIT Files.

func (*FIT) WithMessages added in v0.12.0

func (f *FIT) WithMessages(messages ...Message) *FIT

WithMessages set Messages and return the pointer to the FIT.

type Field

type Field struct {
	// PERF: Embedding the struct as a pointer to avoid runtime duffcopy when creating a field since FieldBase should not be altered.
	*FieldBase

	// Value holds any primitive-type single value (or slice value) in a form of proto.Value.
	// We use proto.Value instead of interface{} because interface{} is heap-allocated, whereas proto.Value is not.
	Value Value

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

Field represents the full representation of a field, as specified in the Global FIT Profile.

func (Field) Clone

func (f Field) Clone() Field

Clone clones Field

func (*Field) SubFieldSubtitution

func (f *Field) SubFieldSubtitution(mesgRef *Message) *SubField

SubFieldSubstitution returns any sub-field that can substitute the properties interpretation of the parent Field (Dynamic Field).

func (Field) WithValue

func (f Field) WithValue(v any) Field

WithValue returns a Field containing v value.

type FieldBase

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)
	Type       profile.ProfileType // Type is defined type that serves as an abstraction layer above base types (primitive-types), e.g. DateTime is a time representation in uint32.
	BaseType   basetype.BaseType   // BaseType is the base of the ProfileType. E.g. profile.DateTime -> basetype.Uint32.
	Array      bool                // Flag whether the value of this field is an array
	Accumulate bool                // Flag to indicate if the value of the field is accumulable.
	Scale      float64             // A scale or offset specified in the FIT profile for binary fields (sint/uint etc.) only. the binary quantity is divided by the scale factor and then the offset is subtracted. (default: 1)
	Offset     float64             // A scale or offset specified in the FIT profile for binary fields (sint/uint etc.) only. the binary quantity is divided by the scale factor and then the offset is subtracted. (default: 0)
	Units      string              // Units of the value, such as m (meter), m/s (meter per second), s (second), etc.
	Components []Component         // List of components
	SubFields  []SubField          // List of sub-fields
}

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.

type FieldDefinition

type FieldDefinition struct {
	Num      byte              // The field definition number
	Size     byte              // The size of the upcoming value
	BaseType basetype.BaseType // The type of the upcoming value to be represented
}

FieldDefinition is the definition of the upcoming field within the message's structure.

type FileHeader

type FileHeader struct {
	Size            byte   // Header size either 12 (legacy) or 14.
	ProtocolVersion byte   // The FIT Protocol version which is being used to encode the FIT file.
	ProfileVersion  uint16 // The FIT Profile Version (associated with data defined in Global FIT Profile).
	DataSize        uint32 // The size of the messages in bytes (this field will be automatically updated by the encoder)
	DataType        string // ".FIT" (a string constant)
	CRC             uint16 // Cyclic Redundancy Check 16-bit value to ensure the integrity if the header. (this field will be automatically updated by the encoder)
}

FileHeader is a FIT's FileHeader with either 12 bytes size without CRC or a 14 bytes size with CRC, while 14 bytes size is the preferred size.

func (FileHeader) MarshalAppend added in v0.15.0

func (h FileHeader) MarshalAppend(b []byte) ([]byte, error)

MarshalAppend appends the FIT format encoding of FileHeader to b, returning the result.

func (FileHeader) MarshalBinary

func (h FileHeader) MarshalBinary() ([]byte, error)

MarshalBinary returns the FIT format encoding of FileHeader and nil error.

type Message

type Message struct {
	Header          byte             // Message Header serves to distinguish whether the message is a Normal Data or a Compressed Timestamp Data. Unlike MessageDefinition, Message's Header should not contain Developer Data Flag.
	Num             typedef.MesgNum  // Global Message Number defined in Global FIT Profile, except number within range 0xFF00 - 0xFFFE are manufacturer specific number.
	Reserved        byte             // Currently undetermined; the default value is 0.
	Architecture    byte             // Architecture type / Endianness. Must be the same
	Fields          []Field          // List of Field
	DeveloperFields []DeveloperField // List of DeveloperField
}

Message is a FIT protocol message containing the data defined in the Message Definition

func (Message) Clone

func (m Message) Clone() Message

Clone clones Message.

func (*Message) FieldByNum

func (m *Message) FieldByNum(num byte) *Field

FieldByNum returns a pointer to the Field in a Message, if not found return nil.

func (*Message) FieldValueByNum added in v0.1.0

func (m *Message) FieldValueByNum(num byte) Value

FieldValueByNum returns the value of the Field in a Messsage, if not found return nil.

func (Message) MarshalAppend added in v0.15.0

func (m Message) MarshalAppend(b []byte) ([]byte, error)

MarshalAppend appends the FIT format encoding of Message to b, returning the result.

func (Message) MarshalBinary

func (m Message) MarshalBinary() ([]byte, error)

MarshalBinary returns the FIT format encoding of Message and any error encountered during marshal.

func (*Message) RemoveFieldByNum

func (m *Message) RemoveFieldByNum(num byte)

RemoveFieldByNum removes Field in a Message by num.

func (Message) WithDeveloperFields

func (m Message) WithDeveloperFields(developerFields ...DeveloperField) Message

WithFields puts the provided fields into the message's fields.

func (Message) WithFieldValues

func (m Message) WithFieldValues(fieldNumValues map[byte]any) Message

WithFieldValues assigns the values of the targeted fields with the given map, where map[byte]any represents the field numbers and their respective values. If the specified fieldNum does not have a corresponding target match in the fields, no value will be assigned.

func (Message) WithFields

func (m Message) WithFields(fields ...Field) Message

WithFields puts the provided fields into the message's fields.

type MessageDefinition

type MessageDefinition struct {
	Header                    byte                       // The message definition header with mask 0b01000000.
	Reserved                  byte                       // Currently undetermined; the default value is 0.
	Architecture              byte                       // The Byte Order to be used to decode the values of both this message definition and the upcoming message. (0: Little-Endian, 1: Big-Endian)
	MesgNum                   typedef.MesgNum            // Global Message Number defined by factory (retrieved from Profile.xslx). (endianness of this 2 Byte value is defined in the Architecture byte)
	FieldDefinitions          []FieldDefinition          // List of the field definition
	DeveloperFieldDefinitions []DeveloperFieldDefinition // List of the developer field definition (only if Developer Data Flag is set in Header)
}

MessageDefinition is the definition of the upcoming data messages.

func CreateMessageDefinition

func CreateMessageDefinition(mesg *Message) (mesgDef MessageDefinition)

CreateMessageDefinition creates new MessageDefinition base on given Message. It will panic if mesg is nil. And mesg must be validated first, for instance if field.Value's size is more than 255 bytes, overflow will occurs.

func (MessageDefinition) Clone

Clone clones MessageDefinition

func (MessageDefinition) MarshalAppend added in v0.15.0

func (m MessageDefinition) MarshalAppend(b []byte) ([]byte, error)

MarshalAppend appends the FIT format encoding of MessageDefinition to b, returning the result.

func (MessageDefinition) MarshalBinary

func (m MessageDefinition) MarshalBinary() ([]byte, error)

MarshalBinary returns the FIT format encoding of MessageDefinition and nil error.

type SubField

type SubField struct {
	Name       string
	Type       profile.ProfileType
	Scale      float64
	Offset     float64
	Units      string
	Maps       []SubFieldMap
	Components []Component
}

SubField is a dynamic interpretation of the main Field in a Message when the SubFieldMap mapping match. See SubFieldMap's docs.

func (SubField) Clone

func (s SubField) Clone() SubField

Clone clones SubField

type SubFieldMap

type SubFieldMap struct {
	RefFieldNum   byte
	RefFieldValue int64
}

SubFieldMap is the mapping between SubField and and the corresponding main Field in a Message. When any Field in a Message has Field.Num == RefFieldNum and Field.Value == RefFieldValue, then the SubField containing this mapping can be interpreted as the main Field's properties (name, scale, type etc.)

type Type added in v0.12.0

type Type byte

Type is Value's type

const (
	TypeInvalid Type = iota
	TypeBool
	TypeInt8
	TypeUint8
	TypeInt16
	TypeUint16
	TypeInt32
	TypeUint32
	TypeInt64
	TypeUint64
	TypeFloat32
	TypeFloat64
	TypeString
	TypeSliceBool
	TypeSliceInt8
	TypeSliceUint8
	TypeSliceInt16
	TypeSliceUint16
	TypeSliceInt32
	TypeSliceUint32
	TypeSliceInt64
	TypeSliceUint64
	TypeSliceFloat32
	TypeSliceFloat64
	TypeSliceString
)

func (Type) String added in v0.12.0

func (t Type) String() string

type Validator

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

Validator is protocol validator

func NewValidator

func NewValidator(version Version) *Validator

NewValidator creates protocol validator base on given version.

func (*Validator) ProtocolVersion added in v0.9.0

func (p *Validator) ProtocolVersion() Version

ProtocolVersion returns the protocol version that this validator validates.

func (*Validator) SetProtocolVersion added in v0.9.0

func (p *Validator) SetProtocolVersion(version Version)

SetProtocolVersion sets new protocol version to validate.

func (*Validator) ValidateMessageDefinition

func (p *Validator) ValidateMessageDefinition(mesgDef *MessageDefinition) error

ValidateMessageDefinition validates whether the message definition contains unsupported data for the targeted version.

type Value added in v0.12.0

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

Value is a zero alloc implementation value that hold any FIT protocol value (value of primitive-types or slice of primitive-types).

To compare two Values of not known type, compare the results of the Any method. Using == on two Values is disallowed.

func Any added in v0.12.0

func Any(v any) Value

Any converts any value into Value. If the given v is not a primitive-type value (or a slice of primitive-type) it will determine it using reflection, and if it's a non-primitive-type slice it will make 1 alloc.

  • If v is not supported such as int, uint, []int, []uint, []any, slice with zero len, etc. Value with TypeInvalid is returned.
  • If v is a primitive-type slice, this will take ownership of v, and the caller should not use v after this call.

func Bool added in v0.12.0

func Bool(v bool) Value

Bool converts bool as Value.

func Float32 added in v0.12.0

func Float32(v float32) Value

Float32 converts float32 as Value.

func Float64 added in v0.12.0

func Float64(v float64) Value

Float64 converts float64 as Value.

func Int16 added in v0.12.0

func Int16(v int16) Value

Int16 converts int16 as Value.

func Int32 added in v0.12.0

func Int32(v int32) Value

Int32 converts int32 as Value.

func Int64 added in v0.12.0

func Int64(v int64) Value

Int64 converts int64 as Value.

func Int8 added in v0.12.0

func Int8(v int8) Value

Int8 converts int8 as Value.

func SliceBool added in v0.12.0

func SliceBool[S []E, E ~bool](s S) Value

SliceBool converts []bool as Value. This takes ownership of s, and the caller should not use s after this call.

func SliceFloat32 added in v0.12.0

func SliceFloat32[S []E, E ~float32](s S) Value

SliceFloat32 converts []float32 as Value. This takes ownership of s, and the caller should not use s after this call.

func SliceFloat64 added in v0.12.0

func SliceFloat64[S []E, E ~float64](s S) Value

SliceFloat64 converts []float64 as Value. This takes ownership of s, and the caller should not use s after this call.

func SliceInt16 added in v0.12.0

func SliceInt16[S []E, E ~int16](s S) Value

SliceInt16 converts []int16 as Value. This takes ownership of s, and the caller should not use s after this call.

func SliceInt32 added in v0.12.0

func SliceInt32[S []E, E ~int32](s S) Value

SliceInt32 converts []int32 as Value. This takes ownership of s, and the caller should not use s after this call.

func SliceInt64 added in v0.12.0

func SliceInt64[S []E, E ~int64](s S) Value

SliceInt64 converts []int64 as Value. This takes ownership of s, and the caller should not use s after this call.

func SliceInt8 added in v0.12.0

func SliceInt8[S []E, E ~int8](s S) Value

SliceInt8 converts []int8 as Value. This takes ownership of s, and the caller should not use s after this call.

func SliceString added in v0.12.0

func SliceString[S []E, E ~string](s S) Value

SliceString converts []string as Value. This takes ownership of s, and the caller should not use s after this call.

func SliceUint16 added in v0.12.0

func SliceUint16[S []E, E ~uint16](s S) Value

SliceUint16 converts []uint16 as Value. This takes ownership of s, and the caller should not use s after this call.

func SliceUint32 added in v0.12.0

func SliceUint32[S []E, E ~uint32](s S) Value

SliceUint32 converts []uint32 as Value. This takes ownership of s, and the caller should not use s after this call.

func SliceUint64 added in v0.12.0

func SliceUint64[S []E, E ~uint64](s S) Value

SliceUint64 converts []uint64 as Value. This takes ownership of s, and the caller should not use s after this call.

func SliceUint8 added in v0.12.0

func SliceUint8[S []E, E ~uint8](s S) Value

SliceUint8 converts []uint8 as Value. This takes ownership of s, and the caller should not use s after this call.

func String added in v0.12.0

func String(v string) Value

String converts string as Value.

func Uint16 added in v0.12.0

func Uint16(v uint16) Value

Uint16 converts uint16 as Value.

func Uint32 added in v0.12.0

func Uint32(v uint32) Value

Uint32 converts uint32 as Value.

func Uint64 added in v0.12.0

func Uint64(v uint64) Value

Uint64 converts uint64 as Value.

func Uint8 added in v0.12.0

func Uint8(v uint8) Value

Uint8 converts uint8 as Value.

func UnmarshalValue added in v0.15.0

func UnmarshalValue(b []byte, arch byte, ref basetype.BaseType, isArray bool) (Value, error)

UnmarshalValue unmarshals b into a proto.Value. The caller should ensure that the len(b) matches its corresponding base type's size, otherwise it might panic.

func (Value) Align added in v0.13.1

func (v Value) Align(t basetype.BaseType) bool

func (Value) Any added in v0.12.0

func (v Value) Any() any

Any returns Value's underlying value. If the underlying value is a slice, the caller takes ownership of that slice value, so Value should no longer be used after this call, except the returned value is copied and the copied value is used instead.

func (Value) Bool added in v0.12.0

func (v Value) Bool() bool

Bool returns Value as bool, if it's not a valid bool value, it returns false.

func (Value) Float32 added in v0.12.0

func (v Value) Float32() float32

Float32 returns Value as float32, if it's not a valid float32 value, it returns basetype.Float32Invalid (0xFFFFFFFF) in float32 value.

func (Value) Float64 added in v0.12.0

func (v Value) Float64() float64

Float64 returns Value as float64, if it's not a valid float64 value, it returns basetype.Float64Invalid (0xFFFFFFFFFFFFFFFF) in float64 value.

func (Value) Int16 added in v0.12.0

func (v Value) Int16() int16

Int16 returns Value as int16, if it's not a valid int16 value, it returns basetype.Sint16Invalid (0x7FFF).

func (Value) Int32 added in v0.12.0

func (v Value) Int32() int32

Int32 returns Value as int32, if it's not a valid int32 value, it returns basetype.Sint32Invalid (0x7FFFFFFF).

func (Value) Int64 added in v0.12.0

func (v Value) Int64() int64

Int64 returns Value as int64, if it's not a valid int64 value, it returns basetype.Sint64Invalid (0x7FFFFFFFFFFFFFFF).

func (Value) Int8 added in v0.12.0

func (v Value) Int8() int8

Int8 returns Value as int8, if it's not a valid int8 value, it returns basetype.Sint8Invalid (0x7F).

func (Value) MarshalAppend added in v0.15.0

func (v Value) MarshalAppend(b []byte, arch byte) ([]byte, error)

MarshalAppend appends the FIT format encoding of Value to b. Returning the result. If arch is 0, marshal in Little-Endian, otherwise marshal in Big-Endian.

func (Value) SliceBool added in v0.12.0

func (v Value) SliceBool() []bool

SliceBool returns Value as []bool, if it's not a valid []bool value, it returns nil. The caller takes ownership of the returned value, so Value should no longer be used after this call, except the returned value is copied and the copied value is used instead.

func (Value) SliceFloat32 added in v0.12.0

func (v Value) SliceFloat32() []float32

SliceFloat32 returns Value as []float32, if it's not a valid []float32 value, it returns nil. The caller takes ownership of the returned value, so Value should no longer be used after this call, except the returned value is copied and the copied value is used instead.

func (Value) SliceFloat64 added in v0.12.0

func (v Value) SliceFloat64() []float64

SliceFloat64 returns Value as []float64, if it's not a valid []float64 value, it returns nil. The caller takes ownership of the returned value, so Value should no longer be used after this call, except the returned value is copied and the copied value is used instead.

func (Value) SliceInt16 added in v0.12.0

func (v Value) SliceInt16() []int16

SliceInt16 returns Value as []int16, if it's not a valid []int16 value, it returns nil. The caller takes ownership of the returned value, so Value should no longer be used after this call, except the returned value is copied and the copied value is used instead.

func (Value) SliceInt32 added in v0.12.0

func (v Value) SliceInt32() []int32

SliceInt32 returns Value as []int32, if it's not a valid []int32 value, it returns nil. The caller takes ownership of the returned value, so Value should no longer be used after this call, except the returned value is copied and the copied value is used instead.

func (Value) SliceInt64 added in v0.12.0

func (v Value) SliceInt64() []int64

SliceInt64 returns Value as []int64, if it's not a valid []int64 value, it returns nil. The caller takes ownership of the returned value, so Value should no longer be used after this call, except the returned value is copied and the copied value is used instead.

func (Value) SliceInt8 added in v0.12.0

func (v Value) SliceInt8() []int8

SliceInt8 returns Value as []int8, if it's not a valid []int8 value, it returns nil. The caller takes ownership of the returned value, so Value should no longer be used after this call, except the returned value is copied and the copied value is used instead.

func (Value) SliceString added in v0.12.0

func (v Value) SliceString() []string

SliceString returns Value as []string, if it's not a valid []string value, it returns nil. The caller takes ownership of the returned value, so Value should no longer be used after this call, except the returned value is copied and the copied value is used instead.

func (Value) SliceUint16 added in v0.12.0

func (v Value) SliceUint16() []uint16

SliceUint16 returns Value as []uint16, if it's not a valid []uint16 value, it returns nil. The caller takes ownership of the returned value, so Value should no longer be used after this call, except the returned value is copied and the copied value is used instead.

func (Value) SliceUint32 added in v0.12.0

func (v Value) SliceUint32() []uint32

SliceUint32 returns Value as []uint32, if it's not a valid []uint32 value, it returns nil. The caller takes ownership of the returned value, so Value should no longer be used after this call, except the returned value is copied and the copied value is used instead.

func (Value) SliceUint64 added in v0.12.0

func (v Value) SliceUint64() []uint64

SliceUint64 returns Value as []uint64, if it's not a valid []uint64 value, it returns nil. The caller takes ownership of the returned value, so Value should no longer be used after this call, except the returned value is copied and the copied value is used instead.

func (Value) SliceUint8 added in v0.12.0

func (v Value) SliceUint8() []uint8

SliceUint8 returns Value as []uint8, if it's not a valid []uint8 value, it returns nil. The caller takes ownership of the returned value, so Value should no longer be used after this call, except the returned value is copied and the copied value is used instead.

func (Value) String added in v0.12.0

func (v Value) String() string

String returns Value as string, if it's not a valid string value, it returns basetype.StringInvalid. This should not be treated as a Go's String method, use Any() if you want to print the underlying value.

func (Value) Type added in v0.12.0

func (v Value) Type() Type

Return the underlying type the Value holds.

func (Value) Uint16 added in v0.12.0

func (v Value) Uint16() uint16

Uint16 returns Value as uint16, if it's not a valid uint16 value, it returns basetype.Uint16Invalid (0xFFFF).

func (Value) Uint16z added in v0.12.0

func (v Value) Uint16z() uint16

Uint16z returns Value as uint16, if it's not a valid uint16 value, it returns basetype.Uint16zInvalid (0).

func (Value) Uint32 added in v0.12.0

func (v Value) Uint32() uint32

Uint32 returns Value as uint32, if it's not a valid uint32 value, it returns basetype.Uint32Invalid (0xFFFFFFFF).

func (Value) Uint32z added in v0.12.0

func (v Value) Uint32z() uint32

Uint32z returns Value as uint32, if it's not a valid uint32 value, it returns basetype.Uint32zInvalid (0).

func (Value) Uint64 added in v0.12.0

func (v Value) Uint64() uint64

Uint64 returns Value as uint64, if it's not a valid uint64 value, it returns basetype.Uint64Invalid (0xFFFFFFFFFFFFFFFF).

func (Value) Uint64z added in v0.12.0

func (v Value) Uint64z() uint64

Uint64z returns Value as uint64, if it's not a valid uint64 value, it returns basetype.Uint64Invalid (0).

func (Value) Uint8 added in v0.12.0

func (v Value) Uint8() uint8

Uint8 returns Value as uint8, if it's not a valid uint8 value, it returns basetype.Uint8Invalid (0xFF).

func (Value) Uint8z added in v0.12.0

func (v Value) Uint8z() uint8

Uint8z returns Value as uint8, if it's not a valid uint8 value, it returns basetype.Uint8zInvalid (0).

func (Value) Valid added in v0.13.1

func (v Value) Valid(t basetype.BaseType) bool

Valid checks whether the Value is valid based on given basetype. This does not verify whether the Type of the Value aligns with the provided BaseType. For slices, even though only one element is valid, the Value will be counted a valid value.

Special case: bool or slice of bool will always be valid since bool type is often used as a flag and there are only two possibility (true/false).

type Version

type Version byte

Version is FIT Protocol Version

func CreateVersion

func CreateVersion(major, minor byte) (Version, bool)

CreateVersion creates version from major and minor value, it can only create version up < Vmax.

Jump to

Keyboard shortcuts

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