OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/media/router/route_message.h" | |
6 | |
7 #include "base/base64.h" | |
8 #include "base/json/string_escape.h" | |
9 | |
10 namespace media_router { | |
11 | |
12 RouteMessage::RouteMessage() = default; | |
13 RouteMessage::RouteMessage(const RouteMessage& other) = default; | |
14 RouteMessage::~RouteMessage() = default; | |
15 | |
16 std::string RouteMessage::ToHumanReadableString() const { | |
17 if (!text && !binary) | |
18 return "null"; | |
19 DCHECK((type == TEXT && text) || (type == BINARY && binary)); | |
20 std::string result; | |
21 if (text) { | |
22 result = "text="; | |
23 base::EscapeJSONString(*text, true, &result); | |
24 } else { | |
25 const base::StringPiece src(reinterpret_cast<const char*>(binary->data()), | |
26 binary->size()); | |
27 base::Base64Encode(src, &result); | |
28 result = "binary=" + result; | |
29 } | |
30 return result; | |
31 } | |
32 | |
33 } // namespace media_router | |
OLD | NEW |