| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/pairing/proto_decoder.h" | 5 #include "components/pairing/proto_decoder.h" |
| 6 | 6 |
| 7 #include "components/pairing/pairing_api.pb.h" | 7 #include "components/pairing/pairing_api.pb.h" |
| 8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // Reset the message data. | 121 // Reset the message data. |
| 122 next_message_type_ = MESSAGE_NONE; | 122 next_message_type_ = MESSAGE_NONE; |
| 123 next_message_size_ = 0; | 123 next_message_size_ = 0; |
| 124 | 124 |
| 125 return true; | 125 return true; |
| 126 } | 126 } |
| 127 | 127 |
| 128 ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendHostStatus( | 128 ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendHostStatus( |
| 129 const pairing_api::HostStatus& message, int* size) { | 129 const pairing_api::HostStatus& message, int* size) { |
| 130 std::string serialized_proto; | 130 std::string serialized_proto; |
| 131 if (!message.SerializeToString(&serialized_proto)) { | 131 if (!message.SerializeToString(&serialized_proto)) |
| 132 NOTREACHED(); | 132 NOTREACHED(); |
| 133 } | |
| 134 | 133 |
| 135 return SendMessage(MESSAGE_HOST_STATUS, serialized_proto, size); | 134 return SendMessage(MESSAGE_HOST_STATUS, serialized_proto, size); |
| 136 } | 135 } |
| 137 | 136 |
| 137 ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendHostNetwork( |
| 138 const pairing_api::AddNetwork& message, |
| 139 int* size) { |
| 140 std::string serialized_proto; |
| 141 if (!message.SerializeToString(&serialized_proto)) |
| 142 NOTREACHED(); |
| 143 |
| 144 return SendMessage(MESSAGE_ADD_NETWORK, serialized_proto, size); |
| 145 } |
| 146 |
| 138 ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendConfigureHost( | 147 ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendConfigureHost( |
| 139 const pairing_api::ConfigureHost& message, int* size) { | 148 const pairing_api::ConfigureHost& message, int* size) { |
| 140 std::string serialized_proto; | 149 std::string serialized_proto; |
| 141 if (!message.SerializeToString(&serialized_proto)) { | 150 if (!message.SerializeToString(&serialized_proto)) |
| 142 NOTREACHED(); | 151 NOTREACHED(); |
| 143 } | |
| 144 | 152 |
| 145 return SendMessage(MESSAGE_CONFIGURE_HOST, serialized_proto, size); | 153 return SendMessage(MESSAGE_CONFIGURE_HOST, serialized_proto, size); |
| 146 } | 154 } |
| 147 | 155 |
| 148 ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendPairDevices( | 156 ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendPairDevices( |
| 149 const pairing_api::PairDevices& message, int* size) { | 157 const pairing_api::PairDevices& message, int* size) { |
| 150 std::string serialized_proto; | 158 std::string serialized_proto; |
| 151 if (!message.SerializeToString(&serialized_proto)) { | 159 if (!message.SerializeToString(&serialized_proto)) |
| 152 NOTREACHED(); | 160 NOTREACHED(); |
| 153 } | |
| 154 | 161 |
| 155 return SendMessage(MESSAGE_PAIR_DEVICES, serialized_proto, size); | 162 return SendMessage(MESSAGE_PAIR_DEVICES, serialized_proto, size); |
| 156 } | 163 } |
| 157 | 164 |
| 158 ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendCompleteSetup( | 165 ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendCompleteSetup( |
| 159 const pairing_api::CompleteSetup& message, int* size) { | 166 const pairing_api::CompleteSetup& message, int* size) { |
| 160 std::string serialized_proto; | 167 std::string serialized_proto; |
| 161 if (!message.SerializeToString(&serialized_proto)) { | 168 if (!message.SerializeToString(&serialized_proto)) |
| 162 NOTREACHED(); | 169 NOTREACHED(); |
| 163 } | |
| 164 | 170 |
| 165 return SendMessage(MESSAGE_COMPLETE_SETUP, serialized_proto, size); | 171 return SendMessage(MESSAGE_COMPLETE_SETUP, serialized_proto, size); |
| 166 } | 172 } |
| 167 | 173 |
| 168 ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendError( | 174 ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendError( |
| 169 const pairing_api::Error& message, int* size) { | 175 const pairing_api::Error& message, int* size) { |
| 170 std::string serialized_proto; | 176 std::string serialized_proto; |
| 171 if (!message.SerializeToString(&serialized_proto)) { | 177 if (!message.SerializeToString(&serialized_proto)) |
| 172 NOTREACHED(); | 178 NOTREACHED(); |
| 173 } | |
| 174 | 179 |
| 175 return SendMessage(MESSAGE_ERROR, serialized_proto, size); | 180 return SendMessage(MESSAGE_ERROR, serialized_proto, size); |
| 176 } | 181 } |
| 177 | 182 |
| 178 ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendMessage( | 183 ProtoDecoder::IOBufferRefPtr ProtoDecoder::SendMessage( |
| 179 uint8_t message_type, | 184 uint8_t message_type, |
| 180 const std::string& message, | 185 const std::string& message, |
| 181 int* size) { | 186 int* size) { |
| 182 uint16_t message_size = message.size(); | 187 uint16_t message_size = message.size(); |
| 183 | 188 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 199 memcpy(&io_buffer->data()[offset], &data, sizeof(data)); | 204 memcpy(&io_buffer->data()[offset], &data, sizeof(data)); |
| 200 offset += sizeof(data); | 205 offset += sizeof(data); |
| 201 | 206 |
| 202 // Write the actual message. | 207 // Write the actual message. |
| 203 memcpy(&io_buffer->data()[offset], message.data(), message.size()); | 208 memcpy(&io_buffer->data()[offset], message.data(), message.size()); |
| 204 | 209 |
| 205 return io_buffer; | 210 return io_buffer; |
| 206 } | 211 } |
| 207 | 212 |
| 208 } // namespace pairing_chromeos | 213 } // namespace pairing_chromeos |
| OLD | NEW |