prikk_object/payload/
common.rs1use prikk_error::Result;
4
5use crate::{CanonicalEncode, CanonicalWriter};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub struct MerkleRoot(pub [u8; 32]);
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
19pub struct PatchSetDigest(pub [u8; 32]);
20
21#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
23#[repr(u16)]
24pub enum Intent {
25 Feature = 1,
27 Fix = 2,
29 Refactor = 3,
31 Docs = 4,
33 Test = 5,
35}
36
37impl Intent {
38 #[must_use]
40 pub const fn code(self) -> u16 {
41 self as u16
42 }
43}
44
45#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
47pub struct OperationConditionEntry {
48 pub key: String,
50 pub value: OperationCondition,
52}
53
54impl CanonicalEncode for OperationConditionEntry {
55 fn encode_canonical(&self, writer: &mut CanonicalWriter) -> Result<()> {
56 writer.field_string(1, &self.key)?;
57 writer.field_record(2, &self.value)?;
58 Ok(())
59 }
60}
61
62#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
64pub enum OperationCondition {
65 OldContentHash(Vec<u8>),
67 AnchorExists(String),
69 PathExists(String),
71 PathAbsent(String),
73}
74
75impl CanonicalEncode for OperationCondition {
76 fn encode_canonical(&self, writer: &mut CanonicalWriter) -> Result<()> {
77 match self {
78 Self::OldContentHash(hash) => {
79 writer.field_u32(1, 1)?;
80 writer.field_bytes(2, hash)?;
81 }
82 Self::AnchorExists(anchor) => {
83 writer.field_u32(1, 2)?;
84 writer.field_string(2, anchor)?;
85 }
86 Self::PathExists(path) => {
87 writer.field_u32(1, 3)?;
88 writer.field_string(2, path)?;
89 }
90 Self::PathAbsent(path) => {
91 writer.field_u32(1, 4)?;
92 writer.field_string(2, path)?;
93 }
94 }
95 Ok(())
96 }
97}