1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Message.cpp Sun May 11 00:30:03 2025 +0200
1.3 @@ -0,0 +1,44 @@
1.4 +/**
1.5 + * djm-fix
1.6 + * Copyright © 2025 František Kučera (Frantovo.cz, GlobalCode.info)
1.7 + *
1.8 + * This program is free software: you can redistribute it and/or modify
1.9 + * it under the terms of the GNU General Public License as published by
1.10 + * the Free Software Foundation, version 3 of the License.
1.11 + *
1.12 + * This program is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 + * GNU General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU General Public License
1.18 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1.19 + */
1.20 +
1.21 +#include <sstream>
1.22 +#include <iomanip>
1.23 +
1.24 +#include "Message.h"
1.25 +
1.26 +std::string Message::toString() const {
1.27 + std::stringstream s;
1.28 + s << "<message";
1.29 + s << " type='" << std::hex << ((int) type) << "'";
1.30 + s << " version='" << std::hex << ((int) version) << "'";
1.31 + s << ">";
1.32 + for (const auto& field : fields) {
1.33 + s << "<field type='" << std::hex << ((int) field.type) << "'>";
1.34 + for (uint8_t b : field.data) {
1.35 + s << std::hex << std::setw(2) << std::setfill('0') << (int) b;
1.36 + }
1.37 + s << "</field>";
1.38 + }
1.39 + s << "</message>";
1.40 + return s.str();
1.41 +}
1.42 +
1.43 +std::vector<Field> Message::findFields(FieldType type) {
1.44 + std::vector<Field> found;
1.45 + for (Field f : fields) if (f.type == type) found.push_back(f);
1.46 + return found;
1.47 +}