No version for distro humble. Known supported distros are highlighted in the buttons above.
No version for distro galactic. Known supported distros are highlighted in the buttons above.
No version for distro foxy. Known supported distros are highlighted in the buttons above.

asyncapi_gencpp package from asyncapi_gencpp repo

asyncapi_gencpp

Package Summary

Tags No category tags.
Version 0.1.0
License BSD-3-Clause
Build type CMAKE
Use RECOMMENDED

Repository Summary

Checkout URI https://github.com/hatchbed/asyncapi_gencpp.git
VCS Type git
VCS Version main
Last Updated 2022-07-29
Dev Status DEVELOPED
CI status No Continuous Integration
Released UNRELEASED
Tags No category tags.
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Package Description

C++ code generator for serializing and deserializing Async API components and messages based on a specification file.

Additional Links

No additional links.

Maintainers

  • Marc Alban

Authors

  • Marc Alban

asyncapi_gencpp

C++ code generator for serializing and deserializing Async API components and messages based on a specification file.

The generator is implemented as as python3 script with the following usage:

usage: asyncapi_gencpp.py [-h] spec prefix outdir

positional arguments:
  spec        AsyncAPI specification file
  prefix      Include file prefix
  outdir      Output directory

The script will generate C++ data structures and code for parsing and writing the JSON objects described in the components and messages sections of the asyncapi spec file. Low level JSON parsing code is handled using the header only nlohmann json library.

The generated objects are returned as std::optional<> to deal with parsing failures, and so will be dependent on C++17.

The generator can also be used directly in cmake using a provided macro.

Example Usage:

asyncapi.yaml

components:
  schemas:
    pose:
      type: object
      properties:
        position:
          $ref: '#/components/schemas/vector3'
        orientation:
          type: object
          properties:
            - w:
              type: number
            - x:
              type: number
            - y:
              type: number
            - z:
              type: number
          required:
            - w
            - x
            - y
            - z
      required:
        - position
        - orientation
    vector3:
      type: object
      properties:
        x:
          type: number
        y:
          type: number
        z:
          type: number
      required:
        - x
        - y
        - z

CMakeLists.txt

project(example)
find_package(asyncapi_gencpp REQUIRED)

# asyncapi_gencpp macro provided via find_package(asyncapi_gencpp)
asyncapi_gencpp(${PROJECT_SOURCE_DIR}/api/asyncapi.yaml ${PROJECT_NAME}/msg ${CMAKE_CURRENT_BINARY_DIR}/include)

add_executable(main src/main.cpp)
add_dependencies(main ${PROJECT_NAME}_gencpp)


main.cpp

#include <iostream>
#include <example/msg/messages.h>  // This header includes all of the includes for the generated code, but individual
                                   // message headers can also be include as needed.

int main(int argc, char **argv) {

  // serialize to JSON
  example::msg::Pose pose;
  pose.position.x = 0.0;
  pose.position.y = 0.0;
  pose.position.z = 0.0;
  pose.orientation.w = 1.0;
  pose.orientation.x = 0.0;
  pose.orientation.y = 0.0;
  pose.orientation.z = 0.0;
  std::string json_string = pose.dump();

  // deserialize from JSON
  auto pose2 = example::msg::Pose::fromJson(json_string);
  if (pose2) {
    std::cout << "position: \n";
    std::cout << " x: " << pose2->position.x << "\n";
    std::cout << " y: " << pose2->position.y << "\n";
    std::cout << " z: " << pose2->position.z << "\n";
    std::cout << "orientation: \n";
    std::cout << " w: " << pose2->orientation.w << "\n";
    std::cout << " x: " << pose2->orientation.x << "\n";
    std::cout << " y: " << pose2->orientation.y << "\n";
    std::cout << " z: " << pose2->orientation.z << "\n";
  }

  return 0;
}


For a more complete example see the rpad library.

ROS Support

This library is agnostic to ROS, but is packaged to work in a ROS1 or ROS2 workspace.

CHANGELOG
No CHANGELOG found.

Wiki Tutorials

See ROS Wiki Tutorials for more details.

Source Tutorials

Not currently indexed.

Package Dependencies

No dependencies on ROS packages.

System Dependencies

Dependant Packages

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged asyncapi_gencpp at answers.ros.org

No version for distro noetic. Known supported distros are highlighted in the buttons above.
No version for distro melodic. Known supported distros are highlighted in the buttons above.
No version for distro ardent. Known supported distros are highlighted in the buttons above.
No version for distro bouncy. Known supported distros are highlighted in the buttons above.
No version for distro crystal. Known supported distros are highlighted in the buttons above.
No version for distro eloquent. Known supported distros are highlighted in the buttons above.
No version for distro dashing. Known supported distros are highlighted in the buttons above.
No version for distro lunar. Known supported distros are highlighted in the buttons above.
No version for distro jade. Known supported distros are highlighted in the buttons above.
No version for distro indigo. Known supported distros are highlighted in the buttons above.
No version for distro hydro. Known supported distros are highlighted in the buttons above.
No version for distro kinetic. Known supported distros are highlighted in the buttons above.