chromium/third_party/openscreen/src/cast/common/channel/message_util.h

// 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.

#ifndef CAST_COMMON_CHANNEL_MESSAGE_UTIL_H_
#define CAST_COMMON_CHANNEL_MESSAGE_UTIL_H_

#include <string>
#include <string_view>

#include "cast/common/channel/proto/cast_channel.pb.h"

namespace Json {
class Value;
}

namespace openscreen::cast {

// Reserved message namespaces for internal messages.
static constexpr char kCastInternalNamespacePrefix[] =;
static constexpr char kTransportNamespacePrefix[] =;
static constexpr char kAuthNamespace[] =;
static constexpr char kHeartbeatNamespace[] =;
static constexpr char kConnectionNamespace[] =;
static constexpr char kReceiverNamespace[] =;
static constexpr char kBroadcastNamespace[] =;
static constexpr char kMediaNamespace[] =;

// Sender and receiver IDs to use for platform messages.
static constexpr char kPlatformSenderId[] =;
static constexpr char kPlatformReceiverId[] =;

static constexpr char kBroadcastId[] =;

static constexpr proto::CastMessage_ProtocolVersion
    kDefaultOutgoingMessageVersion =;

// JSON message key strings.
static constexpr char kMessageKeyType[] =;
static constexpr char kMessageKeyProtocolVersion[] =;
static constexpr char kMessageKeyProtocolVersionList[] =;
static constexpr char kMessageKeyReasonCode[] =;
static constexpr char kMessageKeyAppId[] =;
static constexpr char kMessageKeyRequestId[] =;
static constexpr char kMessageKeyResponseType[] =;
static constexpr char kMessageKeyTransportId[] =;
static constexpr char kMessageKeySessionId[] =;

// JSON message field values.
static constexpr char kMessageTypeConnect[] =;
static constexpr char kMessageTypeClose[] =;
static constexpr char kMessageTypeConnected[] =;
static constexpr char kMessageValueAppAvailable[] =;
static constexpr char kMessageValueAppUnavailable[] =;

// JSON message key strings specific to CONNECT messages.
static constexpr char kMessageKeyBrowserVersion[] =;
static constexpr char kMessageKeyConnType[] =;
static constexpr char kMessageKeyConnectionType[] =;
static constexpr char kMessageKeyUserAgent[] =;
static constexpr char kMessageKeyOrigin[] =;
static constexpr char kMessageKeyPlatform[] =;
static constexpr char kMessageKeySdkType[] =;
static constexpr char kMessageKeySenderInfo[] =;
static constexpr char kMessageKeyVersion[] =;

// JSON message key strings specific to application control messages.
static constexpr char kMessageKeyAvailability[] =;
static constexpr char kMessageKeyAppParams[] =;
static constexpr char kMessageKeyApplications[] =;
static constexpr char kMessageKeyControlType[] =;
static constexpr char kMessageKeyDisplayName[] =;
static constexpr char kMessageKeyIsIdleScreen[] =;
static constexpr char kMessageKeyLaunchedFromCloud[] =;
static constexpr char kMessageKeyLevel[] =;
static constexpr char kMessageKeyMuted[] =;
static constexpr char kMessageKeyName[] =;
static constexpr char kMessageKeyNamespaces[] =;
static constexpr char kMessageKeyReason[] =;
static constexpr char kMessageKeyStatus[] =;
static constexpr char kMessageKeyStepInterval[] =;
static constexpr char kMessageKeyUniversalAppId[] =;
static constexpr char kMessageKeyUserEq[] =;
static constexpr char kMessageKeyVolume[] =;

// JSON message field value strings specific to application control messages.
static constexpr char kMessageValueAttenuation[] =;
static constexpr char kMessageValueBadParameter[] =;
static constexpr char kMessageValueInvalidSessionId[] =;
static constexpr char kMessageValueInvalidCommand[] =;
static constexpr char kMessageValueNotFound[] =;
static constexpr char kMessageValueSystemError[] =;

enum class CastMessageType {};

enum class AppAvailabilityResult {};

std::string ToString(AppAvailabilityResult availability);

const char* CastMessageTypeToString(CastMessageType type);

inline bool IsAuthMessage(const proto::CastMessage& message) {}

inline bool IsTransportNamespace(std::string_view namespace_) {}

proto::CastMessage MakeSimpleUTF8Message(const std::string& namespace_,
                                         std::string payload);

proto::CastMessage MakeConnectMessage(const std::string& source_id,
                                      const std::string& destination_id);
proto::CastMessage MakeCloseMessage(const std::string& source_id,
                                    const std::string& destination_id);

// Returns a session/transport ID string that is unique within this application
// instance, having the format "prefix-12345". For example, calling this with a
// |prefix| of "sender" will result in a string like "sender-12345".
std::string MakeUniqueSessionId(const char* prefix);

// Returns true if the type field in |object| is set to the given |type|.
bool HasType(const Json::Value& object, CastMessageType type);

// Serializes a given cast message to a string.
std::string ToString(const proto::CastMessage& message);

// Helper to get the actual message payload out of a cast message.
const std::string& GetPayload(const proto::CastMessage& message);

}  // namespace openscreen::cast

#endif  // CAST_COMMON_CHANNEL_MESSAGE_UTIL_H_