mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 09:35:48 +00:00
1635c02e92
Summary: Since we are reading from a file, we should make sure this struct is packed, just in case we change it down the line and the compiler decides it might want to introduce padding, we're now protected against that. There was also a discussion about the fact that people might use `ptr += sizeof(BundleHeader)` as an idiom in their code, which would currently be incorrect, if padding was introduced at the end of the file. Actually, it remains incorrect to do that now, because a RAM bundle header is a different size to a BC Bundle header. If people are properly testing their code, they should spot this pretty quickly, because it will always be an incorrect thing to do with a RAM bundle, so this isn't as bad as previously thought: where the code only succeeds when the compiler deigns to not pad the struct at the end. This diff also cleans up how headers are initialised. `BundleHeader` has a constructor that explicitly zero-initialises it so we can rely on the default initializer to do the right thing now. Reviewed By: mhorowitz Differential Revision: D4572032 fbshipit-source-id: 7dc50cfa9438dfdfb9f842dc39d8f15334813c63
38 lines
858 B
C++
38 lines
858 B
C++
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
#include "JSBundleType.h"
|
|
#include "oss-compat-util.h"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
static uint32_t constexpr RAMBundleMagicNumber = 0xFB0BD1E5;
|
|
static uint32_t constexpr BCBundleMagicNumber = 0x6D657300;
|
|
|
|
ScriptTag parseTypeFromHeader(const BundleHeader& header) {
|
|
|
|
switch (littleEndianToHost(header.magic)) {
|
|
case RAMBundleMagicNumber:
|
|
return ScriptTag::RAMBundle;
|
|
case BCBundleMagicNumber:
|
|
return ScriptTag::BCBundle;
|
|
default:
|
|
return ScriptTag::String;
|
|
}
|
|
}
|
|
|
|
const char *stringForScriptTag(const ScriptTag& tag) {
|
|
switch (tag) {
|
|
case ScriptTag::String:
|
|
return "String";
|
|
case ScriptTag::RAMBundle:
|
|
return "RAM Bundle";
|
|
case ScriptTag::BCBundle:
|
|
return "BC Bundle";
|
|
}
|
|
return "";
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|