feat: function signatures #2

open
opened by freshlybakedca.ke targeting master from private/coded/push-mltmlnyrnvuk
+1
Cargo.toml
···
crate-type = ["staticlib"]
[dependencies]
+
libz-sys = "1.1.23"
+18 -2
nilla.nix
···
{ config, lib }:
{
config = {
-
inputs.nixpkgs.src = pins.nixpkgs;
+
inputs.nixpkgs = {
+
src = pins.nixpkgs;
+
settings.overlays = [ config.inputs.fenix.result.overlays.default ];
+
};
+
+
inputs.fenix.src = pins.fenix;
shells.default = {
systems = [ "x86_64-linux" ];
shell =
-
{ mkShell, git }:
+
{ mkShell, git, fenix, bacon }:
mkShell {
inputsFrom = [ git ];
+
packages = [
+
(fenix.complete.withComponents [
+
"cargo"
+
"clippy"
+
"rust-src"
+
"rustc"
+
"rustfmt"
+
"rust-analyzer"
+
])
+
bacon
+
];
};
};
};
+13
npins/sources.json
···
{
"pins": {
+
"fenix": {
+
"type": "Git",
+
"repository": {
+
"type": "GitHub",
+
"owner": "nix-community",
+
"repo": "fenix"
+
},
+
"branch": "main",
+
"submodules": false,
+
"revision": "a563f057979806c59da53070297502eb7af22f62",
+
"url": "https://github.com/nix-community/fenix/archive/a563f057979806c59da53070297502eb7af22f62.tar.gz",
+
"hash": "sha256-WfItZn6duisxCxyltbu7Hs7kxzNeylgZGOwCYwHe26g="
+
},
"nilla": {
"type": "GitRelease",
"repository": {
+1
src/lib.rs
···
+
pub mod reftable;
pub mod varint;
+64
src/reftable/basics.rs
···
+
#[derive(Debug, Clone)]
+
pub struct ReftableBuf {
+
pub data: Vec<u8>,
+
pub len: usize,
+
}
+
+
impl ReftableBuf {
+
pub fn new() -> Self {
+
Self {
+
data: Vec::new(),
+
len: 0,
+
}
+
}
+
+
pub fn with_capacity(capacity: usize) -> Self {
+
Self {
+
data: Vec::with_capacity(capacity),
+
len: 0,
+
}
+
}
+
+
pub fn clear(&mut self) {
+
self.data.clear();
+
self.len = 0;
+
}
+
+
pub fn as_slice(&self) -> &[u8] {
+
&self.data[..self.len]
+
}
+
}
+
+
impl Default for ReftableBuf {
+
fn default() -> Self {
+
Self::new()
+
}
+
}
+
+
pub fn binsearch<F>(sz: usize, mut f: F) -> usize
+
where
+
F: FnMut(usize) -> Result<bool, String>,
+
{
+
todo!()
+
}
+
+
pub fn names_length(names: &[&str]) -> usize {
+
todo!()
+
}
+
+
pub fn parse_names(buf: &str) -> Result<Vec<String>, String> {
+
todo!()
+
}
+
+
pub fn common_prefix_size(a: &ReftableBuf, b: &ReftableBuf) -> usize {
+
todo!()
+
}
+
+
pub enum HashAlgorithm {
+
Sha1 = 89,
+
Sha256 = 247,
+
}
+
+
pub fn hash_size(id: HashAlgorithm) -> u32 {
+
todo!()
+
}
+59
src/reftable/block.rs
···
+
use crate::reftable::{basics::ReftableBuf, blocksource::ReftableBlockData};
+
use libz_sys::z_stream;
+
+
pub struct BlockWriter {
+
pub zstream: Box<z_stream>,
+
pub compressed: Vec<u8>,
+
+
pub block: Vec<u8>,
+
pub block_size: u32,
+
+
pub header_off: u32,
+
+
pub restart_interval: u16,
+
pub hash_size: u32,
+
+
pub next: u32,
+
pub restarts: Vec<u32>,
+
pub restart_len: u32,
+
pub restart_cap: u32,
+
+
pub last_key: ReftableBuf,
+
+
pub scratch: ReftableBuf,
+
pub entries: i32,
+
}
+
+
pub struct BlockIter {
+
pub next_off: u32,
+
pub block: Vec<ReftableBlock>,
+
+
pub last_key: ReftableBuf,
+
pub scratch: ReftableBuf,
+
}
+
+
pub struct ReftableBlock {
+
pub header_off: u32,
+
+
pub block_data: ReftableBlockData,
+
pub hash_size: usize,
+
+
pub zstream: Box<z_stream>,
+
pub uncompressed_data: Vec<u8>,
+
+
pub restart_count: u16,
+
pub restart_off: u32,
+
+
pub full_block_size: u32,
+
pub block_type: u8,
+
}
+
+
pub struct BlockReader {
+
pub zstream: Box<z_stream>,
+
pub uncompressed: Vec<u8>,
+
pub uncompressed_len: usize,
+
+
pub block: ReftableBlock,
+
+
pub pos: usize,
+
}
+21
src/reftable/blocksource.rs
···
+
pub struct ReftableBlockData {
+
data: Vec<u8>,
+
source: ReftableBlockSource,
+
}
+
+
impl AsRef<[u8]> for ReftableBlockData {
+
fn as_ref(&self) -> &[u8] {
+
&self.data
+
}
+
}
+
+
pub trait ReftableBlockSourceOps {
+
fn size(&self) -> u64;
+
fn read_block(&self, offset: u64, size: u32) -> Result<Vec<u8>, String>;
+
fn release_block(&self, data: &ReftableBlockData) -> Result<(), String>;
+
fn close(&mut self) -> Result<(), String>;
+
}
+
+
pub struct ReftableBlockSource {
+
ops: Box<dyn ReftableBlockSourceOps>,
+
}
+34
src/reftable/error.rs
···
+
#[derive(Debug, Clone, PartialEq, Eq)]
+
pub enum ReftableError {
+
General(String),
+
Io,
+
Format,
+
NotExist,
+
Lock,
+
Api,
+
Zlib,
+
EmptyTable,
+
Refname,
+
EntryTooBig,
+
Outdated,
+
OutOfMemory,
+
}
+
+
impl std::fmt::Display for ReftableError {
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+
match self {
+
ReftableError::General(msg) => write!(f, "general error: {}", msg),
+
ReftableError::Io => write!(f, "I/O error"),
+
ReftableError::Format => write!(f, "corrupt reftable file"),
+
ReftableError::NotExist => write!(f, "file does not exist"),
+
ReftableError::Lock => write!(f, "data is locked"),
+
ReftableError::Api => write!(f, "misuse of the reftable API"),
+
ReftableError::Zlib => write!(f, "zlib failure"),
+
ReftableError::EmptyTable => write!(f, "wrote empty table"),
+
ReftableError::Refname => write!(f, "invalid refname"),
+
ReftableError::EntryTooBig => write!(f, "entry too large"),
+
ReftableError::Outdated => write!(f, "data concurrently modified"),
+
ReftableError::OutOfMemory => write!(f, "out of memory"),
+
}
+
}
+
}
+26
src/reftable/fsck.rs
···
+
pub enum ReftableFsckError {
+
TableName,
+
MaxValue,
+
}
+
+
pub struct ReftableFsckInfo {
+
pub msg: String,
+
pub path: String,
+
pub error: ReftableFsckError,
+
}
+
+
pub fn table_has_valid_name(name: &str) -> bool {
+
todo!()
+
}
+
+
pub fn table_check_name(table: &ReftableTable) -> Result<(), String> {
+
todo!()
+
}
+
+
pub fn table_checks(table: &ReftableTable) -> Result<(), String> {
+
todo!()
+
}
+
+
pub fn reftable_fsck_check(stack: &ReftableStack) -> Result<(), String> {
+
todo!()
+
}
src/reftable/iter.rs
src/reftable/merged.rs
+14
src/reftable/mod.rs
···
+
pub mod basics;
+
pub mod block;
+
pub mod blocksource;
+
pub mod error;
+
pub mod fsck;
+
pub mod iter;
+
pub mod merged;
+
pub mod pq;
+
pub mod record;
+
pub mod stack;
+
pub mod system;
+
pub mod table;
+
pub mod tree;
+
pub mod write;
src/reftable/pq.rs
+148
src/reftable/record.rs
···
+
use crate::reftable::basics::ReftableBuf;
+
+
pub const REFTABLE_HASH_SIZE_MAX: usize = 32;
+
pub const REFTABLE_HASH_SIZE_SHA1: usize = 20;
+
pub const REFTABLE_HASH_SIZE_SHA256: usize = 32;
+
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+
pub enum RefValueType {
+
Deletion = 0x0,
+
Val1 = 0x1,
+
Val2 = 0x2,
+
SymRef = 0x3,
+
}
+
+
impl std::convert::TryFrom<u8> for RefValueType {
+
type Error = String;
+
+
fn try_from(value: u8) -> Result<Self, String> {
+
match value {
+
0x0 => Ok(RefValueType::Deletion),
+
0x1 => Ok(RefValueType::Val1),
+
0x2 => Ok(RefValueType::Val2),
+
0x3 => Ok(RefValueType::SymRef),
+
_ => Err(format!("Unknown ref value type: {value}")),
+
}
+
}
+
}
+
+
#[derive(Debug, Clone)]
+
pub enum RefValue {
+
Val1([u8; REFTABLE_HASH_SIZE_MAX]),
+
Val2 {
+
value: [u8; REFTABLE_HASH_SIZE_MAX],
+
target_value: [u8; REFTABLE_HASH_SIZE_MAX],
+
},
+
SymRef(String),
+
}
+
+
#[derive(Debug, Clone)]
+
pub struct ReftableRefRecord {
+
pub refname: String,
+
pub update_index: u64,
+
pub value: Option<RefValue>,
+
}
+
+
impl ReftableRefRecord {
+
pub fn equals(&self, other: &ReftableRefRecord, hash_size: u32) -> bool {
+
todo!()
+
}
+
}
+
+
impl PartialEq for ReftableRefRecord {
+
fn eq(&self, other: &ReftableRefRecord) -> bool {
+
self.equals(other, REFTABLE_HASH_SIZE_MAX as u32)
+
}
+
}
+
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+
pub enum LogValueType {
+
Deletion = 0x0,
+
Update = 0x1,
+
}
+
+
impl std::convert::TryFrom<u8> for LogValueType {
+
type Error = String;
+
+
fn try_from(value: u8) -> Result<Self, String> {
+
match value {
+
0x0 => Ok(LogValueType::Deletion),
+
0x1 => Ok(LogValueType::Update),
+
_ => Err(format!("Unknown log value type: {value}")),
+
}
+
}
+
}
+
+
#[derive(Debug, Clone)]
+
pub struct LogUpdate {
+
pub new_hash: [u8; REFTABLE_HASH_SIZE_MAX],
+
pub old_hash: [u8; REFTABLE_HASH_SIZE_MAX],
+
pub name: String,
+
pub email: String,
+
pub time: u64,
+
pub tz_offset: i16,
+
pub message: String,
+
}
+
+
#[derive(Debug, Clone)]
+
pub struct ReftableLogRecord {
+
pub refname: String,
+
pub update_index: u64,
+
pub value: Option<LogUpdate>,
+
}
+
+
impl ReftableLogRecord {
+
pub fn equals(&self, other: &ReftableLogRecord, hash_size: u32) -> bool {
+
todo!()
+
}
+
}
+
+
impl PartialEq for ReftableLogRecord {
+
fn eq(&self, other: &ReftableLogRecord) -> bool {
+
self.equals(other, REFTABLE_HASH_SIZE_MAX as u32)
+
}
+
}
+
+
#[derive(Debug, Clone)]
+
pub struct ReftableObjRecord {
+
pub hash_prefix: Vec<u8>,
+
pub offsets: Vec<u64>,
+
}
+
+
impl PartialEq for ReftableObjRecord {
+
fn eq(&self, other: &Self) -> bool {
+
self.hash_prefix == other.hash_prefix && self.offsets == other.offsets
+
}
+
}
+
+
#[derive(Debug, Clone)]
+
pub struct ReftableIndexRecord {
+
pub offset: u64,
+
pub last_key: ReftableBuf,
+
}
+
+
impl PartialEq for ReftableIndexRecord {
+
fn eq(&self, other: &Self) -> bool {
+
self.offset == other.offset && self.last_key.as_slice() == other.last_key.as_slice()
+
}
+
}
+
+
#[derive(Debug, Clone)]
+
pub enum ReftableRecord {
+
Ref(ReftableRefRecord),
+
Log(ReftableLogRecord),
+
Obj(ReftableObjRecord),
+
Index(ReftableIndexRecord),
+
}
+
+
impl PartialEq for ReftableRecord {
+
fn eq(&self, other: &Self) -> bool {
+
match (self, other) {
+
(ReftableRecord::Ref(a), ReftableRecord::Ref(b)) => a == b,
+
(ReftableRecord::Log(a), ReftableRecord::Log(b)) => a == b,
+
(ReftableRecord::Obj(a), ReftableRecord::Obj(b)) => a == b,
+
(ReftableRecord::Index(a), ReftableRecord::Index(b)) => a == b,
+
_ => false,
+
}
+
}
+
}
src/reftable/stack.rs
src/reftable/system.rs
src/reftable/table.rs
src/reftable/tree.rs
src/reftable/write.rs