OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "jingle/glue/utils.h" | 5 #include "jingle/glue/utils.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 value.SetString("ip", candidate.address().IPAsString()); | 46 value.SetString("ip", candidate.address().IPAsString()); |
47 value.SetInteger("port", candidate.address().port()); | 47 value.SetInteger("port", candidate.address().port()); |
48 value.SetString("type", candidate.type()); | 48 value.SetString("type", candidate.type()); |
49 value.SetString("protocol", candidate.protocol()); | 49 value.SetString("protocol", candidate.protocol()); |
50 value.SetString("username", candidate.username()); | 50 value.SetString("username", candidate.username()); |
51 value.SetString("password", candidate.password()); | 51 value.SetString("password", candidate.password()); |
52 value.SetDouble("preference", candidate.preference()); | 52 value.SetDouble("preference", candidate.preference()); |
53 value.SetInteger("generation", candidate.generation()); | 53 value.SetInteger("generation", candidate.generation()); |
54 | 54 |
55 std::string result; | 55 std::string result; |
56 base::JSONWriter::Write(&value, false, &result); | 56 base::JSONWriter::Write(&value, &result); |
57 return result; | 57 return result; |
58 } | 58 } |
59 | 59 |
60 bool DeserializeP2PCandidate(const std::string& candidate_str, | 60 bool DeserializeP2PCandidate(const std::string& candidate_str, |
61 cricket::Candidate* candidate) { | 61 cricket::Candidate* candidate) { |
62 scoped_ptr<Value> value(base::JSONReader::Read(candidate_str, true)); | 62 scoped_ptr<Value> value(base::JSONReader::Read(candidate_str, true)); |
63 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) { | 63 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) { |
64 return false; | 64 return false; |
65 } | 65 } |
66 | 66 |
(...skipping 27 matching lines...) Expand all Loading... |
94 candidate->set_protocol(protocol); | 94 candidate->set_protocol(protocol); |
95 candidate->set_username(username); | 95 candidate->set_username(username); |
96 candidate->set_password(password); | 96 candidate->set_password(password); |
97 candidate->set_preference(static_cast<float>(preference)); | 97 candidate->set_preference(static_cast<float>(preference)); |
98 candidate->set_generation(generation); | 98 candidate->set_generation(generation); |
99 | 99 |
100 return true; | 100 return true; |
101 } | 101 } |
102 | 102 |
103 } // namespace jingle_glue | 103 } // namespace jingle_glue |
OLD | NEW |