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

replace default json serializer to improve readability #13185

Merged
merged 4 commits into from
Jul 24, 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
8 changes: 4 additions & 4 deletions common/rs-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <librealsense2/rs.h>
#include <rsutils/os/special-folder.h>
#include <rsutils/json.h>
#include <rsutils/json-config.h>
#include <fstream>

using json = rsutils::json;
Expand Down Expand Up @@ -69,7 +70,7 @@ void config_file::save(const char* filename)
try
{
std::ofstream out(filename);
out << _j.dump( 2 );
out << std::setw( 2 ) << _j;
out.close();
}
catch (...)
Expand All @@ -89,9 +90,8 @@ config_file::config_file( std::string const & filename )
{
try
{
std::ifstream t(_filename);
if (!t.good()) return;
_j = json::parse( t );
if( auto j = rsutils::json_config::load_from_file( filename ) )
_j = std::move( j );
}
catch(...)
{
Expand Down
2 changes: 1 addition & 1 deletion src/dds/rs-dds-device-info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ std::string dds_device_info::get_address() const
void dds_device_info::to_stream( std::ostream & os ) const
{
os << "DDS device (" << _dev->participant()->print( _dev->guid() ) << " on domain "
<< _dev->participant()->get()->get_domain_id() << "):" << _dev->device_info().to_json().dump( 4 );
<< _dev->participant()->get()->get_domain_id() << "):" << std::setw( 4 ) << _dev->device_info().to_json();
}


Expand Down
2 changes: 1 addition & 1 deletion third-party/realdds/src/dds-device-broadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void dds_device_broadcaster::broadcast() const
try
{
topics::flexible_msg msg( _device_info.to_json() );
LOG_DEBUG( "[" << _device_info.debug_name() << "] broadcasting device-info " << _device_info.to_json().dump(4) );
LOG_DEBUG( "[" << _device_info.debug_name() << "] broadcasting device-info " << std::setw( 4 ) << _device_info.to_json() );
std::move( msg ).write_to( *_writer );

// If a broadcast callback is asked for, we wait for acks and call it on the first broadcast (and never again)
Expand Down
2 changes: 1 addition & 1 deletion third-party/realdds/src/dds-device-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void dds_device::impl::on_query_options( json const & j, dds_sample const & )
if( ! option_values.is_object() )
throw std::runtime_error( "missing option-values" );

//LOG_DEBUG( "[" << debug_name() << "] got query-options: " << option_values.dump(4) );
//LOG_DEBUG( "[" << debug_name() << "] got query-options: " << std::setw( 4 ) << option_values );
for( auto it = option_values.begin(); it != option_values.end(); ++it )
{
if( it->is_object() )
Expand Down
4 changes: 2 additions & 2 deletions third-party/realdds/src/dds-device-watcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ dds_device_watcher::dds_device_watcher( std::shared_ptr< dds_participant > const
// Old device coming back to life
device.writer_guid = guid;
LOG_DEBUG( "[" << device.alive->debug_name() << "] device (from "
<< _participant->print( guid ) << ") back to life: " << j.dump( 4 ) );
<< _participant->print( guid ) << ") back to life: " << std::setw( 4 ) << j );
topics::device_info device_info = topics::device_info::from_json( j );
static_cast< dds_discovery_sink * >( device.alive.get() )
->on_discovery_restored( device_info );
Expand All @@ -97,7 +97,7 @@ dds_device_watcher::dds_device_watcher( std::shared_ptr< dds_participant > const
}
}

LOG_DEBUG( "DDS device (from " << _participant->print( guid ) << ") detected: " << j.dump( 4 ) );
LOG_DEBUG( "DDS device (from " << _participant->print( guid ) << ") detected: " << std::setw( 4 ) << j );
topics::device_info device_info = topics::device_info::from_json( j );

// Add a new device record into our dds devices map
Expand Down
9 changes: 9 additions & 0 deletions third-party/rsutils/include/rsutils/json-fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
// Copyright(c) 2023 Intel Corporation. All Rights Reserved.
#pragma once

// Turn off normal JSON I/O (operator<<) serialization
// This disables a few things like json::parse, but we do it because of conflict between our operator<< and the built-in
// one by json. Otherwise (if we do not need custom stream serialization) it's not needed...
#define JSON_NO_IO

#include <nlohmann/json_fwd.hpp>


Expand Down Expand Up @@ -73,4 +78,8 @@ extern json const empty_json_string;
extern json const empty_json_object;


std::ostream & operator<<( std::ostream &, const json & );



} // namespace rsutils
Loading
Loading