10 #include "flutter/fml/logging.h"
20 uint8_t mod = *location % alignment;
22 *location += (alignment - mod);
26 static uint8_t
PeekByte(
unsigned long location, CFDataRef data) {
28 CFRange range = CFRangeMake(location, 1);
29 CFDataGetBytes(data, range, &result);
37 CFRange range = CFRangeMake(*location, length);
38 CFDataGetBytes(data, range,
static_cast<UInt8*
>(destination));
53 return (uint32_t)byte;
54 }
else if (
byte == 254) {
68 CFDataRef result = CFDataCreateWithBytesNoCopy(
69 kCFAllocatorDefault, CFDataGetBytePtr(data) + *location, length,
72 return static_cast<CFDataRef
>(CFAutorelease(result));
79 CFStringRef result = CFStringCreateFromExternalRepresentation(
80 kCFAllocatorDefault, bytes, kCFStringEncodingUTF8);
81 return static_cast<CFStringRef
>(CFAutorelease(result));
88 unsigned long* location,
90 CFTypeRef (*ReadValue)(CFTypeRef),
93 uint8_t type =
PeekByte(*location, data);
97 location, data, type, ReadValue, ReadTypedDataOfType,
user_data);
104 unsigned long* location,
107 CFTypeRef (*ReadValue)(CFTypeRef),
115 return kCFBooleanTrue;
117 return kCFBooleanFalse;
121 return CFAutorelease(
122 CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value));
127 return CFAutorelease(
128 CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &value));
134 return CFAutorelease(
135 CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &value));
145 return ReadTypedDataOfType(field,
user_data);
148 CFMutableArrayRef array = CFArrayCreateMutable(
149 kCFAllocatorDefault, length, &kCFTypeArrayCallBacks);
150 for (UInt32 i = 0; i < length; i++) {
153 CFArrayAppendValue(array, (value == nil ? kCFNull : value));
155 return CFAutorelease(array);
159 CFMutableDictionaryRef dict = CFDictionaryCreateMutable(
160 kCFAllocatorDefault, size, &kCFTypeDictionaryKeyCallBacks,
161 &kCFTypeDictionaryValueCallBacks);
162 for (UInt32 i = 0; i < size; i++) {
167 CFDictionaryAddValue(dict, (key == nil ? kCFNull : key),
168 (val == nil ? kCFNull : val));
170 return CFAutorelease(dict);
179 CFDataAppendBytes(data, &value, 1);
184 unsigned long length) {
185 CFDataAppendBytes(data,
static_cast<const UInt8*
>(bytes), length);
191 }
else if (size <= 0xffff) {
193 UInt16 value = (UInt16)size;
203 uint8_t mod = CFDataGetLength(data) % alignment;
205 for (
int i = 0; i < (alignment - mod); i++) {
213 const char* utf8 = CFStringGetCStringPtr(value, kCFStringEncodingUTF8);
215 size_t length = strlen(utf8);
219 CFIndex length = CFStringGetLength(value);
220 CFIndex used_length = 0;
222 CFIndex buffer_length = length * 3;
223 std::vector<UInt8> buffer;
224 buffer.resize(buffer_length);
225 CFStringGetBytes(value, CFRangeMake(0, length), kCFStringEncodingUTF8, 0,
226 false, buffer.data(), buffer_length, &used_length);
234 const UInt8* bytes = CFDataGetBytePtr(value);
235 CFIndex length = CFDataGetLength(value);
240 CFNumberRef number) {
241 bool success =
false;
242 if (CFGetTypeID(number) == CFBooleanGetTypeID()) {
243 bool b = CFBooleanGetValue((CFBooleanRef)number);
247 }
else if (CFNumberIsFloatType(number)) {
249 success = CFNumberGetValue(number, kCFNumberFloat64Type, &f);
255 }
else if (CFNumberGetByteSize(number) <= 4) {
257 success = CFNumberGetValue(number, kCFNumberSInt32Type, &n);
262 }
else if (CFNumberGetByteSize(number) <= 8) {
264 success = CFNumberGetValue(number, kCFNumberSInt64Type, &n);