Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make our own json dump available in Python #13218

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading