tryParseLogicalReplicationMessage function
Tries to check if the bytesList
is a LogicalReplicationMessage. If so,
LogicalReplicationMessage is returned, otherwise null
is returned.
Implementation
LogicalReplicationMessage? tryParseLogicalReplicationMessage(
Uint8List bytesList, Encoding encoding) {
// the first byte is the msg type
final firstByte = bytesList.first;
final msgType = LogicalReplicationMessageTypes.fromByte(firstByte);
// remaining bytes are the data
final bytes = bytesList.sublist(1);
switch (msgType) {
case LogicalReplicationMessageTypes.Begin:
return BeginMessage(bytes);
case LogicalReplicationMessageTypes.Commit:
return CommitMessage(bytes);
case LogicalReplicationMessageTypes.Origin:
return OriginMessage(bytes,encoding);
case LogicalReplicationMessageTypes.Relation:
return RelationMessage(bytes,encoding);
case LogicalReplicationMessageTypes.Type:
return TypeMessage(bytes,encoding);
case LogicalReplicationMessageTypes.Insert:
return InsertMessage(bytes, encoding);
case LogicalReplicationMessageTypes.Update:
return UpdateMessage(bytes,encoding);
case LogicalReplicationMessageTypes.Delete:
return DeleteMessage(bytes, encoding);
case LogicalReplicationMessageTypes.Truncate:
return TruncateMessage(bytes);
case LogicalReplicationMessageTypes.Unsupported:
default:
// note this needs the full set of bytes unlike other cases
return _tryParseJsonMessage(bytesList,encoding);
}
}