1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "chre/apps/wifi_offload/flatbuffers_serialization.h"
18 #include "chre/apps/wifi_offload/wifi_offload.h"
19 
20 namespace wifi_offload {
21 namespace fbs {
22 
Serialize(const wifi_offload::ScanStats & stats,uint8_t * buffer,size_t buffer_len)23 size_t Serialize(const wifi_offload::ScanStats &stats, uint8_t *buffer,
24                  size_t buffer_len) {
25   return Serialize(stats, buffer, buffer_len, "ScanStats");
26 }
27 
Deserialize(const uint8_t * buffer,size_t buffer_len,wifi_offload::ScanStats * stats)28 bool Deserialize(const uint8_t *buffer, size_t buffer_len,
29                  wifi_offload::ScanStats *stats) {
30   return Deserialize<wifi_offload::ScanStats>(buffer, buffer_len, stats,
31                                               "ScanStats");
32 }
33 
Serialize(const wifi_offload::ScanConfig & config,uint8_t * buffer,size_t buffer_len)34 size_t Serialize(const wifi_offload::ScanConfig &config, uint8_t *buffer,
35                  size_t buffer_len) {
36   return Serialize(config, buffer, buffer_len, "ScanConfig");
37 }
38 
Deserialize(const uint8_t * buffer,size_t buffer_len,wifi_offload::ScanConfig * config)39 bool Deserialize(const uint8_t *buffer, size_t buffer_len,
40                  wifi_offload::ScanConfig *config) {
41   return Deserialize<wifi_offload::ScanConfig>(buffer, buffer_len, config,
42                                                "ScanConfig");
43 }
44 
Serialize(const wifi_offload::Vector<wifi_offload::ScanResult> & results,uint8_t * buffer,size_t buffer_len)45 size_t Serialize(const wifi_offload::Vector<wifi_offload::ScanResult> &results,
46                  uint8_t *buffer, size_t buffer_len) {
47   wifi_offload::ScanResultMessage msg;
48   msg.SetScanResults(results);
49   return Serialize(msg, buffer, buffer_len, "ScanResults");
50 }
51 
Deserialize(const uint8_t * buffer,size_t buffer_len,wifi_offload::Vector<wifi_offload::ScanResult> * results)52 bool Deserialize(const uint8_t *buffer, size_t buffer_len,
53                  wifi_offload::Vector<wifi_offload::ScanResult> *results) {
54   wifi_offload::ScanResultMessage msg;
55   if (Deserialize<wifi_offload::ScanResultMessage>(buffer, buffer_len, &msg,
56                                                    "ScanResults")) {
57     msg.GetScanResults(results);
58     return true;
59   } else {
60     return false;
61   }
62 }
63 
64 }  // namespace fbs
65 }  // namespace wifi_offload
66