CARLA
Loading...
Searching...
No Matches
CarlaRecorderEventAdd.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
8#include "CarlaRecorder.h"
10
11#include <algorithm>
12#include <limits>
13
14void CarlaRecorderEventAdd::Write(std::ostream &OutFile) const
15{
16 // database id
17 WriteValue<uint32_t>(OutFile, this->DatabaseId);
18 WriteValue<uint8_t>(OutFile, this->Type);
19
20 // transform
21 WriteFVector(OutFile, this->Location);
22 WriteFVector(OutFile, this->Rotation);
23
24 // description type
25 WriteValue<uint32_t>(OutFile, this->Description.UId);
26 WriteFString(OutFile, this->Description.Id);
27
28 // attributes
29 uint16_t Total = this->Description.Attributes.size();
30 WriteValue<uint16_t>(OutFile, Total);
31 for (uint16_t i=0; i<Total; ++i)
32 {
33 // type
34 WriteValue<uint8_t>(OutFile, this->Description.Attributes[i].Type);
35 WriteFString(OutFile, this->Description.Attributes[i].Id);
36 WriteFString(OutFile, this->Description.Attributes[i].Value);
37 }
38}
39
40void CarlaRecorderEventAdd::Read(std::istream &InFile)
41{
42 // database id
43 ReadValue<uint32_t>(InFile, this->DatabaseId);
44
45 // database type
46 ReadValue<uint8_t>(InFile, this->Type);
47
48 // transform
49 ReadFVector(InFile, this->Location);
50 ReadFVector(InFile, this->Rotation);
51
52 // description type
53 ReadValue<uint32_t>(InFile, this->Description.UId);
54 ReadFString(InFile, this->Description.Id);
55
56 // attributes
57 uint16_t Total = 0;
58 ReadValue<uint16_t>(InFile, Total);
59 this->Description.Attributes.clear();
60 for (uint16_t i=0; (i<Total) && InFile; ++i)
61 {
63 ReadValue<uint8_t>(InFile, Att.Type);
64 ReadFString(InFile, Att.Id);
65 ReadFString(InFile, Att.Value);
66 this->Description.Attributes.push_back(std::move(Att));
67 }
68}
69
70//---------------------------------------------
71
73{
74 Events.clear();
75}
76
78{
79 Events.push_back(std::move(Event));
80}
81
82void CarlaRecorderEventsAdd::Write(std::ostream &OutFile)
83{
84 // write the packet id
85 WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::EventAdd));
86
87 std::streampos PosStart = OutFile.tellp();
88
89 // write a dummy packet size
90 uint32_t Total = 0;
91 WriteValue<uint32_t>(OutFile, Total);
92
93 // write total records
94 Total = std::min<size_t>(Events.size(), std::numeric_limits<uint16_t>::max());
95 WriteValue<uint16_t>(OutFile, Total);
96
97 for (uint16_t i=0; i<Total; ++i)
98 Events[i].Write(OutFile);
99
100 // write the real packet size
101 std::streampos PosEnd = OutFile.tellp();
102 Total = PosEnd - PosStart - sizeof(uint32_t);
103 OutFile.seekp(PosStart, std::ios::beg);
104 WriteValue<uint32_t>(OutFile, Total);
105 OutFile.seekp(PosEnd, std::ios::beg);
106}
107
108void CarlaRecorderEventsAdd::Read(std::istream &InFile)
109{
111 uint16_t i, Total = 0;
112 ReadValue<uint16_t>(InFile, Total);
113 for (i = 0; (i < Total) && InFile; ++i)
114 {
115 EventAdd.Read(InFile);
116 Add(EventAdd);
117 }
118}
119
120const std::vector<CarlaRecorderEventAdd>& CarlaRecorderEventsAdd::GetEvents()
121{
122 return Events;
123}
void WriteFString(std::ostream &OutFile, const FString &InObj)
void ReadFString(std::istream &InFile, FString &OutObj)
void WriteFVector(std::ostream &OutFile, const FVector &InObj)
void ReadFVector(std::istream &InFile, FVector &OutObj)
std::vector< CarlaRecorderEventAdd > Events
void Add(const CarlaRecorderEventAdd &Event)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
const std::vector< CarlaRecorderEventAdd > & GetEvents()
std::vector< CarlaRecorderActorAttribute > Attributes
void Write(std::ostream &OutFile) const
void Read(std::istream &InFile)
CarlaRecorderActorDescription Description