5
5
#include " flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.h"
6
6
#include < stdint.h>
7
7
8
+ #include < vector>
9
+
10
+ #include " flutter/fml/logging.h"
11
+
8
12
void FlutterStandardCodecHelperReadAlignment (unsigned long * location,
9
13
uint8_t alignment) {
10
14
uint8_t mod = *location % alignment;
@@ -25,7 +29,7 @@ void FlutterStandardCodecHelperReadBytes(unsigned long* location,
25
29
void * destination,
26
30
CFDataRef data) {
27
31
CFRange range = CFRangeMake (*location, length);
28
- CFDataGetBytes (data , range , destination );
32
+ CFDataGetBytes (data, range, static_cast < UInt8 *>( destination) );
29
33
*location += length;
30
34
}
31
35
@@ -59,7 +63,7 @@ static CFDataRef ReadDataNoCopy(unsigned long* location,
59
63
kCFAllocatorDefault , CFDataGetBytePtr (data) + *location, length,
60
64
kCFAllocatorNull );
61
65
*location += length;
62
- return CFAutorelease (result );
66
+ return static_cast < CFDataRef >( CFAutorelease (result) );
63
67
}
64
68
65
69
CFStringRef FlutterStandardCodecHelperReadUTF8 (unsigned long * location,
@@ -68,7 +72,7 @@ CFStringRef FlutterStandardCodecHelperReadUTF8(unsigned long* location,
68
72
CFDataRef bytes = ReadDataNoCopy (location, size, data);
69
73
CFStringRef result = CFStringCreateFromExternalRepresentation (
70
74
kCFAllocatorDefault , bytes, kCFStringEncodingUTF8 );
71
- return CFAutorelease (result );
75
+ return static_cast < CFStringRef >( CFAutorelease (result) );
72
76
}
73
77
74
78
// Peeks ahead to see if we are reading a standard type. If so, recurse
@@ -161,7 +165,7 @@ CFTypeRef FlutterStandardCodecHelperReadValueOfType(
161
165
}
162
166
default :
163
167
// Malformed message.
164
- assert (false);
168
+ FML_DCHECK (false );
165
169
}
166
170
}
167
171
@@ -172,7 +176,7 @@ void FlutterStandardCodecHelperWriteByte(CFMutableDataRef data, uint8_t value) {
172
176
void FlutterStandardCodecHelperWriteBytes (CFMutableDataRef data,
173
177
const void * bytes,
174
178
unsigned long length) {
175
- CFDataAppendBytes (data , bytes , length );
179
+ CFDataAppendBytes (data, static_cast < const UInt8 *>( bytes) , length);
176
180
}
177
181
178
182
void FlutterStandardCodecHelperWriteSize (CFMutableDataRef data, uint32_t size) {
@@ -210,12 +214,12 @@ void FlutterStandardCodecHelperWriteUTF8(CFMutableDataRef data,
210
214
CFIndex used_length = 0 ;
211
215
// UTF16 length times 3 will fit all UTF8.
212
216
CFIndex buffer_length = length * 3 ;
213
- UInt8 * buffer = (UInt8 * )malloc (buffer_length * sizeof (UInt8 ));
217
+ std::vector<UInt8 > buffer;
218
+ buffer.reserve (buffer_length);
214
219
CFStringGetBytes (value, CFRangeMake (0 , length), kCFStringEncodingUTF8 , 0 ,
215
- false, buffer , buffer_length , & used_length );
220
+ false , buffer. data () , buffer_length, &used_length);
216
221
FlutterStandardCodecHelperWriteSize (data, used_length);
217
- FlutterStandardCodecHelperWriteBytes (data , buffer , used_length );
218
- free (buffer );
222
+ FlutterStandardCodecHelperWriteBytes (data, buffer.data (), used_length);
219
223
}
220
224
}
221
225
0 commit comments