add bucket sys marshal func

This commit is contained in:
weisd
2024-10-09 15:06:50 +08:00
parent 1b61aa135e
commit c9423038da
13 changed files with 456 additions and 29 deletions
@@ -1,3 +1,5 @@
use crate::error::Result;
use rmp_serde::Serializer as rmpSerializer;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
@@ -38,3 +40,18 @@ pub struct BucketPolicy {
pub version: String,
pub statements: Vec<BPStatement>,
}
impl BucketPolicy {
pub fn marshal_msg(&self) -> Result<Vec<u8>> {
let mut buf = Vec::new();
self.serialize(&mut rmpSerializer::new(&mut buf).with_struct_map())?;
Ok(buf)
}
pub fn unmarshal(buf: &[u8]) -> Result<Self> {
let t: BucketPolicy = rmp_serde::from_slice(buf)?;
Ok(t)
}
}