Some checks failed
dev release / build (push) Failing after 12s
Builds out the full v1 scope: a vendored+patched openscreen subset for low-latency Cast Streaming (Mirroring receiver 0F5096E8) alongside the existing Cast V2/HLS and new DLNA/AVTransport casting paths, breadcastd's Idle/Casting state machine with a private IPC socket, the breadcast GTK4 popup as a thin IPC client, and bread.cast.*/bread.command.cast.* breadd integration (device discovery, start/stop, mirroring lifecycle events). Also adds bakery/systemd/Forgejo CI packaging. Validated end-to-end against a real Chromecast/Google TV: negotiated Cast Streaming session, live pipeline playback, and daemon+GUI click-to-cast/ stop through the actual popup.
62 lines
1.9 KiB
C++
62 lines
1.9 KiB
C++
// Copyright 2019 The Chromium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "util/json/json_serialization.h"
|
|
|
|
#include <memory>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
#include "json/reader.h"
|
|
#include "json/writer.h"
|
|
#include "platform/base/error.h"
|
|
#include "util/osp_logging.h"
|
|
|
|
namespace openscreen::json {
|
|
|
|
ErrorOr<Json::Value> Parse(std::string_view document) {
|
|
Json::CharReaderBuilder builder;
|
|
Json::CharReaderBuilder::strictMode(&builder.settings_);
|
|
if (document.empty()) {
|
|
return ErrorOr<Json::Value>(Error::Code::kJsonParseError, "empty document");
|
|
}
|
|
|
|
Json::Value root_node;
|
|
std::string error_msg;
|
|
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
|
|
const bool succeeded = reader->parse(&*document.begin(), &*document.end(),
|
|
&root_node, &error_msg);
|
|
if (!succeeded) {
|
|
return ErrorOr<Json::Value>(Error::Code::kJsonParseError, error_msg);
|
|
}
|
|
|
|
return root_node;
|
|
}
|
|
|
|
ErrorOr<std::string> Stringify(const Json::Value& value) {
|
|
Json::StreamWriterBuilder factory;
|
|
#ifndef _DEBUG
|
|
// Default is to "pretty print" the output JSON in a human readable
|
|
// format. On non-debug builds, we can remove pretty printing by simply
|
|
// getting rid of all indentation.
|
|
factory["indentation"] = "";
|
|
#endif
|
|
|
|
std::unique_ptr<Json::StreamWriter> const writer(factory.newStreamWriter());
|
|
std::ostringstream stream;
|
|
writer->write(value, &stream);
|
|
|
|
if (!stream) {
|
|
// Note: jsoncpp doesn't give us more information about what actually
|
|
// went wrong, just says to "check the stream". However, failures on
|
|
// the stream should be rare, as we do not throw any errors in the jsoncpp
|
|
// library.
|
|
return ErrorOr<std::string>(Error::Code::kJsonWriteError, "Invalid stream");
|
|
}
|
|
|
|
return stream.str();
|
|
}
|
|
|
|
} // namespace openscreen::json
|