fromJson static method

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

Decodes a sync message from json.

Returns null for type codes outside the sync protocol, so it can be chained with other decoders (like Message.fromJson).

Implementation

static Message? fromJson(Map<String, dynamic> json) {
  final type = json['type'] as int;
  if (type == MessageType.handshakeRequest.value) {
    return HandshakeRequestMessage.fromJson(json);
  }
  if (type == MessageType.handshakeResponse.value) {
    return HandshakeResponseMessage.fromJson(json);
  }
  if (type == MessageType.change.value) {
    return ChangeMessage.fromJson(json);
  }
  if (type == MessageType.changes.value) {
    return ChangesMessage.fromJson(json);
  }
  if (type == MessageType.documentStatus.value) {
    return DocumentStatusMessage.fromJson(json);
  }
  if (type == MessageType.documentStatusRequest.value) {
    return DocumentStatusRequestMessage.fromJson(json);
  }
  return null;
}