# Copyright (c) 2023 Boston Dynamics, Inc. All rights reserved.
#
# Downloading, reproducing, distributing or otherwise using the SDK Software
# is subject to the terms and conditions of the Boston Dynamics Software
# Development Kit License (20191101-BDSDK-SL).
"""Common message processors."""
from bosdyn.api.header_pb2 import RequestHeader
from bosdyn.util import now_nsec, set_timestamp_from_nsec # bosdyn-core
[docs]class DataBufferLoggingProcessor:
"""Processor that logs every protobuf message to the robot's data buffer."""
def __init__(self, data_buffer_client):
"""
Args:
data_buffer_client: Instance of DataBufferClient.
"""
self.data_buffer_client = data_buffer_client
[docs] def mutate(self, proto, **kwargs):
"""Logs the protobuf message to the data buffer.
Args:
proto: The protobuf request or response to log.
"""
self.data_buffer_client.add_protobuf_async(proto)
[docs]def log_all_rpcs(client, data_buffer_client):
"""Attach a DataBufferLoggingProcessor to log all RPC requests and responses for the given client."""
processor = DataBufferLoggingProcessor(data_buffer_client)
client.request_processors.append(processor)
client.response_processors.append(processor)