fromJson static method

Message? fromJson(
  1. Map<String, dynamic> json
)

Deserialize a message from a JSON string

Implementation

static Message? fromJson(Map<String, dynamic> json) {
  final type = json['type'] as int;
  if (type < 0 || type >= MessageType.values.length) {
    return null;
  }

  switch (MessageType.values[type]) {
    case MessageType.handshakeRequest:
      return HandshakeRequestMessage.fromJson(json);
    case MessageType.handshakeResponse:
      return HandshakeResponseMessage.fromJson(json);
    case MessageType.change:
      return ChangeMessage.fromJson(json);
    case MessageType.documentStatus:
      return DocumentStatusMessage.fromJson(json);
    case MessageType.documentStatusRequest:
      return DocumentStatusRequestMessage.fromJson(json);
    case MessageType.ping:
      return PingMessage.fromJson(json);
    case MessageType.pong:
      return PongMessage.fromJson(json);
    case MessageType.error:
      return ErrorMessage.fromJson(json);
  }
}