foxglove / omgidl

Monorepo offering packages for typescript support of OMG IDL schemas in Foxglove applications
MIT License
5 stars 4 forks source link

Fix edge cases of optional parameters #217

Closed snosenzo closed 1 month ago

snosenzo commented 1 month ago

Changelog

Docs

Description

Fixes two issues in our implementation of optional fields.

The first issue (FG-8644) was us not expecting optional parameters of final structs to have emHeaders in XCDR1. This is specified in the spec here:

image image

This was fixed by adding && field.isOptional.

The second issue (FG-8627) fixed occurred in PL_CDR2 when trying to read the absent, optional, final field of a message, which was causing a RangeError because emHeaders are not present for absent optional fields in PL_CDR2 since they are able to check id's of the emHeaders. This was fixed by catching the RangeError and returning undefined as we do when the emHeader is not the id we expect which is the other case when optional field is not present.

I also wrapped the readMemberFieldValue in a try/catch to be able to give better error messages at which field failed and where in the serialized message it encountered the error.