How to parse a message containing an array of strings?

Decoding an array from a fit file is normally quite simple. E.g. if you have 4 bytes of data and you know it must be decoded into an array of uint8's you know that there will be 4 elements in the array because an uint8 is stored in one byte.

This does however not work for an array of strings if the string length is not known. In the profile I see this happening in 3 messages:

- field_description.field_name

- field_description.units

- exercise_title.wkt_step_name

QUESTION: how can I distinguish the elements of these arrays?

  • The size in bytes of the string is in the field definitions for the message. Same place the "4 bytes" in your example above came from. The strings are C style strings and are separated by null terminators.


    If you do encounter an array of strings, in almost all cases you will want to use the first element as the field value. The other values are due to the device allocating a fixed amount of memory for the string and not zeroing out the memory. I can't think of a field in public FIT SDK that is an array of strings, so taking the first value is the way to go.

    Is this a for fun or learning project, or is there project where one of the existing SDKs does not work for?

  • Hi Ben, thanks for your answer. My question is for a learning project, I'm not aware that one of the SDKs doesn't work for this.