1
1
#include " resource/factory/BlobFactory.h"
2
2
#include " resource/type/Blob.h"
3
+ #include " resource/readerbox/BinaryReaderBox.h"
3
4
#include " spdlog/spdlog.h"
4
5
5
6
namespace LUS {
6
- std::shared_ptr<IResource> BlobFactory::ReadResource (std::shared_ptr<ResourceInitData> initData,
7
- std::shared_ptr<BinaryReader> reader) {
8
- auto resource = std::make_shared<Blob>(initData);
9
- std::shared_ptr<ResourceVersionFactory> factory = nullptr ;
10
-
11
- switch (resource->GetInitData ()->ResourceVersion ) {
12
- case 0 :
13
- factory = std::make_shared<BlobFactoryV0>();
14
- break ;
7
+ std::shared_ptr<IResource> ResourceFactoryBinaryBlobV0::ReadResource (std::shared_ptr<ResourceInitData> initData,
8
+ std::shared_ptr<ReaderBox> readerBox) {
9
+ auto binaryReaderBox = std::dynamic_pointer_cast<BinaryReaderBox>(readerBox);
10
+ if (binaryReaderBox == nullptr ) {
11
+ SPDLOG_ERROR (" ReaderBox must be a BinaryReaderBox." );
12
+ return nullptr ;
15
13
}
16
14
17
- if (factory == nullptr ) {
18
- SPDLOG_ERROR (" Failed to load Blob with version {}" , resource->GetInitData ()->ResourceVersion );
15
+ auto reader = binaryReaderBox->GetReader ();
16
+ if (reader == nullptr ) {
17
+ SPDLOG_ERROR (" null reader in box." );
19
18
return nullptr ;
20
19
}
21
20
22
- factory->ParseFileBinary (reader, resource);
23
-
24
- return resource;
25
- }
26
-
27
- void BlobFactoryV0::ParseFileBinary (std::shared_ptr<BinaryReader> reader, std::shared_ptr<IResource> resource) {
28
- std::shared_ptr<Blob> blob = std::static_pointer_cast<Blob>(resource);
29
- ResourceVersionFactory::ParseFileBinary (reader, blob);
21
+ auto blob = std::make_shared<Blob>(initData);
30
22
31
23
uint32_t dataSize = reader->ReadUInt32 ();
32
24
@@ -35,5 +27,7 @@ void BlobFactoryV0::ParseFileBinary(std::shared_ptr<BinaryReader> reader, std::s
35
27
for (uint32_t i = 0 ; i < dataSize; i++) {
36
28
blob->Data .push_back (reader->ReadUByte ());
37
29
}
30
+
31
+ return blob;
38
32
}
39
33
} // namespace LUS
0 commit comments