Message.cpp
author František Kučera <franta-hg@frantovo.cz>
Sun, 01 Jun 2025 13:18:10 +0200
branchv_0
changeset 20 a08e30243b95
parent 19 4ed672cecc25
permissions -rw-r--r--
Added tag v0.1 for changeset 334b727f7516
franta-hg@18
     1
/**
franta-hg@18
     2
 * djm-fix
franta-hg@18
     3
 * Copyright © 2025 František Kučera (Frantovo.cz, GlobalCode.info)
franta-hg@18
     4
 *
franta-hg@18
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@18
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@18
     7
 * the Free Software Foundation, version 3 of the License.
franta-hg@18
     8
 *
franta-hg@18
     9
 * This program is distributed in the hope that it will be useful,
franta-hg@18
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@18
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@18
    12
 * GNU General Public License for more details.
franta-hg@18
    13
 *
franta-hg@18
    14
 * You should have received a copy of the GNU General Public License
franta-hg@18
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@18
    16
 */
franta-hg@18
    17
franta-hg@18
    18
#include <sstream>
franta-hg@18
    19
#include <iomanip>
franta-hg@18
    20
franta-hg@18
    21
#include "Message.h"
franta-hg@18
    22
franta-hg@18
    23
std::string Message::toString() const {
franta-hg@18
    24
	std::stringstream s;
franta-hg@18
    25
	s << "<message";
franta-hg@19
    26
	s << " type='"  << std::hex << ((int) type)  << "'";
franta-hg@19
    27
	s << " model='" << std::hex << ((int) model) << "'";
franta-hg@18
    28
	s << ">";
franta-hg@18
    29
	for (const auto& field : fields) {
franta-hg@18
    30
		s << "<field type='" << std::hex << ((int) field.type) << "'>";
franta-hg@18
    31
		for (uint8_t b : field.data) {
franta-hg@18
    32
			s << std::hex << std::setw(2) << std::setfill('0') << (int) b;
franta-hg@18
    33
		}
franta-hg@18
    34
		s << "</field>";
franta-hg@18
    35
	}
franta-hg@18
    36
	s << "</message>";
franta-hg@18
    37
	return s.str();
franta-hg@18
    38
}
franta-hg@18
    39
franta-hg@18
    40
std::vector<Field> Message::findFields(FieldType type) {
franta-hg@18
    41
	std::vector<Field> found;
franta-hg@18
    42
	for (Field f : fields) if (f.type == type) found.push_back(f);
franta-hg@18
    43
	return found;
franta-hg@18
    44
}