From 14bce9f885ecfb4a0309a7aa398db033f1cc542e Mon Sep 17 00:00:00 2001 From: Tobias Deiminger Date: Tue, 16 Apr 2024 22:06:31 +0200 Subject: Add BufferId as Rust type Up to now it was represented as i32. If we introduce a newtype for it, we can handle it idiomatically as dedicated Variant::BufferId variant (instead of having it mashed into Variant::UserType). --- src/primitive/bufferid.rs | 37 +++++++++++++++++++++++++++++++++++++ src/primitive/mod.rs | 2 ++ 2 files changed, 39 insertions(+) create mode 100644 src/primitive/bufferid.rs diff --git a/src/primitive/bufferid.rs b/src/primitive/bufferid.rs new file mode 100644 index 0000000..6ee2447 --- /dev/null +++ b/src/primitive/bufferid.rs @@ -0,0 +1,37 @@ +#[derive(Copy, Clone, Debug, std::cmp::PartialEq)] +pub struct BufferId(pub i32); + +use crate::{deserialize::*, error::ProtocolError, serialize::*}; + +impl Serialize for BufferId { + fn serialize(&self) -> Result, ProtocolError> { + self.0.serialize() + } +} + +impl Deserialize for BufferId { + fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> { + let (size, value) = i32::parse(b)?; + return Ok((size, BufferId(value))); + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + pub fn bufferid_parse_test() { + let test_bytes: &[u8] = &[0, 0, 0, 1]; + let (len, res) = BufferId::parse(test_bytes).unwrap(); + assert_eq!(len, test_bytes.len()); + assert_eq!(res, BufferId(1)); + } + + #[test] + pub fn bufferid_serialize_test() { + let res = BufferId(1).serialize().unwrap(); + let expected_bytes: &[u8] = &[0, 0, 0, 1]; + assert_eq!(res, expected_bytes); + } +} diff --git a/src/primitive/mod.rs b/src/primitive/mod.rs index dbc4a58..67bb2ac 100644 --- a/src/primitive/mod.rs +++ b/src/primitive/mod.rs @@ -1,3 +1,4 @@ +mod bufferid; mod bufferinfo; mod datetime; mod message; @@ -10,6 +11,7 @@ mod variant; mod variantlist; mod variantmap; +pub use bufferid::*; pub use bufferinfo::*; pub use datetime::*; pub use message::*; -- cgit v1.2.3 a href='/catinator.git/diff/deploy/vendor/github.com/jsonnet-libs/k8s-alpha/1.19/_gen/core/v1/secretProjection.libsonnet?h=1.7.1&follow=1'>diff
Commit message (Expand)AuthorLines
2025-12-14fix non-sasl connection registrationMax Audron-9/+35
2025-12-14fix readme badge linksMax Audron-3/+3
2025-12-14update readme and remotesMax Audron-1/+14
2025-12-14release 1.7.01.7.0Max Audron-2/+2
2025-12-14add server passwordMax Audron-1/+6
2025-12-14update cargo dependenciesMax Audron-670/+505
2025-12-14update flake inputs to nixpkgs 25.11Max Audron-36/+41
2025-05-06fix rustls missing cryptoproviderMax Audron-1/+6
2025-05-06remove too commonly used used for shifty_eyesMax Audron-1/+1
2025-05-06fix truncate on unicodeMax Audron-10/+20
2025-05-06update dependenciesMax Audron-691/+1659
2024-08-12add nix build and moduleMax Audron-5/+427
2022-02-19remove jsonnet lock fileMax Audron-36/+0
2022-02-19fix deploy to work with gitlab agentMax Audron-4/+4
2021-10-22write tons of documentation and reorganize some modulesMax Audron-65/+300
2021-10-22remove wolfram alpha url shorteningMax Audron-1/+2
2021-10-20remove failing wolfram alpha test casesMax Audron-105/+55
2021-10-20bump version to 1.6.2Max Audron-3/+2
2021-10-20prepare for release on crates.ioMax Audron-39/+65
2021-10-20add async docs to macro crate and bump versionMax Audron-9/+10
2021-10-20change hook errors to be logged as warningsMax Audron-3/+3
2021-10-20fix configuration not loading correctly on release buildsMax Audron-8/+23
2021-10-19replace sedregex crate8-rework-sedMax Audron-20/+358
2021-10-19add formatting trait for irc codesMax Audron-0/+129
2021-10-17fix links in readmeMax Audron-2/+2