2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #include "hphp/runtime/base/repo-auth-type-codec.h"
18 #include "hphp/runtime/vm/unit.h"
19 #include "hphp/runtime/vm/repo.h"
20 #include "hphp/runtime/vm/repo-global-data.h"
24 //////////////////////////////////////////////////////////////////////
28 template <class LookupStr
, class LookupArrayType
>
29 RepoAuthType
decodeRATImpl(const unsigned char*& pc
, LookupStr lookupStr
,
30 LookupArrayType lookupArrayType
) {
31 using T
= RepoAuthType::Tag
;
32 auto const rawTag
= *pc
++;
33 bool const highBitSet
= rawTag
& kRATArrayDataBit
;
34 auto const tag
= static_cast<T
>(rawTag
& ~kRATArrayDataBit
);
65 return RepoAuthType
{tag
};
93 std::memcpy(&id
, pc
, sizeof id
);
95 auto const arr
= lookupArrayType(id
);
96 return RepoAuthType
{tag
, arr
};
98 return RepoAuthType
{tag
};
107 std::memcpy(&id
, pc
, sizeof id
);
109 const StringData
* const clsName
= lookupStr(id
);
110 return RepoAuthType
{tag
, clsName
};
118 RepoAuthType
decodeRAT(const Unit
* unit
, const unsigned char*& pc
) {
119 return decodeRATImpl(
121 [&](uint32_t id
) { return unit
->lookupLitstrId(id
); },
122 [&](uint32_t id
) { return unit
->lookupArrayTypeId(id
); }
126 RepoAuthType
decodeRAT(const UnitEmitter
& ue
, const unsigned char*& pc
) {
127 return decodeRATImpl(
129 [&](uint32_t id
) { return ue
.lookupLitstr(id
); },
130 [&](uint32_t id
) { return ue
.lookupArrayType(id
); }
134 void encodeRAT(UnitEmitter
& ue
, RepoAuthType rat
) {
135 using T
= RepoAuthType::Tag
;
156 case T::OptUncArrKey
:
165 ue
.emitByte(static_cast<uint8_t>(rat
.tag()));
193 auto tagByte
= static_cast<uint8_t>(rat
.tag());
194 if (rat
.hasArrData()) tagByte
|= kRATArrayDataBit
;
195 ue
.emitByte(tagByte
);
196 if (rat
.hasArrData()) {
197 ue
.emitInt32(rat
.arrayId());
206 ue
.emitByte(static_cast<uint8_t>(rat
.tag()));
207 ue
.emitInt32(ue
.mergeLitstr(rat
.clsName()));
212 //////////////////////////////////////////////////////////////////////