C/C++ API Reference
Loading...
Searching...
No Matches
decoder.h
1// Copyright 2025 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15#pragma once
16
17#include <optional>
18#include <string>
19#include <vector>
20
21#include "pw_result/result.h"
22#include "pw_stream/stream.h"
23#include "pw_tokenizer/detokenize.h"
24#include "pw_trace_tokenized/trace_tokenized.h"
25
26namespace pw::trace {
27
29
34 EventType type = EventType::PW_TRACE_EVENT_TYPE_INVALID;
35 // TODO: https://pwbug.dev/448489618 - The 'flag' field in the token is
36 // ostensibly a decimal integer string, but could actually be any arbitrary C
37 // expression that evaluates to an integer. Rather than try to parse it and
38 // risk failing, simply return it as a string for now.
39 std::string flags_str;
40 std::string module;
41 std::string group;
42 std::string label;
43 std::string data_fmt;
44 uint64_t timestamp_usec{};
45 std::optional<uint64_t> trace_id;
46 std::vector<std::byte> data;
47};
48
51 public:
60 TokenizedDecoder(tokenizer::Detokenizer& detokenizer, uint64_t ticks_per_sec)
61 : detokenizer_(detokenizer), ticks_per_sec_(ticks_per_sec) {}
62
65 void SetTimeOffset(uint64_t time_offset) { last_timestamp_us_ = time_offset; }
66
76
87
88 private:
89 tokenizer::Detokenizer& detokenizer_;
90 const uint64_t ticks_per_sec_;
91 uint64_t last_timestamp_us_ = 0;
92
93 uint64_t usec_per_tick() const { return 1'000'000 / ticks_per_sec_; }
94};
95
97
98} // namespace pw::trace
Definition: result.h:143
Definition: stream.h:326
Definition: detokenize.h:103
TokenizedDecoder can decode pw_trace_tokenized-encoded trace events.
Definition: decoder.h:50
Result< DecodedEvent > ReadSizePrefixed(stream::Reader &reader)
TokenizedDecoder(tokenizer::Detokenizer &detokenizer, uint64_t ticks_per_sec)
Definition: decoder.h:60
Result< DecodedEvent > Decode(ConstByteSpan data)
void SetTimeOffset(uint64_t time_offset)
Definition: decoder.h:65
Definition: decoder.h:33