JavaScript SDK Encoder and Altitude/Enhanced Altitude (Maybe Bug)

Hey!

This is my second time trying to asking about this. My last post was "moderated" around a month ago, and I have been waiting, but no one seems to have approved it... and sadly the GitHub issues are disabled.

I have found a weird behavior with the JS SDK when encoding and then decoding (enhanced) altitude. In the following snippet, I encode and then decode the record message. The problem is that the altitude on the original message is not what gets saved when encoding.

import { Decoder, Encoder, Profile, Stream } from '@garmin/fitsdk'

const recordMesg = {
  timestamp: new Date('2025-05-28T08:38:47.000Z'),
  heartRate: 125,
  speed: 1.1,
  distance: 1.8,
  altitude: 20,
}

const encoder = new Encoder()
encoder.onMesg(Profile.MesgNum.RECORD, recordMesg)

const stream = Stream.fromByteArray(encoder.close())

const decoder = new Decoder(stream)

const { messages, errors } = decoder.read()

console.log(messages, errors)

I have tried with applyScaleAndOffset off too, but it doesn't seem to be the issue. This feels like a bug, but I'm not sure.

Does anyone have an idea?

  • I ran your code and this is what is logged to the console, which is what is expected.  

    {"recordMesgs":[{"timestamp":"2025-05-28T08:38:47.000Z","heartRate":125,"speed":1.1,"distance":1.8,"altitude":20,"enhancedSpeed":1.1,"enhancedAltitude":20}]}

    Component expansion is copying the speed and altitude values into the enhanced fields. Encoders should write either speed or enhancedSpeed, and when decoding, you should only need to read from enhancedSpeed (replace speed with altitude, respiration, etc).