as<E> method

E as <E>()

Allow transformation back to popular data types For using the as() and asXX() methods, We're assuming it is safe to transform to utf8 Strings.

This method provides a common generic way of transforming the bytes to one the supported serialization formats. As an example: as() is same as asString() as is same as asMap() as<Map<String, dynamic>>() is same as asMap<String, dynamic>() as() is same as asList() as() is same as asInt()

Implementation

E as<E>(){
  assert(_isStream != null && !_isStream);

  if( E == String )
    return asString() as E;
  else if( E.toString().startsWith("Map<") )
    return asMap() as E;
  else if( E.toString().startsWith("List<") )
    return asList() as E;
  else if( E == int )
    return asInt() as E;
  else if( E == double )
    return asDouble() as E;
  else if( E == num )
    return asNumber() as E;
  else if( E == bool )
    return asBool() as E;

  throw "Unsupported return type. Deserialize to one of the supported formats";
}