Skip to content

Commit

Permalink
make our own json dump available in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Jul 31, 2024
1 parent d22a9d6 commit bdaf864
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions third-party/realdds/py/pyrealdds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ PYBIND11_MODULE(NAME, m) {
py::arg( "nested-string" ) = "",
py::arg( "logger" ) = LIBREALSENSE_ELPP_ID );

m.def(
"json_dump", // pretty print, using our own output; also available in pyrsutils - here for convenience
[]( rsutils::json const & j, size_t indent )
{
std::ostringstream os;
if( indent )
os << std::setw( indent );
os << j;
return os.str();
},
py::arg( "json" ),
py::arg( "indent" ) = 4 );

using realdds::dds_guid;
py::class_< dds_guid >( m, "guid" )
.def( py::init<>() )
Expand Down
2 changes: 1 addition & 1 deletion third-party/realdds/scripts/topic-sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def on_flexible_available( reader ):
if not s:
s = json.dumps( j ) # without indent
else:
s = json.dumps( j, indent=4 )
s = dds.json_dump( j, indent=4 )
i( f'{timestamp()} {sample} {s}', )
got_something = True
for topic_path in args.flexible_be or []:
Expand Down
12 changes: 12 additions & 0 deletions third-party/rsutils/py/pyrsutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ PYBIND11_MODULE(NAME, m) {
{ return rsutils::string::shorten_json_string( j.dump(), max_length ).to_string(); },
py::arg( "json" ),
py::arg( "max-length" ) = 96 );
m.def(
"json_dump", // pretty print, using our own output
[]( rsutils::json const & j, size_t indent )
{
std::ostringstream os;
if( indent )
os << std::setw( indent );
os << j;
return os.str();
},
py::arg( "json" ),
py::arg( "indent" ) = 4 );
m.def( "executable_path", &rsutils::os::executable_path );
m.def( "executable_name", &rsutils::os::executable_name, py::arg( "with_extension" ) = false );

Expand Down

0 comments on commit bdaf864

Please sign in to comment.