2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 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 #ifndef incl_HPHP_JSON_CHANNELED_DECOMPRESSOR_H_
17 #define incl_HPHP_JSON_CHANNELED_DECOMPRESSOR_H_
22 #include "folly/dynamic.h"
23 #include "folly/FBString.h"
24 #include "folly/FBVector.h"
25 #include "folly/io/Cursor.h"
27 #include "hphp/util/gen-cpp/channeled_json_compressor_types.h"
30 ///////////////////////////////////////////////////////////////////////////////
33 A class that compresses json files according to channels
35 class ChanneledJsonDecompressor
{
38 ChanneledJsonDecompressor();
39 ~ChanneledJsonDecompressor();
41 // Reads the data into channels
42 void readChannels(folly::io::Cursor
& cursor
);
44 // Read an object from the underlying channels
45 void read(folly::dynamic
* outObj
);
48 // Read a variable length integer into from the given channels
49 int64_t readVarInt(Channel channel
);
51 // Read a type (The type is not Type because there are intermediate values)
55 void readMap(int64_t length
, folly::dynamic
* outMapObj
);
58 void readArray(int64_t length
, folly::dynamic
* outArrayObj
);
61 void readString(int64_t length
, Channel channel
,
62 folly::dynamic
* outStringObj
);
65 void readDouble(folly::dynamic
* outDoubleObj
);
69 // Maintains the channel's state
71 const folly::fbstring channel_
;
75 explicit ChannelState(const folly::fbstring
& channel
);
77 // Get the data pointer, advance the position
78 const char* read(uint32_t length
);
81 // output channels (implemented as strings).
82 // see this discussion of stringstream here: https://fburl.com/16088028
83 folly::fbvector
<ChannelState
> channels_
;
86 std::map
<uint32_t, folly::fbstring
> memoStrings_
;
87 uint32_t memoStringsNext_
;
90 std::map
<uint32_t, folly::fbstring
> memoKeys_
;
91 uint32_t memoKeysNext_
;