writeValue method

bool writeValue(
  1. dynamic value
)

Serializes a JavaScript delegate object into the buffer.

@param value JavaScript delegate object

Implementation

bool writeValue(dynamic value) {
  if (value is String) {
    writeString(value);
  } else if (value is int) {
    writeInt(value);
  } else if (value is double) {
    writeDouble(value);
  } else if (value is bool) {
    if (value) {
      writeTag(SerializationTag.kTrue);
    } else {
      writeTag(SerializationTag.kFalse);
    }
  } else if (value == undefined) {
    writeTag(SerializationTag.kUndefined);
  } else if (value == nul) {
    writeTag(SerializationTag.kNull);
  } else if (value == hole) {
    writeTag(SerializationTag.kTheHole);
  } else {
    int? id = _objectMap[value];
    if (id != null) {
      writeTag(SerializationTag.kObjectReference);
      writer.putVarint(id);
    } else {
      return false;
    }
  }
  return true;
}