1 // Copyright (c) 2006- Facebook
2 // Distributed under the Thrift Software License
4 // See accompanying file LICENSE or visit the Thrift site at:
5 // http://developers.facebook.com/thrift/
7 #ifndef _THRIFT_TREFLECTIONLOCAL_H_
8 #define _THRIFT_TREFLECTIONLOCAL_H_ 1
12 #include <protocol/TProtocol.h>
15 * Local Reflection is a blanket term referring to the the structure
16 * and generation of this particular representation of Thrift types.
17 * (It is called local because it cannot be serialized by Thrift).
19 * @author David Reiss <dreiss@facebook.com>
22 namespace facebook
{ namespace thrift
{ namespace reflection
{ namespace local
{
24 using facebook::thrift::protocol::TType
;
26 // We include this many bytes of the structure's fingerprint when serializing
27 // a top-level structure. Long enough to make collisions unlikely, short
28 // enough to not significantly affect the amount of memory used.
29 const int FP_PREFIX_LEN
= 4;
38 uint8_t fp_prefix
[FP_PREFIX_LEN
];
40 // Use an anonymous union here so we can fit two TypeSpecs in one cache line.
43 // Use parallel arrays here for denser packing (of the arrays).
53 // Static initialization of unions isn't really possible,
54 // so take the plunge and use constructors.
55 // Hopefully they'll be evaluated at compile time.
57 TypeSpec(TType ttype
) : ttype(ttype
) {
58 std::memset(fp_prefix
, 0, FP_PREFIX_LEN
);
62 const uint8_t* fingerprint
,
67 std::memcpy(fp_prefix
, fingerprint
, FP_PREFIX_LEN
);
68 tstruct
.metas
= metas
;
69 tstruct
.specs
= specs
;
72 TypeSpec(TType ttype
, TypeSpec
* subtype1
, TypeSpec
* subtype2
) :
75 std::memset(fp_prefix
, 0, FP_PREFIX_LEN
);
76 tcontainer
.subtype1
= subtype1
;
77 tcontainer
.subtype2
= subtype2
;
82 }}}} // facebook::thrift::reflection::local
84 #endif // #ifndef _THRIFT_TREFLECTIONLOCAL_H_