Giter VIP home page Giter VIP logo

json_transport's Introduction

json_transport

Build Status

Providing schemaless transport over ROS pub/sub via JSON. This is useful when schema is enforced elsewhere, or the data is truly schemaless (i.e. parameters, diagnostics).

C++

The provided serializers allow publishing and subscribing json_transport::json_t datatypes, which are nlohmann::json under the hood.

The nlohmann/json.hpp library is bundled in, but can be dropped for an apt dependency in artful, or if the package is bloomed into the rosdistro.

#include "json_transport/json_transport.hpp"

json_transport::json_t sent = {
  {"this_is_json", true},
  {"pi", 3.141},
  {"list_of_plugins", {
    "every_kind",
    "of_plugin",
    "you_can_imagine"
  }},
};

ros::NodeHandle nh;
auto publisher = nh.advertise<json_transport::json_t>("json", 1, true);
publisher.publish(sent);

auto received = ros::topic::waitForMessage<json_transport::json_t>("json");

assert(*received == sent);

Nested json_msg/Json types can be packed/unpacked via helper methods:

MyCustomMessage message();
message.json_field = json_transport::pack(json_data)

assert(json_data == json_transport::unpack(message.json_field))

Python

The provided json_transport.PackedJson data type allows publishing and subscribing anything that can be serialized/deserialized natively via the stdlib json module.

import json_transport
import rospy

rospy.init_node('json_talker')
pub = rospy.Publisher('json', json_transport.PackedJson, queue_size=1, latch=True)
pub.publish(1)
pub.publish([1, 2, 3])
pub.publish({'a': 1, 'b': 2, 'c': 3})

msg = rospy.wait_for_message('json', json_transport.PackedJson)

assert msg.data == {'a': 1, 'b': 2, 'c': 3}

Nested json_msg/Json types can be packed/unpacked via helper methods:

msg = MyCustomMessage(
    json_field=json_transport.pack(serializable_data)
)

assert serializable_data == json_transport.unpack(msg.json_field)

json_transport's People

Contributors

aadityaravindran avatar ablakey avatar garyservin avatar locus-services avatar matthewbwhitaker avatar paulbovbel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

json_transport's Issues

i386 builds are failing to build on kinetic sizeof(json_transport::json_t) == 16

It looks like there's an assumption about the size of the data that doesn't hold on 32bit vs the 64. Though oddly it works for amd64, arm64, armhf(32) but not i386. See the downstream here: http://build.ros.org/view/Kbin_uX32/job/Ksrc_uX__json_transport__ubuntu_xenial__source/

From the latest build: http://build.ros.org/view/Kbin_uX32/job/Kbin_uX32__json_transport__ubuntu_xenial_i386__binary/326/console

[ 50%] Building CXX object CMakeFiles/test_listener_cpp.dir/test/test_listener.cpp.o
/usr/lib/ccache/i686-linux-gnu-g++   -DROSCONSOLE_BACKEND_LOG4CXX -DROS_PACKAGE_NAME=\"json_transport\" -I/tmp/binarydeb/ros-kinetic-json-transport-0.0.1/include -I/opt/ros/kinetic/include -I/opt/ros/kinetic/share/xmlrpcpp/cmake/../../../include/xmlrpcpp  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -DNDEBUG -Wdate-time -D_FORTIFY_SOURCE=2    -std=c++14 -Wall -Werror -o CMakeFiles/test_listener_cpp.dir/test/test_listener.cpp.o -c /tmp/binarydeb/ros-kinetic-json-transport-0.0.1/test/test_listener.cpp
In file included from /tmp/binarydeb/ros-kinetic-json-transport-0.0.1/test/test_listener.cpp:31:0:
/tmp/binarydeb/ros-kinetic-json-transport-0.0.1/include/json_transport/json_transport.hpp:45:1: error: static assertion failed: sizeof(json_transport::json_t) == 16
 ROS_STATIC_ASSERT(sizeof(json_transport::json_t) == 16);
 ^
CMakeFiles/test_listener_cpp.dir/build.make:65: recipe for target 'CMakeFiles/test_listener_cpp.dir/test/test_listener.cpp.o' failed
make[4]: Leaving directory '/tmp/binarydeb/ros-kinetic-json-transport-0.0.1/obj-i686-linux-gnu'
make[4]: *** [CMakeFiles/test_listener_cpp.dir/test/test_listener.cpp.o] Error 1
make[3]: *** [CMakeFiles/test_listener_cpp.dir/all] Error 2
make[2]: *** [all] Error 2
CMakeFiles/Makefile2:201: recipe for target 'CMakeFiles/test_listener_cpp.dir/all' failed

ROS2

Hello,

Is there ROS2 version?

AttributeError: module 'json_msgs.msg' has no attribute 'Json'

Env:
Ubuntu 20.04 ROS-noetic

Hello,
I run the example code and I got the error below.
any help is appreciate, thanks

publisher = rospy.Publisher(topicName,json_transport.PackedJson,queue_size=10)

class PackedJson(json_msg.Json):
AttributeError: module 'json_msgs.msg' has no attribute 'Json'

Provide an incremental update mechanism

We can leverage JSON merge patch to provide an incremental-update mechanism for a large dataset. Consider implementing several topics to transport base JSON, and a side channel for providing deltas/updates.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.