Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_JSON_JSON_VALUE_SERIALIZER_H_ | 5 #ifndef BASE_JSON_JSON_VALUE_SERIALIZER_H_ |
| 6 #define BASE_JSON_JSON_VALUE_SERIALIZER_H_ | 6 #define BASE_JSON_JSON_VALUE_SERIALIZER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 : json_string_(&const_cast<std::string&>(json_string)), | 31 : json_string_(&const_cast<std::string&>(json_string)), |
| 32 initialized_with_const_string_(true), | 32 initialized_with_const_string_(true), |
| 33 pretty_print_(false), | 33 pretty_print_(false), |
| 34 allow_trailing_comma_(false) { | 34 allow_trailing_comma_(false) { |
| 35 } | 35 } |
| 36 | 36 |
| 37 virtual ~JSONStringValueSerializer(); | 37 virtual ~JSONStringValueSerializer(); |
| 38 | 38 |
| 39 // Attempt to serialize the data structure represented by Value into | 39 // Attempt to serialize the data structure represented by Value into |
| 40 // JSON. If the return value is true, the result will have been written | 40 // JSON. If the return value is true, the result will have been written |
| 41 // into the string passed into the constructor. | 41 // into the string passed into the constructor. In the overloaded method, |
|
Jói
2011/11/10 11:08:16
Please document this separately rather than togeth
Eric Dingle
2011/11/10 15:05:25
Done.
| |
| 42 // |ignore_binary_values| is used to indicate how the serializer should | |
| 43 // behave when encountering a binary value. | |
| 42 virtual bool Serialize(const Value& root); | 44 virtual bool Serialize(const Value& root); |
| 45 virtual bool Serialize(const Value& root, bool ignore_binary_values); | |
| 43 | 46 |
| 44 // Attempt to deserialize the data structure encoded in the string passed | 47 // Attempt to deserialize the data structure encoded in the string passed |
| 45 // in to the constructor into a structure of Value objects. If the return | 48 // in to the constructor into a structure of Value objects. If the return |
| 46 // value is NULL, and if |error_code| is non-null, |error_code| will | 49 // value is NULL, and if |error_code| is non-null, |error_code| will |
| 47 // contain an integer error code (either JsonFileError or JsonParseError). | 50 // contain an integer error code (either JsonFileError or JsonParseError). |
| 48 // If |error_message| is non-null, it will be filled in with a formatted | 51 // If |error_message| is non-null, it will be filled in with a formatted |
| 49 // error message including the location of the error if appropriate. | 52 // error message including the location of the error if appropriate. |
| 50 // The caller takes ownership of the returned value. | 53 // The caller takes ownership of the returned value. |
| 51 virtual Value* Deserialize(int* error_code, std::string* error_message); | 54 virtual Value* Deserialize(int* error_code, std::string* error_message); |
| 52 | 55 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 80 | 83 |
| 81 // DO NOT USE except in unit tests to verify the file was written properly. | 84 // DO NOT USE except in unit tests to verify the file was written properly. |
| 82 // We should never serialize directly to a file since this will block the | 85 // We should never serialize directly to a file since this will block the |
| 83 // thread. Instead, serialize to a string and write to the file you want on | 86 // thread. Instead, serialize to a string and write to the file you want on |
| 84 // the file thread. | 87 // the file thread. |
| 85 // | 88 // |
| 86 // Attempt to serialize the data structure represented by Value into | 89 // Attempt to serialize the data structure represented by Value into |
| 87 // JSON. If the return value is true, the result will have been written | 90 // JSON. If the return value is true, the result will have been written |
| 88 // into the file whose name was passed into the constructor. | 91 // into the file whose name was passed into the constructor. |
| 89 virtual bool Serialize(const Value& root); | 92 virtual bool Serialize(const Value& root); |
| 93 virtual bool Serialize(const Value& root, bool ignore_binary_values); | |
| 90 | 94 |
| 91 // Attempt to deserialize the data structure encoded in the file passed | 95 // Attempt to deserialize the data structure encoded in the file passed |
| 92 // in to the constructor into a structure of Value objects. If the return | 96 // in to the constructor into a structure of Value objects. If the return |
| 93 // value is NULL, and if |error_code| is non-null, |error_code| will | 97 // value is NULL, and if |error_code| is non-null, |error_code| will |
| 94 // contain an integer error code (either JsonFileError or JsonParseError). | 98 // contain an integer error code (either JsonFileError or JsonParseError). |
| 95 // If |error_message| is non-null, it will be filled in with a formatted | 99 // If |error_message| is non-null, it will be filled in with a formatted |
| 96 // error message including the location of the error if appropriate. | 100 // error message including the location of the error if appropriate. |
| 97 // The caller takes ownership of the returned value. | 101 // The caller takes ownership of the returned value. |
| 98 virtual Value* Deserialize(int* error_code, std::string* error_message); | 102 virtual Value* Deserialize(int* error_code, std::string* error_message); |
| 99 | 103 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 120 FilePath json_file_path_; | 124 FilePath json_file_path_; |
| 121 | 125 |
| 122 // A wrapper for file_util::ReadFileToString which returns a non-zero | 126 // A wrapper for file_util::ReadFileToString which returns a non-zero |
| 123 // JsonFileError if there were file errors. | 127 // JsonFileError if there were file errors. |
| 124 int ReadFileToString(std::string* json_string); | 128 int ReadFileToString(std::string* json_string); |
| 125 | 129 |
| 126 DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueSerializer); | 130 DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueSerializer); |
| 127 }; | 131 }; |
| 128 | 132 |
| 129 #endif // BASE_JSON_JSON_VALUE_SERIALIZER_H_ | 133 #endif // BASE_JSON_JSON_VALUE_SERIALIZER_H_ |
| OLD | NEW |