Serialize custom section. See "include/loader/serialize.h".
| 8 | |
| 9 | // Serialize custom section. See "include/loader/serialize.h". |
| 10 | Expect<void> |
| 11 | Serializer::serializeSection(const AST::CustomSection &Sec, |
| 12 | std::vector<uint8_t> &OutVec) const noexcept { |
| 13 | // Custom section: 0x00 + size:u32 + name:vec(byte) + content:byte*. |
| 14 | // Section ID. |
| 15 | OutVec.push_back(0x00U); |
| 16 | auto OrgSize = OutVec.size(); |
| 17 | // Name: vec(byte). |
| 18 | serializeU32(static_cast<uint32_t>(Sec.getName().size()), OutVec); |
| 19 | OutVec.insert(OutVec.end(), Sec.getName().begin(), Sec.getName().end()); |
| 20 | // Content: byte*. |
| 21 | OutVec.insert(OutVec.end(), Sec.getContent().begin(), Sec.getContent().end()); |
| 22 | // Backward insert the section size. |
| 23 | serializeU32(static_cast<uint32_t>(OutVec.size() - OrgSize), OutVec, |
| 24 | std::next(OutVec.begin(), static_cast<ptrdiff_t>(OrgSize))); |
| 25 | return {}; |
| 26 | } |
| 27 | |
| 28 | // Serialize type section. See "include/loader/serialize.h". |
| 29 | Expect<void> |