# How to fill and read a nunavut::support::VariableLengthArray\<std::uint8\_t, 50\>

**URL:** <https://forum.opencyphal.org/t/how-to-fill-and-read-a-nunavut-variablelengtharray-std-uint8-t-50/1897>\
**Category:** Nunavut\
**Created:** [May 24, 2023, 11:58am UTC](https://forum.opencyphal.org/t/how-to-fill-and-read-a-nunavut-variablelengtharray-std-uint8-t-50/1897 "2023-05-24T11:58:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rebeccaRossRobotics](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/rebeccarossrobotics/32/1387_2.png) [@rebeccaRossRobotics](https://forum.opencyphal.org/u/rebeccaRossRobotics)\
**Post date:** [May 24, 2023, 11:58am UTC](https://forum.opencyphal.org/t/how-to-fill-and-read-a-nunavut-variablelengtharray-std-uint8-t-50/1897/1 "2023-05-24T11:58:18Z")

</div>

Hi there!

I’m currently attempting to use the .dsdl data types for the first time. I’m wondering if you could give me an example on how to fill and then read a `nunavut::support::VariableLengthArray<std::uint8_t, 50>`

More specifically. I am trying to fill the GetInfo name property. I had a look at the examples on 107-arduino-cyphal, and they show how to fill the parameter property of ExecuteCommand::Request\_1\_1. They show it like this:

```auto
 /* Request some coffee. */
  std::string const cmd_param("I want a double espresso with cream!");
  ExecuteCommand::Request_1_1 req;
  req.command = 0xCAFE;
  std::copy_n(cmd_param.begin(),
              std::min(cmd_param.length(), req.parameter.capacity()),
              req.parameter.begin());

```

I have assumed that this is the same process for the GetInfo name property as in the dsdl files they have the same definition of uint8[]

This is what I’ve tried so far, but yakut doesn’t read anything as the name of my node.  
 ![Wed 24 May 12:57:29 BST 2023](https://forum.opencyphal.org/uploads/default/optimized/2X/9/9f2de2d51b00fcae71ee9ae45b72b972514102dc_2_690x51.png)

```auto
  uavcan::node::GetInfo::Response_1_0 response;
  Serial.println("Get info requested");

  response.protocol_version.major = CANARD_CYPHAL_SPECIFICATION_VERSION_MAJOR;
  response.protocol_version.minor = CANARD_CYPHAL_SPECIFICATION_VERSION_MINOR;

  response.hardware_version.major = HW_VERSION_MAJOR;
  response.hardware_version.minor = HW_VERSION_MINOR;
  response.software_version.major = SW_VERSION_MAJOR;
  response.software_version.minor = SW_VERSION_MINOR;
  response.software_vcs_revision_id = VCS_REVISION_ID;

  response.unique_id = get_unique_id();
  std::string const name("rossrobotics.mk4.cantranslator.robot");
  std::copy_n(
    name.begin(),
    std::min(name.length(), response.name.capacity()),
    response.name.begin());

```

Nowhere does it say how to convert this back into a string when its been received by a node to be able to use/print to screen. How would I do that?

Thanks in advance  
Rebecca

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [May 24, 2023, 12:18pm UTC](https://forum.opencyphal.org/t/how-to-fill-and-read-a-nunavut-variablelengtharray-std-uint8-t-50/1897/2 "2023-05-24T12:18:19Z")

</div>

The first snippet looks correct to me and requires no changes, as far as I see.

The problem with Yakut has nothing to do with DSDL. It is simply unable to fetch the `uavcan.node.GetInfo` response for some unrelated reason. Maybe this service is not implemented by the node. To check, invoke the service manually and evaluate the response (`-v` is added for verbosity, add another one for extra verbosity which may aid in diagnosing the problem):

```sh
y -v q 42 uavcan.node.GetInfo

```

> [@rebeccaRossRobotics](#):
>
> Nowhere does it say how to convert this back into a string when its been received by a node to be able to use/print to screen. How would I do that?

Make a null-terminated char buffer and copy the bytes there. Note that soon we’re going to add proper string support to DSDL and Nunavut, see here for details: [Add support for strings and byte arrays by pavel-kirienko · Pull Request #97 · OpenCyphal/pydsdl · GitHub](https://github.com/OpenCyphal/pydsdl/pull/97).

---

<div class="post-metadata">

**Author:** ![rebeccaRossRobotics](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/rebeccarossrobotics/32/1387_2.png) [@rebeccaRossRobotics](https://forum.opencyphal.org/u/rebeccaRossRobotics)\
**Post date:** [May 24, 2023, 12:27pm UTC](https://forum.opencyphal.org/t/how-to-fill-and-read-a-nunavut-variablelengtharray-std-uint8-t-50/1897/3 "2023-05-24T12:27:26Z")

</div>

Thank Pavel for your quick response. I did `y -v q 35 uavcan.node.GetInfo` and this was its response

```plaintext
2023-05-24 12:23:05 0000039 INF yakut.cmd.call: Request object: uavcan.node.GetInfo.Request.1.0()
2023-05-24 12:23:05 0000039 INF yakut.param.transport: Transport constructed from registers: CANTransport(SocketCANMedia('can0', mtu=8), local_node_id=42)
2023-05-24 12:23:05 0000039 INF pycyphal.transport.can.media.socketcan._socketcan: SocketCANMedia('can0', mtu=8) FIXME: acceptance filter configuration is not yet implemented; please submit patches! Requested configuration: ext:xxx1x0xxxxxxxxx0101010xxxxxxx, ext:xxxxx0xxxxxxxxxxxxxxxx0101010, ext:xxx0x0xx11101010101010xxxxxxx
2023-05-24 12:23:05 0000039 INF yakut.cmd.call: Request duration [second]: transport layer: 0.000000, application layer: 0.008191, application layer overhead: 0.008191
430:
  protocol_version: {major: 1, minor: 0}
  hardware_version: {major: 0, minor: 1}
  software_version: {major: 0, minor: 1}
  software_vcs_revision_id: 0
  unique_id: [0, 0, 0, 0, 0, 0, 0, 0, 228, 97, 144, 55, 3, 18, 33, 35]
  name: ''
  software_image_crc: []
  certificate_of_authenticity: ''

```

I must that something wrong in my code so i’ll look into it.

Thanks I’ll implement copying the bytes there and check their example one works too.  
Oh that’s good to know about the string support thanks!

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [May 24, 2023, 12:38pm UTC](https://forum.opencyphal.org/t/how-to-fill-and-read-a-nunavut-variablelengtharray-std-uint8-t-50/1897/4 "2023-05-24T12:38:57Z")

</div>

Wait, I see an issue now in your first snippet. Either it’s incomplete or you’re missing the resize operation. Either do it manually or (much preferable) use [`std::back_inserter`](https://en.cppreference.com/w/cpp/iterator/back_inserter).

---

<div class="post-metadata">

**Author:** ![aentinger](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/aentinger/32/1428_2.png) [@aentinger](https://forum.opencyphal.org/u/aentinger)\
**Post date:** [May 24, 2023, 2:01pm UTC](https://forum.opencyphal.org/t/how-to-fill-and-read-a-nunavut-variablelengtharray-std-uint8-t-50/1897/5 "2023-05-24T14:01:58Z")

</div>

A PR with a fix would be welcome.

Btw. The node info service is implemented for 107-Arduino-Cyphal, the library is fully standard compliant.

You can see how to correctly fill the VLA [here](https://github.com/107-systems/107-Arduino-Cyphal/blob/8fb338514f6b66c48ad36d1d9e1aafc049b0eecb/src/util/nodeinfo/NodeInfo.hpp#L55).

---

<div class="post-metadata">

**Author:** ![rebeccaRossRobotics](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/rebeccarossrobotics/32/1387_2.png) [@rebeccaRossRobotics](https://forum.opencyphal.org/u/rebeccaRossRobotics)\
**Post date:** [May 24, 2023, 2:10pm UTC](https://forum.opencyphal.org/t/how-to-fill-and-read-a-nunavut-variablelengtharray-std-uint8-t-50/1897/6 "2023-05-24T14:10:18Z")

</div>

Thanks so much is exactly what i was looking for! All working now 🙂

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [May 24, 2023, 2:11pm UTC](https://forum.opencyphal.org/t/how-to-fill-and-read-a-nunavut-variablelengtharray-std-uint8-t-50/1897/7 "2023-05-24T14:11:40Z")

</div>

If you could send a pull request to the repository fixing this deficiency, that would be nice.

---

<div class="post-metadata">

**Author:** ![rebeccaRossRobotics](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/rebeccarossrobotics/32/1387_2.png) [@rebeccaRossRobotics](https://forum.opencyphal.org/u/rebeccaRossRobotics)\
**Post date:** [May 24, 2023, 2:12pm UTC](https://forum.opencyphal.org/t/how-to-fill-and-read-a-nunavut-variablelengtharray-std-uint8-t-50/1897/8 "2023-05-24T14:12:38Z")

</div>

To fix the example code?  
Sure i can do that

---

<div class="post-metadata">

**Author:** ![rebeccaRossRobotics](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/rebeccarossrobotics/32/1387_2.png) [@rebeccaRossRobotics](https://forum.opencyphal.org/u/rebeccaRossRobotics)\
**Post date:** [May 25, 2023, 8:03am UTC](https://forum.opencyphal.org/t/how-to-fill-and-read-a-nunavut-variablelengtharray-std-uint8-t-50/1897/9 "2023-05-25T08:03:12Z")

</div>

PR has been made this morning 🙂

---

<div class="post-metadata">

**Author:** ![aentinger](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/aentinger/32/1428_2.png) [@aentinger](https://forum.opencyphal.org/u/aentinger)\
**Post date:** [May 25, 2023, 8:38am UTC](https://forum.opencyphal.org/t/how-to-fill-and-read-a-nunavut-variablelengtharray-std-uint8-t-50/1897/10 "2023-05-25T08:38:38Z")

</div>

And [merged](https://github.com/107-systems/107-Arduino-Cyphal/pull/231)! Thank you very much 🙇‍♂️
