1 |
efrain |
1 |
/*
|
|
|
2 |
* Copyright 2019 Google
|
|
|
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 |
#import <Foundation/Foundation.h>
|
|
|
18 |
|
|
|
19 |
#import "GoogleDataTransport/GDTCORLibrary/Internal/GDTCORReachability.h"
|
|
|
20 |
#import "GoogleDataTransport/GDTCORLibrary/Public/GoogleDataTransport/GDTCOREvent.h"
|
|
|
21 |
|
|
|
22 |
#import "GoogleDataTransport/GDTCCTLibrary/Protogen/nanopb/cct.nanopb.h"
|
|
|
23 |
|
|
|
24 |
NS_ASSUME_NONNULL_BEGIN
|
|
|
25 |
|
|
|
26 |
#pragma mark - General purpose encoders
|
|
|
27 |
|
|
|
28 |
/** Converts an NSString* to a pb_bytes_array_t*.
|
|
|
29 |
*
|
|
|
30 |
* @note calloc is called in this method. Ensure that pb_release is called on this or the parent.
|
|
|
31 |
*
|
|
|
32 |
* @param string The string to convert.
|
|
|
33 |
* @return A newly allocated array of bytes representing the UTF8 encoding of the string.
|
|
|
34 |
*/
|
|
|
35 |
pb_bytes_array_t *GDTCCTEncodeString(NSString *string);
|
|
|
36 |
|
|
|
37 |
/** Converts an NSData to a pb_bytes_array_t*.
|
|
|
38 |
*
|
|
|
39 |
* @note calloc is called in this method. Ensure that pb_release is called on this or the parent.
|
|
|
40 |
*
|
|
|
41 |
* @param data The data to convert.
|
|
|
42 |
* @return A newly allocated array of bytes with [data bytes] copied into it.
|
|
|
43 |
*/
|
|
|
44 |
pb_bytes_array_t *GDTCCTEncodeData(NSData *data);
|
|
|
45 |
|
|
|
46 |
#pragma mark - CCT object constructors
|
|
|
47 |
|
|
|
48 |
/** Encodes a batched log request.
|
|
|
49 |
*
|
|
|
50 |
* @note Ensure that pb_release is called on the batchedLogRequest param.
|
|
|
51 |
*
|
|
|
52 |
* @param batchedLogRequest A pointer to the log batch to encode to bytes.
|
|
|
53 |
* @return An NSData object representing the bytes of the log request batch.
|
|
|
54 |
*/
|
|
|
55 |
FOUNDATION_EXPORT
|
|
|
56 |
NSData *GDTCCTEncodeBatchedLogRequest(gdt_cct_BatchedLogRequest *batchedLogRequest);
|
|
|
57 |
|
|
|
58 |
/** Constructs a gdt_cct_BatchedLogRequest given sets of events segemented by mapping ID.
|
|
|
59 |
*
|
|
|
60 |
* @note calloc is called in this method. Ensure that pb_release is called on this or the parent.
|
|
|
61 |
*
|
|
|
62 |
* @param logMappingIDToLogSet A map of mapping IDs to sets of events to convert into a batch.
|
|
|
63 |
* @return A newly created gdt_cct_BatchedLogRequest.
|
|
|
64 |
*/
|
|
|
65 |
FOUNDATION_EXPORT
|
|
|
66 |
gdt_cct_BatchedLogRequest GDTCCTConstructBatchedLogRequest(
|
|
|
67 |
NSDictionary<NSString *, NSSet<GDTCOREvent *> *> *logMappingIDToLogSet);
|
|
|
68 |
|
|
|
69 |
/** Constructs a log request given a log source and a set of events.
|
|
|
70 |
*
|
|
|
71 |
* @note calloc is called in this method. Ensure that pb_release is called on this or the parent.
|
|
|
72 |
* @param logSource The CCT log source to put into the log request.
|
|
|
73 |
* @param logSet The set of events to send in this log request.
|
|
|
74 |
*/
|
|
|
75 |
FOUNDATION_EXPORT
|
|
|
76 |
gdt_cct_LogRequest GDTCCTConstructLogRequest(int32_t logSource, NSSet<GDTCOREvent *> *logSet);
|
|
|
77 |
|
|
|
78 |
/** Constructs a gdt_cct_LogEvent given a GDTCOREvent*.
|
|
|
79 |
*
|
|
|
80 |
* @param event The GDTCOREvent to convert.
|
|
|
81 |
* @return The new gdt_cct_LogEvent object.
|
|
|
82 |
*/
|
|
|
83 |
FOUNDATION_EXPORT
|
|
|
84 |
gdt_cct_LogEvent GDTCCTConstructLogEvent(GDTCOREvent *event);
|
|
|
85 |
|
|
|
86 |
/** Constructs a gdt_cct_ClientInfo representing the client device.
|
|
|
87 |
*
|
|
|
88 |
* @return The new gdt_cct_ClientInfo object.
|
|
|
89 |
*/
|
|
|
90 |
FOUNDATION_EXPORT
|
|
|
91 |
gdt_cct_ClientInfo GDTCCTConstructClientInfo(void);
|
|
|
92 |
|
|
|
93 |
/** Constructs a gdt_cct_IosClientInfo representing the client device.
|
|
|
94 |
*
|
|
|
95 |
* @return The new gdt_cct_IosClientInfo object.
|
|
|
96 |
*/
|
|
|
97 |
FOUNDATION_EXPORT
|
|
|
98 |
gdt_cct_IosClientInfo GDTCCTConstructiOSClientInfo(void);
|
|
|
99 |
|
|
|
100 |
/** Constructs the data of a gdt_cct_NetworkConnectionInfo representing the client nework connection
|
|
|
101 |
* information.
|
|
|
102 |
*
|
|
|
103 |
* @return The data of a gdt_cct_NetworkConnectionInfo object.
|
|
|
104 |
*/
|
|
|
105 |
FOUNDATION_EXPORT
|
|
|
106 |
NSData *GDTCCTConstructNetworkConnectionInfoData(void);
|
|
|
107 |
|
|
|
108 |
/** Return a gdt_cct_NetworkConnectionInfo_MobileSubtype representing the client
|
|
|
109 |
*
|
|
|
110 |
* @return The gdt_cct_NetworkConnectionInfo_MobileSubtype.
|
|
|
111 |
*/
|
|
|
112 |
FOUNDATION_EXPORT
|
|
|
113 |
gdt_cct_NetworkConnectionInfo_MobileSubtype GDTCCTNetworkConnectionInfoNetworkMobileSubtype(void);
|
|
|
114 |
|
|
|
115 |
#pragma mark - CCT object decoders
|
|
|
116 |
|
|
|
117 |
/** Decodes a gdt_cct_LogResponse given proto bytes.
|
|
|
118 |
*
|
|
|
119 |
* @note calloc is called in this method. Ensure that pb_release is called on the return value.
|
|
|
120 |
*
|
|
|
121 |
* @param data The proto bytes of the gdt_cct_LogResponse.
|
|
|
122 |
* @param error An error that will be populated if something went wrong during decoding.
|
|
|
123 |
* @return A newly allocated gdt_cct_LogResponse from the data, if the bytes decoded properly.
|
|
|
124 |
*/
|
|
|
125 |
FOUNDATION_EXPORT
|
|
|
126 |
gdt_cct_LogResponse GDTCCTDecodeLogResponse(NSData *data, NSError **error);
|
|
|
127 |
|
|
|
128 |
NS_ASSUME_NONNULL_END
|