encode method

void encode(
  1. dynamic d
)

Implementation

void encode(dynamic d) {
  if (d == null) return _writer.writeUint8(0xc0);
  if (d is bool) return _writer.writeUint8(d == true ? 0xc3 : 0xc2);
  if (d is int) return d >= 0 ? _writePositiveInt(d) : _writeNegativeInt(d);
  if (d is Float) return _writeFloat(d);
  if (d is double) return _writeDouble(d);
  if (d is String) return _writeString(d);
  if (d is Uint8List) return _writeBinary(d);
  if (d is Iterable) return _writeIterable(d);
  if (d is ByteData)
    return _writeBinary(
        d.buffer.asUint8List(d.offsetInBytes, d.lengthInBytes));
  if (d is Map) return _writeMap(d);
  if (_extEncoder != null && _writeExt(d)) {
    return;
  }
  throw FormatError("Don't know how to serialize $d");
}