MCPcopy Create free account
hub / github.com/JRickey/BattleShip / ReadResource

Method ReadResource

port/resource/RelocFileFactory.cpp:4–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include "RelocFile.h"
3
4std::shared_ptr<Ship::IResource>
5ResourceFactoryBinaryRelocFileV0::ReadResource(std::shared_ptr<Ship::File> file,
6 std::shared_ptr<Ship::ResourceInitData> initData) {
7 if (!FileHasValidFormatAndReader(file, initData)) {
8 return nullptr;
9 }
10
11 auto relocFile = std::make_shared<RelocFile>(initData);
12 auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
13
14 relocFile->FileId = reader->ReadUInt32();
15 relocFile->RelocInternOffset = reader->ReadUInt16();
16 relocFile->RelocExternOffset = reader->ReadUInt16();
17
18 uint32_t numExternIds = reader->ReadUInt32();
19 relocFile->ExternFileIds.reserve(numExternIds);
20 for (uint32_t i = 0; i < numExternIds; i++) {
21 relocFile->ExternFileIds.push_back(reader->ReadUInt16());
22 }
23
24 uint32_t dataSize = reader->ReadUInt32();
25 relocFile->Data.resize(dataSize);
26 reader->Read(reinterpret_cast<char*>(relocFile->Data.data()), static_cast<int32_t>(dataSize));
27
28 return relocFile;
29}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected