git_internal/internal/object/
mod.rs1pub mod blob;
2pub mod commit;
3pub mod note;
4pub mod signature;
5pub mod tag;
6pub mod tree;
7pub mod types;
8pub mod utils;
9
10use std::{
11 fmt::Display,
12 io::{BufRead, Read},
13 str::FromStr,
14};
15
16use sha1::Digest;
17
18use crate::internal::object::types::ObjectType;
19use crate::internal::zlib::stream::inflate::ReadBoxed;
20use crate::{errors::GitError, hash::SHA1};
21
22pub trait ObjectTrait: Send + Sync + Display {
23 fn from_bytes(data: &[u8], hash: SHA1) -> Result<Self, GitError>
25 where
26 Self: Sized;
27
28 fn from_buf_read<R: BufRead>(read: &mut ReadBoxed<R>, size: usize) -> Self
32 where
33 Self: Sized,
34 {
35 let mut content: Vec<u8> = Vec::with_capacity(size);
36 read.read_to_end(&mut content).unwrap();
37 let h = read.hash.clone();
38 let hash_str = h.finalize();
39 Self::from_bytes(&content, SHA1::from_str(&format!("{hash_str:x}")).unwrap()).unwrap()
40 }
41
42 fn get_type(&self) -> ObjectType;
44
45 fn get_size(&self) -> usize;
46
47 fn to_data(&self) -> Result<Vec<u8>, GitError>;
48}