Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors #4

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,465 changes: 940 additions & 525 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ maintenance = { status = "experimental" }

[dependencies]
futures-io = { version = "0.3", optional = true }
futures-util = { version = "0.3", optional = true }
futures-util = { version = "0.3", optional = true, features = ["io"] }
libc = "0.2"
log = "0.4"

[dev-dependencies]
async-std = "1.2"
env_logger = "0.7"
env_logger = "0.11"
futures= "0.3"
structopt = "0.3"

[build-dependencies]
cc = "1.0"
rand = "0.6"
bindgen = "0.52"
rand = "0.8"
bindgen = "0.69"
pkg-config = { version = "0.3", optional = true }

[features]
Expand Down
6 changes: 3 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ fn main() {
}
let bindings = builder
.header("xdelta3/xdelta3/xdelta3.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.whitelist_function("xd3_.*")
.whitelist_type("xd3_.*")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.allowlist_function("xd3_.*")
.allowlist_type("xd3_.*")
.rustified_enum("xd3_.*")
.generate()
.expect("Unable to generate bindings");
Expand Down
188,316 changes: 188,316 additions & 0 deletions head

Large diffs are not rendered by default.

Empty file added out.sql
Empty file.
47 changes: 47 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,50 @@ pub fn decode(input: &[u8], src: &[u8]) -> Option<Vec<u8>> {
}
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn roundtrip() {
let input = b"Hello, world! Hello, world!";
let src = b"Hello, world!";

let patch = encode(input, src).unwrap();
let output = decode(&patch, src).unwrap();

assert_eq!(output.as_slice(), input);
}

#[test]
fn roundtrip_process() {
use std::io::*;
use stream::*;

let src = b"Hello, world!".to_vec();
let input = b"Hello, world! Hello, world!".to_vec();

let mut patch = Vec::new();
process(
Xd3Config::new(),
ProcessMode::Encode,
input.as_slice(),
src.as_slice(),
&mut patch,
)
.unwrap();

let mut output = Vec::new();
process(
Xd3Config::new(),
ProcessMode::Decode,
patch.as_slice(),
src.as_slice(),
&mut output,
)
.unwrap();

assert_eq!(output, input);
}
}
53 changes: 53 additions & 0 deletions src/rw.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
use std::pin::Pin;
use std::task::{Context, Poll};

struct Xdelta3Reader<R1, R2> {
input: R1,
state: ProcessState<R2>,
mode: Mode,
}

impl<R1, R2> AsyncRead for Xdelta3Reader<R1, R2>
where
R1: Unpin + AsyncRead,
R2: Unpin + AsyncRead,
{
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<Result<usize>> {
use binding::xd3_rvalues::*;

let mode = self.as_ref().mode;
let state = &mut self.as_mut().state;

loop {
match state.step(mode) {
XD3_INPUT => {
if state.eof {
break;
}
// state.read_input(&mut input).await?;
}
XD3_OUTPUT => {
// state.write_output(&mut output).await?;
}
XD3_GETSRCBLK => {
// state.src_buf.getblk().await;
}
XD3_GOTHEADER | XD3_WINSTART | XD3_WINFINISH => {
// do nothing
}
XD3_TOOFARBACK | XD3_INTERNAL | XD3_INVALID | XD3_INVALID_INPUT | XD3_NOSECOND
| XD3_UNIMPLEMENTED => {
return Poll::Ready(Err(std::io::Error::new(std::io::ErrorKind::Other)));
}
}
}

unimplemented!();
}
}
*/
Loading
Loading