Skip to content

Commit f04450c

Browse files
committed
CON-191: Finished docs
1 parent 12598cd commit f04450c

2 files changed

Lines changed: 55 additions & 18 deletions

File tree

docs/data.rst

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Similarly, to get a field in a :class:`Input` sample, use the appropriate
158158
getter: :meth:`SampleIterator.getNumber()`, :meth:`SampleIterator.getBoolean()`,
159159
:meth:`SampleIterator.getString()`, or the type-independent
160160
:meth:`SampleIterator.get()`.
161-
``getString`` also works with numeric fields, returning the number as a string:
161+
:meth:`SampleIterator.getString` also works with numeric fields, returning the number as a string:
162162

163163
.. code-block::
164164
@@ -179,10 +179,11 @@ getter: :meth:`SampleIterator.getNumber()`, :meth:`SampleIterator.getBoolean()`,
179179
180180
181181
.. note::
182-
The typed getters and setters perform better than ``set``
183-
and ``get`` in applications that write or read at high rates.
184-
Also prefer ``getJson`` and ``setFromJson`` over ``set``
185-
and ``get`` when accessing all or most of the fields of a sample
182+
The typed getters and setters perform better than :meth:`Instance.set`
183+
and :meth:`SampleIterator.get` in applications that write or read at high rates.
184+
Also, prefer :meth:`SampleIterator.getJson` and :meth:`Instance.setFromJson`
185+
over :meth:`Instance.set` and :meth:`SampleIterator.get` when accessing all
186+
or most of the fields of a sample
186187
(see previous section).
187188

188189
.. note::
@@ -193,26 +194,47 @@ getter: :meth:`SampleIterator.getNumber()`, :meth:`SampleIterator.getBoolean()`,
193194
Accessing 64-bit integers
194195
^^^^^^^^^^^^^^^^^^^^^^^^^
195196
Internally, *Connector* relies on a framework that only contains a single number
196-
type, which is an IEEE-754 floating-point number. Additionally, *Connector* does not use
197+
type, an IEEE-754 floating-point number. Additionally, *Connector* does not use
197198
JavaScript's BigInt representation for numbers, meaning JavaScript has this same limitation.
198-
As a result, not all 64-bit integers can be represented with exact precision.
199+
As a result, not all 64-bit integers can be represented with exact precision using all
200+
APIs.
199201
If your type contains uint64 or int64 members, and you expect them to be larger
200-
than ``2^53``, then you must take the following into account.
202+
than ``Number.MAX_SAFE_INTEGER`` (or smaller than ``Number.MIN_SAFE_INTEGER``),
203+
then you must take the following into account.
204+
205+
64-bit values with an absolute value greater or equal to 2^53 can be set via:
206+
- The type-agnostic setter, :meth:`Instance.set`. The values must be supplied
207+
as strings, e.g., ``the_output.instance.set('my_uint64', '18446744073709551615')``.
208+
- :meth:`Instance.setString`, e.g., ``the_output.instance.setString('my_uint64', '18446744073709551615')``.
209+
- :meth:`Instance.setFromJson`, if the values are provided as strings, e.g., ``the_output.instance.setFromJson({my_uint64: '18446744073709551615'})``.
210+
211+
64-bit values with an absolute value greater than 2^53 can be retrieved via:
212+
- The type-agnostic getter, :meth:`SampleIterator.get`. If the absolute value of
213+
the field is less than ``2^53`` it will be returned as a number; otherwise it will be
214+
returned as a string, e.g., ``sample.get(0).get('my_int64') // '9223372036854775807' OR 1234``.
215+
- Using :meth:`SampleIterator.getString`. The value will be returned as a string,
216+
e.g., ``sample.getString(my_int64') // '9223372036854775807' OR '1234'``.
201217

202-
64-bit values larger than 2^53 can be set via:
203-
- The type-agnostic setter (``instance.set()``), if they are supplied as strings, e.g., ``the_output.instance.set('my_uint64', '18446744073709551615')``.
204-
- The ``setString`` setter, e.g., ``the_output.instance.setString('my_uint64', '18446744073709551615')``.
205-
- Via a ``setFromJson``, if they are provided as strings, e.g., ``the_output.instance.setFromJson({my_uint64: '18446744073709551615'})``.
218+
.. warning::
219+
220+
If :meth:`SampleIterator.getNumber()` is used to retrieve a value > 2^53 it will
221+
throw a :class:`DDSError`.
222+
223+
.. warning::
206224

207-
64-bit values larger than 2^53 can be retrieved via:
208-
- The type-agnostic getter, ``getValue``. If the value is smaller than 2^53, it will be returned as a number; otherwise it will be returned as a string:
209-
e.g., ``sample.get(0).get('my_int64') // e.g., '9223372036854775807' OR 1234``.
210-
- The ``getString`` method.
211-
The value will be returned as a string, e.g., ``sample.getString(my_int64') // '9223372036854775807'``.
225+
If :meth:`Instance.setNumber()` is used to set a value >= 2^53 it will throw a
226+
:class:`DDSError`.
212227

213228
.. warning::
214229

215-
If getNumber or setNumber is used with a value larger than 2^53, that value will produce an ``Error``.
230+
The :meth:`SampleIterator.getJson()` method should not be used to retrieve integer
231+
values larger than ``Number.MAX_SAFE_INTEGER`` (or smaller than ``Number.MIN_SAFE_INTEGER``).
232+
The values returned may be corrupted **but no error will be thrown**.
233+
234+
.. note::
235+
236+
The :meth:`Instance.setNumber()` operation can safely handle ``abs(value) < 2^53``,
237+
whereas the :meth:`SampleIterator.getNumber()` operation can safely handle ``abs(value) <= 2^53``.
216238

217239
Accessing structs
218240
^^^^^^^^^^^^^^^^^

rticonnextdds-connector.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@ class SampleIterator {
500500
/**
501501
* Gets the value of a numeric field in this sample.
502502
*
503+
* .. note::
504+
* This operation should not be used with values with an aboslute value
505+
* larger than `Number.MAX_SAFE_INTEGER`. See :ref:`Accessing 64-bit integers`
506+
* for more information.
507+
*
503508
* @param {string} fieldName - The name of the field.
504509
* @returns {number} The numeric value of the field.
505510
*/
@@ -1283,6 +1288,11 @@ class Instance {
12831288
/**
12841289
* Sets a numeric field.
12851290
*
1291+
* .. note::
1292+
* This operation should not be used with values with an aboslute value
1293+
* larger than `Number.MAX_SAFE_INTEGER`. See :ref:`Accessing 64-bit integers`
1294+
* for more information.
1295+
*
12861296
* @param {string} fieldName - The name of the field.
12871297
* @param {number} value - A numeric value, or null, to unset an
12881298
* optional member.
@@ -1424,6 +1434,11 @@ class Instance {
14241434
/**
14251435
* Retrives the value of this instance as a JSON object.
14261436
*
1437+
* .. note::
1438+
* This operation should not be used with values with an aboslute value
1439+
* larger than `Number.MAX_SAFE_INTEGER`. See :ref:`Accessing 64-bit integers`
1440+
* for more information.
1441+
*
14271442
* @returns {JSON} The value of this instance as a JSON object.
14281443
*/
14291444
getJson () {

0 commit comments

Comments
 (0)