Fix crash when trying to change staticness of a property
[hiphop-php.git] / hphp / util / channeled-json-decompressor.h
blob2727f96aa63fb7535791a85fe6abcdc2f038f4b5
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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_
19 #include <vector>
20 #include <map>
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"
29 namespace HPHP {
30 ///////////////////////////////////////////////////////////////////////////////
32 /**
33 A class that compresses json files according to channels
35 class ChanneledJsonDecompressor {
37 public:
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);
47 private:
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)
52 uint8_t readType();
54 // read a map
55 void readMap(int64_t length, folly::dynamic* outMapObj);
57 // write an array
58 void readArray(int64_t length, folly::dynamic* outArrayObj);
60 // write a string
61 void readString(int64_t length, Channel channel,
62 folly::dynamic* outStringObj);
64 // write a double
65 void readDouble(folly::dynamic* outDoubleObj);
67 private:
69 // Maintains the channel's state
70 struct ChannelState {
71 const folly::fbstring channel_;
72 uint32_t pos_;
74 // Contructor
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_;
85 // memoised strings
86 std::map<uint32_t, folly::fbstring> memoStrings_;
87 uint32_t memoStringsNext_;
89 //memoised keys
90 std::map<uint32_t, folly::fbstring> memoKeys_;
91 uint32_t memoKeysNext_;
94 } // namespace HPHP
96 #endif