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 357 of file FlutterStandardCodec.mm.

References _range.

357  {
358  return _range.location < _data.length;
359 }
NSRange _range

◆ initWithData:()

- (instancetype) initWithData: (NSData*)  data

Create a new FlutterStandardReader who reads from data.

Definition at line 344 of file FlutterStandardCodec.mm.

References _range.

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

◆ readAlignment:()

- (void) readAlignment: (UInt8)  alignment

Advances the read position until it is aligned with alignment.

Definition at line 400 of file FlutterStandardCodec.mm.

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

Referenced by readAlignment:, and readValueOfType:.

400  :(UInt8)alignment {
401  UInt8 mod = _range.location % alignment;
402  if (mod) {
403  _range.location += (alignment - mod);
404  }
405 }
NSRange _range

◆ readByte()

- (UInt8) readByte

Reads a byte value and increments the position.

Definition at line 367 of file FlutterStandardCodec.mm.

References readBytes:length:, and value.

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

367  {
368  UInt8 value;
369  [self readBytes:&value length:1];
370  return value;
371 }
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 361 of file FlutterStandardCodec.mm.

References _range, and length.

Referenced by readByte, readSize, and readValueOfType:.

361  :(void*)destination length:(NSUInteger)length {
362  _range.length = length;
363  [_data getBytes:destination range:_range];
364  _range.location += _range.length;
365 }
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 388 of file FlutterStandardCodec.mm.

References _range, and length.

Referenced by readAlignment:, and readUTF8.

388  :(NSUInteger)length {
389  _range.length = length;
390  NSData* data = [_data subdataWithRange:_range];
391  _range.location += _range.length;
392  return data;
393 }
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 373 of file FlutterStandardCodec.mm.

References readByte, readBytes:length:, and value.

Referenced by readAlignment:, readUTF8, and readValueOfType:.

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

◆ readUTF8()

- (NSString *) readUTF8

Read a null terminated string encoded with UTF-8/

Definition at line 395 of file FlutterStandardCodec.mm.

References readData:, and readSize.

Referenced by readValueOfType:.

395  {
396  NSData* bytes = [self readData:[self readSize]];
397  return [[[NSString alloc] initWithData:bytes encoding:NSUTF8StringEncoding] autorelease];
398 }

◆ readValue()

- (nullable id) readValue

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

See also: -[FlutterStandardWriter writeValue]

Definition at line 415 of file FlutterStandardCodec.mm.

References readByte, and readValueOfType:.

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

415  {
416  return [self readValueOfType:[self readByte]];
417 }

◆ readValueOfType:()

- (nullable id) readValueOfType: (UInt8)  type

Decodes a value matching the type specified.

See also:

Definition at line 419 of file FlutterStandardCodec.mm.

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

Referenced by readValue.

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