| 950 | } |
| 951 | |
| 952 | void emitFieldAccessors(const std::vector<Field>& fields, |
| 953 | const std::vector<Field>& sideFields, |
| 954 | const std::vector<std::string>& external) { |
| 955 | for (size_t i = 0; i < fields.size(); ++i) { |
| 956 | const Field& field = fields[i]; |
| 957 | const std::string offset = offsetExpr(fields, i, sideFields, external); |
| 958 | if (field.type == "bytes") { |
| 959 | const std::string length = lengthExpr(field, sideFields, external); |
| 960 | out_ << " std::span<uint8> " << field.name << "() { return detail::Slice(body(), " |
| 961 | << offset << ", " << length << "); }\n" |
| 962 | << " std::span<const uint8> " << field.name |
| 963 | << "() const { return detail::Slice(body(), " << offset << ", " << length << "); }\n" |
| 964 | << " bool set_" << field.name |
| 965 | << "(std::span<const uint8> value) { return detail::CopyBytes(body(), " |
| 966 | << offset << ", " << length << ", value); }\n"; |
| 967 | } else { |
| 968 | out_ << " " << field.type << " " << field.name |
| 969 | << "() const { return detail::Read<" << field.type << ">(body(), " << offset << "); }\n" |
| 970 | << " void set_" << field.name << "(" << field.type |
| 971 | << " value) { detail::Write(body(), " << offset << ", value); }\n"; |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | void emitDebugString(const std::string& cls, const std::vector<Field>& fields) { |
| 977 | out_ << " std::string DebugString() const {\n" |