starnix_perfetto_trace_decoder/
lib.rs

1// Copyright 2025 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use perfetto_protos::perfetto::protos::ReadBuffersResponse;
6use perfetto_trace_protos::perfetto::protos::Trace;
7use prost::{DecodeError, Message};
8
9/// Decodes a Perfetto trace from a protobuf blob.
10///
11/// This function is intentionally isolated in its own crate to contain the
12/// build-time cost of monomorphizing the `Trace::decode` function.
13pub fn decode_trace(protobuf_blob: &[u8]) -> Result<Trace, DecodeError> {
14    Trace::decode(protobuf_blob)
15}
16
17/// Encodes a Perfetto trace into a protobuf blob.
18///
19/// This function is intentionally isolated in its own crate to contain the
20/// build-time cost of monomorphizing the `Trace::encode_to_vec` function.
21pub fn encode_trace(trace: &Trace) -> Vec<u8> {
22    trace.encode_to_vec()
23}
24
25/// Decodes a Perfetto read buffers response from a protobuf blob.
26///
27/// This function is intentionally isolated in its own crate to contain the
28/// build-time cost of monomorphizing the `ReadBuffersResponse::decode` function.
29pub fn decode_read_buffers_response(
30    protobuf_blob: &[u8],
31) -> Result<ReadBuffersResponse, DecodeError> {
32    ReadBuffersResponse::decode(protobuf_blob)
33}