Flutter Engine
FlutterStandardReader Class Reference

#import <FlutterCodecs.h>

Inheritance diagram for FlutterStandardReader:

Instance Methods

(instancetype) - initWithData:
 
(BOOL) - hasMore
 
(UInt8) - readByte
 
(void) - readBytes:length:
 
(NSData *) - readData:
 
(UInt32) - readSize
 
(void) - readAlignment:
 
(NSString *) - readUTF8
 
(nullable id- readValue
 
(nullable id- readValueOfType:
 

Detailed Description

A reader of the Flutter standard binary encoding.

See FlutterStandardMessageCodec for details on the encoding.

The encoding is extensible via subclasses overriding readValueOfType.

Definition at line 132 of file FlutterCodecs.h.

Method Documentation

◆ hasMore()

- (BOOL) hasMore

Returns YES when the reader hasn't reached the end of its data.

Definition at line 353 of file FlutterStandardCodec.mm.

References _range.

353  {
354  return _range.location < _data.length;
355 }
NSRange _range

◆ initWithData:()

- (instancetype) initWithData: (NSData*)  data

Create a new FlutterStandardReader who reads from data.

Definition at line 340 of file FlutterStandardCodec.mm.

References _range.

340  :(NSData*)data {
341  self = [super init];
342  NSAssert(self, @"Super init cannot be nil");
343  _data = [data retain];
344  _range = NSMakeRange(0, 0);
345  return self;
346 }
NSRange _range

◆ readAlignment:()

- (void) readAlignment: (UInt8)  alignment

Advances the read position until it is aligned with alignment.

Definition at line 396 of file FlutterStandardCodec.mm.

References _range, flutter::elementSizeForFlutterStandardDataType(), readAlignment:, readData:, and readSize.

Referenced by readAlignment:, and readValueOfType:.

396  :(UInt8)alignment {
397  UInt8 mod = _range.location % alignment;
398  if (mod) {
399  _range.location += (alignment - mod);
400  }
401 }
NSRange _range

◆ readByte()

- (UInt8) readByte

Reads a byte value and increments the position.

Definition at line 363 of file FlutterStandardCodec.mm.

References readBytes:length:, and value.

Referenced by FlutterStandardMethodCodec::codecWithReaderWriter:, readSize, and readValue.

363  {
364  UInt8 value;
365  [self readBytes:&value length:1];
366  return value;
367 }
uint8_t value

◆ readBytes:length:()

- (void) readBytes: (void*)  destination
length: (NSUInteger)  length 

Reads a sequence of byte values of length and increments the position.

Definition at line 357 of file FlutterStandardCodec.mm.

References _range, and length.

Referenced by readByte, readSize, and readValueOfType:.

357  :(void*)destination length:(NSUInteger)length {
358  _range.length = length;
359  [_data getBytes:destination range:_range];
360  _range.location += _range.length;
361 }
NSRange _range
size_t length

◆ readData:()

- (NSData *) readData: (NSUInteger)  length

Reads a sequence of byte values of length and increments the position.

Definition at line 384 of file FlutterStandardCodec.mm.

References _range, and length.

Referenced by readAlignment:, and readUTF8.

384  :(NSUInteger)length {
385  _range.length = length;
386  NSData* data = [_data subdataWithRange:_range];
387  _range.location += _range.length;
388  return data;
389 }
NSRange _range
size_t length

◆ readSize()

- (UInt32) readSize

Reads a 32-bit unsigned integer representing a collection size and increments the position.

Definition at line 369 of file FlutterStandardCodec.mm.

References readByte, readBytes:length:, and value.

Referenced by readAlignment:, readUTF8, and readValueOfType:.

369  {
370  UInt8 byte = [self readByte];
371  if (byte < 254) {
372  return (UInt32)byte;
373  } else if (byte == 254) {
374  UInt16 value;
375  [self readBytes:&value length:2];
376  return value;
377  } else {
378  UInt32 value;
379  [self readBytes:&value length:4];
380  return value;
381  }
382 }
uint8_t value

◆ readUTF8()

- (NSString *) readUTF8

Read a null terminated string encoded with UTF-8/

Definition at line 391 of file FlutterStandardCodec.mm.

References readData:, and readSize.

Referenced by readValueOfType:.

391  {
392  NSData* bytes = [self readData:[self readSize]];
393  return [[[NSString alloc] initWithData:bytes encoding:NSUTF8StringEncoding] autorelease];
394 }

◆ readValue()

- (nullable id) readValue

Reads a byte for FlutterStandardField the decodes a value matching that type.

See also: -[FlutterStandardWriter writeValue]

Definition at line 411 of file FlutterStandardCodec.mm.

References readByte, and readValueOfType:.

Referenced by FlutterStandardMethodCodec::codecWithReaderWriter:, FlutterStandardMessageCodec::codecWithReaderWriter:, and readValueOfType:.

411  {
412  return [self readValueOfType:[self readByte]];
413 }

◆ readValueOfType:()

- (nullable id) readValueOfType: (UInt8)  type

Decodes a value matching the type specified.

See also:

Definition at line 415 of file FlutterStandardCodec.mm.

References length, readAlignment:, readBytes:length:, readSize, readUTF8, readValue, fml::size(), and value.

Referenced by readValue.

415  :(UInt8)type {
416  FlutterStandardField field = (FlutterStandardField)type;
417  switch (field) {
418  case FlutterStandardFieldNil:
419  return nil;
420  case FlutterStandardFieldTrue:
421  return @YES;
422  case FlutterStandardFieldFalse:
423  return @NO;
424  case FlutterStandardFieldInt32: {
425  SInt32 value;
426  [self readBytes:&value length:4];
427  return @(value);
428  }
429  case FlutterStandardFieldInt64: {
430  SInt64 value;
431  [self readBytes:&value length:8];
432  return @(value);
433  }
434  case FlutterStandardFieldFloat64: {
435  Float64 value;
436  [self readAlignment:8];
437  [self readBytes:&value length:8];
438  return [NSNumber numberWithDouble:value];
439  }
440  case FlutterStandardFieldIntHex:
441  case FlutterStandardFieldString:
442  return [self readUTF8];
443  case FlutterStandardFieldUInt8Data:
444  case FlutterStandardFieldInt32Data:
445  case FlutterStandardFieldInt64Data:
446  case FlutterStandardFieldFloat64Data:
447  return [self readTypedDataOfType:FlutterStandardDataTypeForField(field)];
448  case FlutterStandardFieldList: {
449  UInt32 length = [self readSize];
450  NSMutableArray* array = [NSMutableArray arrayWithCapacity:length];
451  for (UInt32 i = 0; i < length; i++) {
452  id value = [self readValue];
453  [array addObject:(value == nil ? [NSNull null] : value)];
454  }
455  return array;
456  }
457  case FlutterStandardFieldMap: {
458  UInt32 size = [self readSize];
459  NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:size];
460  for (UInt32 i = 0; i < size; i++) {
461  id key = [self readValue];
462  id val = [self readValue];
463  [dict setObject:(val == nil ? [NSNull null] : val)
464  forKey:(key == nil ? [NSNull null] : key)];
465  }
466  return dict;
467  }
468  default:
469  NSAssert(NO, @"Corrupted standard message");
470  }
471 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
uint8_t value
size_t length

The documentation for this class was generated from the following files: