use bytes::Bytes;
#[derive(Debug, Clone)]
pub enum ReplicationMessage {
Begin(BeginBody),
Commit(CommitBody),
Origin(OriginBody),
Relation(RelationBody),
Type(TypeBody),
Insert(InsertBody),
Update(UpdateBody),
Delete(DeleteBody),
Truncate(TruncateBody),
StreamStart(StreamStartBody),
StreamStop(StreamStopBody),
StreamCommit(StreamCommitBody),
StreamAbort(StreamAbortBody),
}
#[derive(Debug, Clone)]
pub struct BeginBody {
pub final_lsn: u64,
pub timestamp: i64,
pub xid: u32,
}
#[derive(Debug, Clone)]
pub struct CommitBody {
pub flags: u8,
pub commit_lsn: u64,
pub end_lsn: u64,
pub timestamp: i64,
}
#[derive(Debug, Clone)]
pub struct OriginBody {
pub commit_lsn: u64,
pub name: String,
}
#[derive(Debug, Clone)]
pub struct RelationBody {
pub id: u32,
pub namespace: String,
pub name: String,
pub replica_identity: u8,
pub columns: Vec<Column>,
}
#[derive(Debug, Clone)]
pub struct Column {
pub flags: u8,
pub name: String,
pub type_id: i32,
pub type_mode: i32,
}
#[derive(Debug, Clone)]
pub struct TypeBody {
pub id: u32,
pub namespace: String,
pub name: String,
}
#[derive(Debug, Clone)]
pub struct InsertBody {
pub relation_id: u32,
pub tuple: Tuple,
}
#[derive(Debug, Clone)]
pub struct UpdateBody {
pub relation_id: u32,
pub key_tuple: Option<Tuple>,
pub new_tuple: Tuple,
}
#[derive(Debug, Clone)]
pub struct DeleteBody {
pub relation_id: u32,
pub key_tuple: Option<Tuple>,
}
#[derive(Debug, Clone)]
pub struct TruncateBody {
pub relation_ids: Vec<u32>,
pub options: u8,
}
#[derive(Debug, Clone)]
pub struct Tuple(pub Vec<TupleData>);
#[derive(Debug, Clone)]
pub enum TupleData {
Null,
Toast,
Text(Bytes),
}
#[derive(Debug, Clone)]
pub struct StreamStartBody {
pub xid: u32,
pub first_segment: u8,
}
#[derive(Debug, Clone)]
pub struct StreamStopBody;
#[derive(Debug, Clone)]
pub struct StreamCommitBody {
pub xid: u32,
pub flags: u8,
pub commit_lsn: u64,
pub transaction_end_lsn: u64,
pub commit_time: i64,
}
#[derive(Debug, Clone)]
pub struct StreamAbortBody {
pub xid: u32,
pub sub_xid: u32,
}
#[derive(Debug, Clone)]
pub enum XLogData {
StandbyStatusUpdate {
wal_write_position: u64,
wal_flush_position: u64,
wal_apply_position: u64,
client_time: i64,
reply_requested: bool,
},
PrimaryKeepAlive {
wal_end: u64,
timestamp: i64,
reply_requested: bool,
},
XLogData {
wal_start: u64,
wal_end: u64,
timestamp: i64,
data: Bytes,
},
}