5#import "flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.h"
6#import "flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec_Internal.h"
10#pragma mark - Codec for basic message channel
15+ (instancetype)sharedInstance {
16 static id _sharedInstance = nil;
17 if (!_sharedInstance) {
21 return _sharedInstance;
30 NSAssert(
self,
@"Super init cannot be nil");
31 _readerWriter = readerWriter;
35- (NSData*)
encode:(
id)message {
39 NSMutableData*
data = [NSMutableData dataWithCapacity:32];
51 NSAssert(![reader hasMore],
@"Corrupted standard message");
56#pragma mark - Codec for method channel
61+ (instancetype)sharedInstance {
62 static id _sharedInstance = nil;
63 if (!_sharedInstance) {
67 return _sharedInstance;
76 NSAssert(
self,
@"Super init cannot be nil");
77 _readerWriter = readerWriter;
82 NSMutableData*
data = [NSMutableData dataWithCapacity:32];
89- (NSData*)encodeSuccessEnvelope:(
id)result {
90 NSMutableData*
data = [NSMutableData dataWithCapacity:32];
98 NSMutableData*
data = [NSMutableData dataWithCapacity:32];
111 NSAssert(![reader hasMore],
@"Corrupted standard method call");
112 NSAssert([value1 isKindOfClass:[NSString
class]],
@"Corrupted standard method call");
116- (
id)decodeEnvelope:(NSData*)envelope {
119 NSAssert(
flag <= 1,
@"Corrupted standard envelope");
124 NSAssert(![reader hasMore],
@"Corrupted standard envelope");
130 NSAssert(![reader hasMore],
@"Corrupted standard envelope");
131 NSAssert([
code isKindOfClass:[NSString
class]],
@"Invalid standard envelope");
132 NSAssert(
message == nil || [
message isKindOfClass:[NSString
class]],
133 @"Invalid standard envelope");
143#pragma mark - Standard serializable types
146+ (instancetype)typedDataWithBytes:(NSData*)data {
150+ (instancetype)typedDataWithInt32:(NSData*)data {
154+ (instancetype)typedDataWithInt64:(NSData*)data {
158+ (instancetype)typedDataWithFloat32:(NSData*)data {
162+ (instancetype)typedDataWithFloat64:(NSData*)data {
166+ (instancetype)typedDataWithData:(NSData*)data type:(FlutterStandardDataType)type {
170- (instancetype)initWithData:(NSData*)data type:(FlutterStandardDataType)type {
172 NSAssert(
data,
@"Data cannot be nil");
173 NSAssert(
data.length %
elementSize == 0,
@"Data must contain integral number of elements");
175 NSAssert(
self,
@"Super init cannot be nil");
183- (
BOOL)isEqual:(
id)object {
184 if (
self ==
object) {
192 [
self.data isEqual:other.data];
196 return [
self.data hash] ^
self.type;
200#pragma mark - Writer and reader of standard codec
203 NSMutableData* _data;
206- (instancetype)initWithData:(NSMutableData*)data {
208 NSAssert(
self,
@"Super init cannot be nil");
213- (void)writeByte:(UInt8)value {
217- (void)writeBytes:(const
void*)bytes length:(NSUInteger)length {
221- (void)writeData:(NSData*)data {
225- (void)writeSize:(UInt32)size {
229- (void)writeAlignment:(UInt8)alignment {
233- (void)writeUTF8:(NSString*)value {
235 (__bridge CFStringRef)
value);
239 if (
value == nil || (__bridge CFNullRef)
value == kCFNull) {
241 }
else if ([
value isKindOfClass:[NSNumber
class]]) {
243 }
else if ([
value isKindOfClass:[NSString
class]]) {
247 }
else if ([
value isKindOfClass:[NSData
class]]) {
249 }
else if ([
value isKindOfClass:[NSArray
class]]) {
251 }
else if ([
value isKindOfClass:[NSDictionary
class]]) {
265 FastWriteValueOfType(
info->writer,
info->data,
key);
280static void WriteValueOfType(CFTypeRef writer,
281 CFMutableDataRef
data,
289 CFNumberRef number = (CFNumberRef)
value;
292 NSLog(
@"Unsupported value: %@ of number type %ld",
value, CFNumberGetType(number));
293 NSCAssert(NO,
@"Unsupported value for standard codec");
298 CFStringRef
string = (CFStringRef)
value;
317 CFArrayRef array = (CFArrayRef)
value;
319 CFIndex
count = CFArrayGetCount(array);
321 for (CFIndex
i = 0;
i <
count; ++
i) {
322 FastWriteValueOfType(writer,
data, CFArrayGetValueAtIndex(array,
i));
327 CFDictionaryRef dict = (CFDictionaryRef)
value;
329 CFIndex
count = CFDictionaryGetCount(dict);
335 CFDictionaryApplyFunction(dict, WriteKeyValues, (
void*)&
info);
339 id objc_value = (__bridge
id)
value;
340 NSLog(
@"Unsupported value: %@ of type %@", objc_value, [objc_value
class]);
341 NSCAssert(NO,
@"Unsupported value for standard codec");
347- (void)writeValue:(
id)value {
349 WriteValueOfType((__bridge CFTypeRef)
self, (__bridge CFMutableDataRef)
self->_data,
type,
350 (__bridge CFTypeRef)
value);
359- (instancetype)initWithData:(NSData*)data {
361 NSAssert(
self,
@"Super init cannot be nil");
363 _range = NSMakeRange(0, 0);
368 return _range.location < _data.length;
371- (void)readBytes:(
void*)destination length:(NSUInteger)length {
373 (__bridge CFDataRef)_data);
384- (NSData*)readData:(NSUInteger)length {
386 NSData*
data = [_data subdataWithRange:_range];
391- (NSString*)readUTF8 {
393 (__bridge CFDataRef)_data);
396- (void)readAlignment:(UInt8)alignment {
400- (nullable
id)readValue {
401 return (__bridge
id)ReadValue((__bridge CFTypeRef)
self);
407 (__bridge CFDataRef)reader->_data);
413 unsigned long* location = &reader->_range.location;
414 CFDataRef
data = (__bridge CFDataRef)reader->_data;
420 UInt64
length = elementCount * elementSize;
421 NSRange range = NSMakeRange(*location,
length);
424 NSData* bytes = [(__bridge NSData*)data subdataWithRange:range];
429- (nullable
id)readValueOfType:(UInt8)type {
431 &
_range.location, (__bridge CFDataRef)_data,
type, ReadValue, ReadTypedDataOfType,
432 (__bridge CFTypeRef)
self);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
CFTypeRef FlutterStandardCodecHelperReadValueOfType(unsigned long *location, CFDataRef data, uint8_t type, CFTypeRef(*ReadValue)(CFTypeRef), CFTypeRef(*ReadTypedDataOfType)(FlutterStandardField, CFTypeRef), CFTypeRef user_data)
bool FlutterStandardCodecHelperWriteNumber(CFMutableDataRef data, CFNumberRef number)
void FlutterStandardCodecHelperWriteData(CFMutableDataRef data, CFDataRef value)
uint8_t FlutterStandardCodecHelperReadByte(unsigned long *location, CFDataRef data)
void FlutterStandardCodecHelperWriteSize(CFMutableDataRef data, uint32_t size)
CFStringRef FlutterStandardCodecHelperReadUTF8(unsigned long *location, CFDataRef data)
void FlutterStandardCodecHelperWriteBytes(CFMutableDataRef data, const void *bytes, unsigned long length)
void FlutterStandardCodecHelperWriteUTF8(CFMutableDataRef data, CFStringRef value)
void FlutterStandardCodecHelperWriteByte(CFMutableDataRef data, uint8_t value)
uint32_t FlutterStandardCodecHelperReadSize(unsigned long *location, CFDataRef data)
void FlutterStandardCodecHelperReadAlignment(unsigned long *location, uint8_t alignment)
void FlutterStandardCodecHelperWriteAlignment(CFMutableDataRef data, uint8_t alignment)
void FlutterStandardCodecHelperReadBytes(unsigned long *location, unsigned long length, void *destination, CFDataRef data)
@ FlutterStandardFieldMap
@ FlutterStandardFieldList
@ FlutterStandardFieldNil
@ FlutterStandardFieldString
FlutterStandardCodecObjcType
@ FlutterStandardCodecObjcTypeNSArray
@ FlutterStandardCodecObjcTypeFlutterStandardTypedData
@ FlutterStandardCodecObjcTypeNSData
@ FlutterStandardCodecObjcTypeNSString
@ FlutterStandardCodecObjcTypeNil
@ FlutterStandardCodecObjcTypeUnknown
@ FlutterStandardCodecObjcTypeNSDictionary
@ FlutterStandardCodecObjcTypeNSNumber
static void encode(uint8_t output[16], const uint32_t input[4])
static uint32_t hash(const SkShaderBase::GradientInfo &v)
FlutterSemanticsFlag flag
instancetype errorWithCode:message:details:(NSString *code,[message] NSString *_Nullable message,[details] id _Nullable details)
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
static CFTypeRef ReadValue(CFTypeRef user_data)
nullable id readValueOfType:(UInt8 type)
FlutterStandardDataType type
instancetype typedDataWithData:type:(NSData *data, [type] FlutterStandardDataType type)
void writeByte:(UInt8 value)
void writeValue:(id value)
static void FastWriteValueOfType(CFTypeRef writer, CFMutableDataRef data, CFTypeRef value)
static FlutterStandardCodecObjcType GetWriteType(id value)
static void WriteKeyValues(CFTypeRef key, CFTypeRef value, void *context)
FlutterStandardField FlutterStandardFieldForDataType(FlutterStandardDataType type)
FlutterStandardDataType FlutterStandardDataTypeForField(FlutterStandardField field)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
UInt8 elementSizeForFlutterStandardDataType(FlutterStandardDataType type)
static DecodeResult decode(std::string path)
std::shared_ptr< const fml::Mapping > data