PgLsn type.
This commit is contained in:
@@ -24,6 +24,9 @@ pub mod types;
|
||||
/// A Postgres OID.
|
||||
pub type Oid = u32;
|
||||
|
||||
/// A Postgres Log Sequence Number (LSN).
|
||||
pub type Lsn = u64;
|
||||
|
||||
/// An enum indicating if a value is `NULL` or not.
|
||||
pub enum IsNull {
|
||||
/// The value is `NULL`.
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::io::Read;
|
||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
use std::str;
|
||||
|
||||
use crate::{write_nullable, FromUsize, IsNull, Oid};
|
||||
use crate::{write_nullable, FromUsize, IsNull, Lsn, Oid};
|
||||
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
@@ -142,6 +142,22 @@ pub fn int8_from_sql(mut buf: &[u8]) -> Result<i64, StdBox<dyn Error + Sync + Se
|
||||
Ok(v)
|
||||
}
|
||||
|
||||
/// Serializes a `PG_LSN` value.
|
||||
#[inline]
|
||||
pub fn lsn_to_sql(v: Lsn, buf: &mut BytesMut) {
|
||||
buf.put_u64(v);
|
||||
}
|
||||
|
||||
/// Deserializes a `PG_LSN` value.
|
||||
#[inline]
|
||||
pub fn lsn_from_sql(mut buf: &[u8]) -> Result<Lsn, StdBox<dyn Error + Sync + Send>> {
|
||||
let v = buf.read_u64::<BigEndian>()?;
|
||||
if !buf.is_empty() {
|
||||
return Err("invalid buffer size".into());
|
||||
}
|
||||
Ok(v)
|
||||
}
|
||||
|
||||
/// Serializes a `FLOAT4` value.
|
||||
#[inline]
|
||||
pub fn float4_to_sql(v: f32, buf: &mut BytesMut) {
|
||||
|
||||
Reference in New Issue
Block a user