aboutsummaryrefslogtreecommitdiff
path: root/cast/streaming/message_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'cast/streaming/message_util.h')
-rw-r--r--cast/streaming/message_util.h32
1 files changed, 15 insertions, 17 deletions
diff --git a/cast/streaming/message_util.h b/cast/streaming/message_util.h
index 17345495..de207da2 100644
--- a/cast/streaming/message_util.h
+++ b/cast/streaming/message_util.h
@@ -8,21 +8,19 @@
#include "json/value.h"
#include "platform/base/error.h"
+namespace openscreen {
namespace cast {
-namespace streaming {
-inline openscreen::Error CreateParseError(const std::string& type) {
- return openscreen::Error(openscreen::Error::Code::kJsonParseError,
- "Failed to parse " + type);
+inline Error CreateParseError(const std::string& type) {
+ return Error(Error::Code::kJsonParseError, "Failed to parse " + type);
}
-inline openscreen::Error CreateParameterError(const std::string& type) {
- return openscreen::Error(openscreen::Error::Code::kParameterInvalid,
- "Invalid parameter: " + type);
+inline Error CreateParameterError(const std::string& type) {
+ return Error(Error::Code::kParameterInvalid, "Invalid parameter: " + type);
}
-inline openscreen::ErrorOr<bool> ParseBool(const Json::Value& parent,
- const std::string& field) {
+inline ErrorOr<bool> ParseBool(const Json::Value& parent,
+ const std::string& field) {
const Json::Value& value = parent[field];
if (!value.isBool()) {
return CreateParseError("bool field " + field);
@@ -30,8 +28,8 @@ inline openscreen::ErrorOr<bool> ParseBool(const Json::Value& parent,
return value.asBool();
}
-inline openscreen::ErrorOr<int> ParseInt(const Json::Value& parent,
- const std::string& field) {
+inline ErrorOr<int> ParseInt(const Json::Value& parent,
+ const std::string& field) {
const Json::Value& value = parent[field];
if (!value.isInt()) {
return CreateParseError("integer field: " + field);
@@ -39,8 +37,8 @@ inline openscreen::ErrorOr<int> ParseInt(const Json::Value& parent,
return value.asInt();
}
-inline openscreen::ErrorOr<uint32_t> ParseUint(const Json::Value& parent,
- const std::string& field) {
+inline ErrorOr<uint32_t> ParseUint(const Json::Value& parent,
+ const std::string& field) {
const Json::Value& value = parent[field];
if (!value.isUInt()) {
return CreateParseError("unsigned integer field: " + field);
@@ -48,8 +46,8 @@ inline openscreen::ErrorOr<uint32_t> ParseUint(const Json::Value& parent,
return value.asUInt();
}
-inline openscreen::ErrorOr<std::string> ParseString(const Json::Value& parent,
- const std::string& field) {
+inline ErrorOr<std::string> ParseString(const Json::Value& parent,
+ const std::string& field) {
const Json::Value& value = parent[field];
if (!value.isString()) {
return CreateParseError("string field: " + field);
@@ -61,14 +59,14 @@ inline openscreen::ErrorOr<std::string> ParseString(const Json::Value& parent,
// Use this template for parsing only when there is a reasonable default
// for the type you are using, e.g. int or std::string.
template <typename T>
-T ValueOrDefault(const openscreen::ErrorOr<T>& value, T fallback = T{}) {
+T ValueOrDefault(const ErrorOr<T>& value, T fallback = T{}) {
if (value.is_value()) {
return value.value();
}
return fallback;
}
-} // namespace streaming
} // namespace cast
+} // namespace openscreen
#endif // CAST_STREAMING_MESSAGE_UTIL_H_