From ccd351b2c1f15e331d1e2d46bc11de0c4c050dab Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Fri, 30 Sep 2022 17:44:52 +0000 Subject: [PATCH] pw_rpc: Expose PacketMeta::payload Change-Id: Ideb24994cabdd3140187f1350f4a9ab8e1a15443 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/112712 Reviewed-by: Wyatt Hepler Commit-Queue: Taylor Cramer --- pw_rpc/public/pw_rpc/packet_meta.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pw_rpc/public/pw_rpc/packet_meta.h b/pw_rpc/public/pw_rpc/packet_meta.h index bf2a7b5433..206754f2fc 100644 --- a/pw_rpc/public/pw_rpc/packet_meta.h +++ b/pw_rpc/public/pw_rpc/packet_meta.h @@ -38,15 +38,20 @@ class PacketMeta { constexpr bool destination_is_server() const { return destination_ == internal::Packet::kServer; } + // Note: this `payload` is only valid so long as the original `data` buffer + // passed to `PacketMeta::FromBuffer` remains valid. + constexpr ConstByteSpan payload() const { return payload_; } private: constexpr explicit PacketMeta(const internal::Packet packet) : channel_id_(packet.channel_id()), service_id_(internal::WrapServiceId(packet.service_id())), - destination_(packet.destination()) {} + destination_(packet.destination()), + payload_(packet.payload()) {} uint32_t channel_id_; ServiceId service_id_; internal::Packet::Destination destination_; + ConstByteSpan payload_; }; } // namespace pw::rpc