JMAP protocol layer refactoring (part 2)

This commit is contained in:
mdecimus
2025-09-24 18:14:44 +02:00
parent 6c612f7e1c
commit a95010c42e
60 changed files with 2260 additions and 1747 deletions

View File

@@ -15,7 +15,7 @@ use crate::blob_hash::BlobHash;
const B_LINKED: u8 = 0x10;
const B_RESERVED: u8 = 0x20;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum BlobClass {
Reserved {
account_id: u32,
@@ -65,14 +65,14 @@ impl BlobClass {
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct BlobId {
pub hash: BlobHash,
pub class: BlobClass,
pub section: Option<BlobSection>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct BlobSection {
pub offset_start: usize,
pub size: usize,
@@ -126,7 +126,7 @@ impl BlobId {
}
#[allow(clippy::should_implement_trait)]
fn from_iter<T, U>(it: &mut T) -> Option<Self>
pub fn from_iter<T, U>(it: &mut T) -> Option<Self>
where
T: Iterator<Item = U> + Leb128Iterator<U>,
U: Borrow<u8>,

View File

@@ -16,6 +16,8 @@ pub const BLOB_HASH_LEN: usize = 32;
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
serde::Serialize,
serde::Deserialize,
)]

View File

@@ -8,7 +8,7 @@ use crate::DocumentId;
use std::{ops::Deref, str::FromStr};
use utils::codec::base32_custom::{BASE32_ALPHABET, BASE32_INVERSE};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy, PartialOrd, Ord)]
#[repr(transparent)]
pub struct Id(u64);

View File

@@ -30,6 +30,8 @@ pub const OTHER: usize = 12;
Eq,
Hash,
Default,
PartialOrd,
Ord,
serde::Serialize,
)]
#[serde(untagged)]
@@ -65,6 +67,10 @@ pub enum Keyword {
impl Keyword {
pub fn parse(value: &str) -> Self {
Self::try_parse(value).unwrap_or_else(|| Keyword::Other(value.to_string()))
}
pub fn try_parse(value: &str) -> Option<Self> {
value
.split_at_checked(1)
.filter(|(prefix, _)| matches!(*prefix, "$" | "\\"))
@@ -84,7 +90,6 @@ impl Keyword {
"mdnsent" => Keyword::MdnSent
)
})
.unwrap_or_else(|| Keyword::Other(value.to_string()))
}
pub fn id(&self) -> Result<u32, &str> {
@@ -142,6 +147,12 @@ impl Keyword {
}
}
impl From<String> for Keyword {
fn from(value: String) -> Self {
Keyword::try_parse(&value).unwrap_or(Keyword::Other(value))
}
}
impl Display for Keyword {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
@@ -241,3 +252,12 @@ impl From<&ArchivedKeyword> for Keyword {
}
}
}
impl<'de> serde::Deserialize<'de> for Keyword {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
Ok(Keyword::parse(<&str>::deserialize(deserializer)?))
}
}

View File

@@ -4,8 +4,20 @@
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use utils::config::utils::ParseValue;
#[derive(
rkyv::Archive, rkyv::Deserialize, rkyv::Serialize, Clone, Copy, PartialEq, Eq, Hash, Debug,
rkyv::Archive,
rkyv::Deserialize,
rkyv::Serialize,
Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug,
PartialOrd,
Ord,
)]
#[rkyv(derive(Debug))]
pub enum SpecialUse {
@@ -80,3 +92,9 @@ impl From<&ArchivedSpecialUse> for SpecialUse {
}
}
}
impl ParseValue for SpecialUse {
fn parse_value(value: &str) -> Result<Self, String> {
SpecialUse::parse(value).ok_or_else(|| format!("Unknown folder role {:?}", value))
}
}

View File

@@ -6,10 +6,10 @@
use crate::collection::SyncCollection;
use serde::Serialize;
use std::fmt::Display;
use std::{fmt::Display, str::FromStr};
use utils::map::bitmap::{Bitmap, BitmapItem};
#[derive(Debug, Eq, PartialEq, Hash, Clone, Copy, Serialize)]
#[derive(Debug, Eq, PartialEq, Hash, Clone, Copy, Serialize, PartialOrd, Ord)]
#[repr(u8)]
pub enum DataType {
#[serde(rename = "Email")]
@@ -199,6 +199,14 @@ impl DataType {
}
}
impl FromStr for DataType {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
DataType::parse(s).ok_or(())
}
}
impl Display for DataType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_str())