// Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef GOOGLE_PROTOBUF_UTIL_INTERNAL_JSON_STREAM_PARSER_H__ #define GOOGLE_PROTOBUF_UTIL_INTERNAL_JSON_STREAM_PARSER_H__ #include <cstdint> #include <stack> #include <string> #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/status.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/status.h> // Must be included last. #include <google/protobuf/port_def.inc> namespace google { namespace protobuf { namespace util { namespace converter { class ObjectWriter; // A JSON parser that can parse a stream of JSON chunks rather than needing the // entire JSON string up front. It is a modified version of the parser in // //net/proto/json/json-parser.h that has been changed in the following ways: // - Changed from recursion to an explicit stack to allow resumption // - Added support for int64 and uint64 numbers // - Removed support for octal and decimal escapes // - Removed support for numeric keys // - Removed support for functions (javascript) // - Removed some lax-comma support (but kept trailing comma support) // - Writes directly to an ObjectWriter rather than using subclassing // // Here is an example usage: // JsonStreamParser parser(ow_.get()); // util::Status result = parser.Parse(chunk1); // result.Update(parser.Parse(chunk2)); // result.Update(parser.FinishParse()); // GOOGLE_DCHECK(result.ok()) << "Failed to parse JSON"; // // This parser is thread-compatible as long as only one thread is calling a // Parse() method at a time. class PROTOBUF_EXPORT JsonStreamParser { … }; } // namespace converter } // namespace util } // namespace protobuf } // namespace google #include <google/protobuf/port_undef.inc> #endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_JSON_STREAM_PARSER_H__