2016-11-23 14:31:43 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <memory>
|
|
|
|
|
2017-09-22 16:56:52 +00:00
|
|
|
#include <cxxreact/JSBigString.h>
|
2017-02-16 14:45:41 +00:00
|
|
|
#include <cxxreact/JSModulesUnbundle.h>
|
2016-11-23 14:31:43 +00:00
|
|
|
|
2017-06-27 18:15:36 +00:00
|
|
|
#ifndef RN_EXPORT
|
|
|
|
#define RN_EXPORT __attribute__((visibility("default")))
|
|
|
|
#endif
|
|
|
|
|
2016-11-23 14:31:43 +00:00
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
2017-06-27 18:15:36 +00:00
|
|
|
class RN_EXPORT JSIndexedRAMBundle : public JSModulesUnbundle {
|
2016-11-23 14:31:43 +00:00
|
|
|
public:
|
|
|
|
// Throws std::runtime_error on failure.
|
|
|
|
JSIndexedRAMBundle(const char *sourceURL);
|
|
|
|
|
|
|
|
// Throws std::runtime_error on failure.
|
2017-02-01 22:10:34 +00:00
|
|
|
std::unique_ptr<const JSBigString> getStartupCode();
|
2016-11-23 14:31:43 +00:00
|
|
|
// Throws std::runtime_error on failure.
|
|
|
|
Module getModule(uint32_t moduleId) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct ModuleData {
|
|
|
|
uint32_t offset;
|
|
|
|
uint32_t length;
|
|
|
|
};
|
|
|
|
static_assert(
|
|
|
|
sizeof(ModuleData) == 8,
|
|
|
|
"ModuleData must not have any padding and use sizes matching input files");
|
|
|
|
|
|
|
|
struct ModuleTable {
|
|
|
|
size_t numEntries;
|
|
|
|
std::unique_ptr<ModuleData[]> data;
|
|
|
|
ModuleTable() : numEntries(0) {};
|
|
|
|
ModuleTable(size_t entries) :
|
|
|
|
numEntries(entries),
|
2016-12-03 10:18:59 +00:00
|
|
|
data(std::unique_ptr<ModuleData[]>(new ModuleData[numEntries])) {};
|
2016-11-23 14:31:43 +00:00
|
|
|
size_t byteLength() const {
|
|
|
|
return numEntries * sizeof(ModuleData);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string getModuleCode(const uint32_t id) const;
|
|
|
|
void readBundle(char *buffer, const std::streamsize bytes) const;
|
|
|
|
void readBundle(
|
|
|
|
char *buffer, const
|
|
|
|
std::streamsize bytes,
|
|
|
|
const std::ifstream::pos_type position) const;
|
|
|
|
|
|
|
|
mutable std::ifstream m_bundle;
|
|
|
|
ModuleTable m_table;
|
|
|
|
size_t m_baseOffset;
|
2017-02-01 22:10:34 +00:00
|
|
|
std::unique_ptr<JSBigBufferString> m_startupCode;
|
2016-11-23 14:31:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|