tryParseLogicalReplicationMessage function
- @Deprecated('This method will be removed from public API. ' 'Please file a new issue on GitHub if you are using it.')
- PgByteDataReader reader,
- int length
Tries to check if the bytesList
is a LogicalReplicationMessage. If so,
LogicalReplicationMessage is returned, otherwise null
is returned.
Implementation
@Deprecated('This method will be removed from public API. '
'Please file a new issue on GitHub if you are using it.')
LogicalReplicationMessage? tryParseLogicalReplicationMessage(
PgByteDataReader reader, int length) {
// the first byte is the msg type
final firstByte = reader.readUint8();
final msgType = LogicalReplicationMessageTypes.fromByte(firstByte);
switch (msgType) {
case LogicalReplicationMessageTypes.begin:
return BeginMessage._parse(reader);
case LogicalReplicationMessageTypes.commit:
return CommitMessage._parse(reader);
case LogicalReplicationMessageTypes.origin:
return OriginMessage._parse(reader);
case LogicalReplicationMessageTypes.relation:
return RelationMessage._parse(reader);
case LogicalReplicationMessageTypes.type:
return TypeMessage._parse(reader);
case LogicalReplicationMessageTypes.insert:
return InsertMessage._syncParse(reader);
case LogicalReplicationMessageTypes.update:
return UpdateMessage._syncParse(reader);
case LogicalReplicationMessageTypes.delete:
return DeleteMessage._syncParse(reader);
case LogicalReplicationMessageTypes.truncate:
return TruncateMessage._parse(reader);
case LogicalReplicationMessageTypes.unsupported:
// wal2json messages starts with `{` as the first byte
if (firstByte == '{'.codeUnits.single) {
// note this needs the full set of bytes unlike other cases
final bb = BytesBuffer();
bb.addByte(firstByte);
bb.add(reader.read(length - 1));
try {
return JsonMessage(reader.encoding.decode(bb.toBytes()));
} catch (_) {
// ignore
}
}
return null;
}
}