| 328 | |
| 329 | template <typename T, typename ElemLoader> |
| 330 | Expect<void> loadSectionContent(T &Sec, ElemLoader &&Func) { |
| 331 | Sec.setStartOffset(FMgr.getOffset()); |
| 332 | // Load the section size first. |
| 333 | EXPECTED_TRY(uint32_t SecSize, FMgr.readU32().map_error([this](auto E) { |
| 334 | return logLoadError(E, FMgr.getLastOffset(), NodeAttrFromAST<T>()); |
| 335 | })); |
| 336 | |
| 337 | // Check the remain file/buffer size. |
| 338 | if (unlikely(FMgr.getRemainSize() < SecSize)) { |
| 339 | return logLoadError(ErrCode::Value::LengthOutOfBounds, |
| 340 | FMgr.getLastOffset(), NodeAttrFromAST<T>()); |
| 341 | } |
| 342 | |
| 343 | // Set the section size. |
| 344 | Sec.setContentSize(SecSize); |
| 345 | auto StartOffset = FMgr.getOffset(); |
| 346 | |
| 347 | // Invoke the callback function. |
| 348 | EXPECTED_TRY(Func()); |
| 349 | |
| 350 | // Check the read size matches the section size. |
| 351 | auto EndOffset = FMgr.getOffset(); |
| 352 | if (EndOffset - StartOffset != Sec.getContentSize()) { |
| 353 | return logLoadError(ErrCode::Value::SectionSizeMismatch, EndOffset, |
| 354 | NodeAttrFromAST<T>()); |
| 355 | } |
| 356 | return {}; |
| 357 | } |
| 358 | |
| 359 | template <typename T, typename ElemLoader> |
| 360 | Expect<void> loadSectionContentVec(T &Sec, ElemLoader &&Func) { |
nothing calls this directly
no test coverage detected