Summary Files Commits Branches @commit @diff @stats
path: root / src / frame.cpp
diff options
context:
space:
mode:
Commitdb6384c470fe5660bf474aa49f46b00b893c4b3e (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-07-03 15:10:02 +0300
Committer
 Syndamia <kamen@syndamia.com>
2025-07-03 15:10:02 +0300
Files757b8683feb6bffbbc7f2643636806fd5b140858 /src/frame.cpp
iso-tp-parser-carista-db6384c470fe5660bf474aa49f46b00b893c4b3e.tar
iso-tp-parser-carista-db6384c470fe5660bf474aa49f46b00b893c4b3e.tar.gz
iso-tp-parser-carista-db6384c470fe5660bf474aa49f46b00b893c4b3e.zip
Parentbef1b7e46471f1668d2c84380ef685a15defe06a (diff)
chore(frame): Implement rule of 4 and move implementations from header to source
1 files changed, 55 insertions, 1 deletions
-rw-r--r--src/frame.cpp56
diff --git a/src/frame.cpp b/src/frame.cpp
index 05ec58d..babfef7 100644
--- a/src/frame.cpp
+++ b/src/frame.cpp
@@ -1,3 +1,4 @@
+#include <cstring>
#include "frame.h"
unsigned char hex_byte_to_byte(unsigned char byte) {
@@ -20,12 +21,14 @@ unsigned char next_hex_byte(const unsigned char*& iso_tp_frame) {
return byte;
}
+/* Private */
+
// b0 b1 b2 b3 b4 b5 b6 b7
// 02 10 C0 00 00 00 00 00
void Frame::parse_frame_str(const unsigned char* iso_tp_frame) {
unsigned char byte0 = next_hex_byte(iso_tp_frame);
- this->type = (FrameType)((byte0 & 0b11110000) >> 4);
+ this->type =(FrameType)((byte0 & 0b11110000) >> 4);
this->size = byte0 & 0b00001111;
switch (this->type) {
@@ -57,6 +60,57 @@ void Frame::parse_frame_str(const unsigned char* iso_tp_frame) {
}
}
+void Frame::free() {
+ delete[] this->data;
+}
+
+void Frame::copyFrom(const Frame& other) {
+ this->type = other.type;
+ this->size = other.size;
+ this->data_size = other.data_size;
+
+ this->data = new unsigned char[this->data_size];
+ std::memcpy(this->data, other.data, this->data_size);
+}
+
+/* Public */
+
+Frame::Frame(const char* iso_tp_frame) {
+ this->parse_frame_str((const unsigned char*)iso_tp_frame);
+}
+
+Frame::~Frame() {
+ free();
+}
+
+Frame::Frame(const Frame& other) {
+ copyFrom(other);
+}
+
+Frame& Frame::operator=(const Frame& other) {
+ if (this != &other) {
+ free();
+ copyFrom(other);
+ }
+ return *this;
+}
+
+FrameType Frame::get_type() const {
+ return this->type;
+}
+
+unsigned int Frame::get_size() const {
+ return this->size;
+}
+
+unsigned int Frame::get_data_size() const {
+ return this->data_size;
+}
+
+const unsigned char* Frame::get_data() const {
+ return this->data;
+}
+
std::ostream& operator<<(std::ostream& os, const Frame& f) {
for (int i = 0; i < f.data_size; ++i) {
os << (unsigned)f.data[i];