Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(654)

Unified Diff: mojo/services/network/net_address_type_converters.cc

Issue 596383002: Mojo UDP API implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@udp_interface
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/services/network/net_address_type_converters.cc
diff --git a/mojo/services/network/net_address_type_converters.cc b/mojo/services/network/net_address_type_converters.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e482978c6c66cfbf00dc468fe8e8b49bc122e564
--- /dev/null
+++ b/mojo/services/network/net_address_type_converters.cc
@@ -0,0 +1,64 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/services/network/net_address_type_converters.h"
+
+#include "base/sys_byteorder.h"
+
+namespace mojo {
+
+// static
+net::IPEndPoint TypeConverter<net::IPEndPoint, NetAddressPtr>::Convert(
+ const NetAddressPtr& obj) {
+ if (!obj)
+ return net::IPEndPoint();
+
+ switch (obj->family) {
+ case NET_ADDRESS_FAMILY_IPV4:
+ if (!obj->ipv4)
+ break;
+
brettw 2014/09/29 18:24:25 I think it would be easier to follow if you moved
yzshen1 2014/09/29 21:51:11 Done.
+ return net::IPEndPoint(
+ obj->ipv4->addr.storage(), base::NetToHost16(obj->ipv4->port));
+ case NET_ADDRESS_FAMILY_IPV6:
+ if (!obj->ipv6)
+ break;
+
+ return net::IPEndPoint(
+ obj->ipv6->addr.storage(), base::NetToHost16(obj->ipv6->port));
+ default:
+ break;
+ }
+
+ return net::IPEndPoint();
+}
+
+// static
+NetAddressPtr TypeConverter<NetAddressPtr, net::IPEndPoint>::Convert(
+ const net::IPEndPoint& obj) {
+ NetAddressPtr net_address(NetAddress::New());
+
+ switch (obj.GetFamily()) {
+ case net::ADDRESS_FAMILY_IPV4:
+ net_address->family = NET_ADDRESS_FAMILY_IPV4;
+ net_address->ipv4 = NetAddressIPv4::New();
+ net_address->ipv4->port =
+ base::HostToNet16(static_cast<uint16>(obj.port()));
+ net_address->ipv4->addr = Array<uint8_t>::From(obj.address());
+ break;
+ case NET_ADDRESS_FAMILY_IPV6:
+ net_address->ipv6 = NetAddressIPv6::New();
+ net_address->family = NET_ADDRESS_FAMILY_IPV6;
+ net_address->ipv6->port =
+ base::HostToNet16(static_cast<uint16>(obj.port()));
+ net_address->ipv6->addr = Array<uint8_t>::From(obj.address());
+ break;
+ default:
+ break;
+ }
+
+ return net_address.Pass();
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698