use serde_derive::{Deserialize, Serialize};
use crate::chunk::FileSpan;
use crate::hashing::ObjectId;
#[derive(Debug, Clone)]
pub struct Blob {
pub contents: Contents,
pub id: ObjectId,
pub kind: Type,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Type {
Chunk,
Tree,
}
#[derive(Debug, Clone)]
pub enum Contents {
Buffer(Vec<u8>),
Span(FileSpan),
}
impl Blob {
pub fn bytes(&self) -> &[u8] {
match &self.contents {
Contents::Buffer(v) => v,
Contents::Span(s) => s.as_ref(),
}
}
}