1 // 2 // json_util.hpp 3 // util 4 // 5 // Copyright © 2024 Apple Inc. All rights reserved. 6 // 7 // Please refer to the license found in the LICENSE file in the root directory of the source tree. 8 9 #pragma once 10 11 #include <iostream> 12 #include <optional> 13 #include <sstream> 14 15 namespace executorchcoreml { 16 namespace json { 17 /// Reads and returns the first json object from the stream. 18 /// 19 /// The returned string is not guaranteed to be a valid json object, the caller must 20 /// use a JSON parser to parse the returned string into a json object. 21 /// 22 /// 23 /// @param stream The stream to read from. 24 /// @param max_bytes_to_read The maximum bytes that can be read from the stream. 25 /// @retval The json object string or `nullopt` if there is no json object in the stream. 26 std::optional<std::string> read_object_from_stream(std::istream& stream, 27 size_t max_bytes_to_read = 10 * 1024 * 1024); 28 29 } // namespace json 30 } // namespace executorchcoreml 31