Skip to content

Commit

Permalink
remove Error struct, improve test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Mar 26, 2017
1 parent 5f63ff4 commit 0d867b8
Show file tree
Hide file tree
Showing 9 changed files with 512 additions and 372 deletions.
27 changes: 9 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
sudo: false
language: rust
rust:
- nightly
- beta
- stable
- beta
- nightly
sudo: false
# https://github.com/huonw/travis-cargo
addons:
apt:
packages:
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- binutils-dev
before_script:
- |
pip install 'travis-cargo<0.2' --user &&
export PATH=$HOME/.local/bin:$PATH
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
script:
- |
travis-cargo build &&
travis-cargo test
- export CARGO_TARGET_DIR=`pwd`/target
- cargo build
- cargo test
- cargo doc --no-deps
after_success:
- |
travis-cargo --only stable coveralls --no-sudo --verify
- travis-cargo --only nightly coveralls --no-sudo --verify
env:
global:
# override the default `--features unstable` used for the nightly branch (optional)
Expand Down
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[package]
name = "resp"
version = "0.5.0"
version = "1.0.0"
authors = ["Qing Yan <[email protected]>"]
description = "RESP(REdis Serialization Protocol) Serialization for Rust."
documentation = "https://iorust.github.io/resp/resp"
homepage = "https://github.com/iorust/resp"
repository = "https://github.com/iorust/resp.git"
readme = "README.md"
keywords = ["redis", "resp", "serde", "serialization"]
keywords = ["redis", "resp", "serialization"]
license = "MIT/Apache-2.0"

[dev-dependencies]
rand = "0.3"
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ enum Value {
#### `fn encode_slice(array: &[&str]) -> Vec<u8>`

### Decoder
#### `Decoder.new() -> Self`
#### `Decoder.with_buf_bulk() -> Self`
#### `decoder.feed(buf: &[u8]) -> Result<(), io:Error>`
#### `decoder.read() -> Option<Value>`
#### `decoder.buffer_len() -> usize`
#### `decoder.result_len() -> usize`
#### `Decoder.new(reader: BufReader<R>) -> Self`
#### `Decoder.with_buf_bulk(reader: BufReader<R>) -> Self`
#### `decoder.decode() -> Result<Value>`


[version-image]: https://img.shields.io/crates/v/resp.svg
Expand Down
38 changes: 20 additions & 18 deletions benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ extern crate test;
extern crate resp;

use test::Bencher;
use std::io::BufReader;
use resp::{Value, Decoder};

fn prepare_values() -> Value {
let a = vec![
Value::Null,
Value::NullArray,
Value::String("OKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOK".to_string()),
Value::Error("ErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErr".to_string()),
Value::Integer(1234567890),
Value::Bulk("Bulk String Bulk String Bulk String Bulk String Bulk String Bulk String".to_string()),
Value::Array(vec![Value::Null, Value::Integer(123), Value::Bulk("Bulk String Bulk String".to_string())])
];
let a = vec![Value::Null,
Value::NullArray,
Value::String("OKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOK"
.to_string()),
Value::Error("ErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErrErr"
.to_string()),
Value::Integer(1234567890),
Value::Bulk("Bulk String Bulk String Bulk String Bulk String Bulk String Bulk String"
.to_string()),
Value::Array(vec![Value::Null,
Value::Integer(123),
Value::Bulk("Bulk String Bulk String".to_string())])];
let mut b = a.clone();
b.push(Value::Array(a));
b.push(Value::Null);
Expand All @@ -28,10 +32,8 @@ fn prepare_values() -> Value {
}

// Last result:
// test decode_values ... bench: 5,984 ns/iter (+/- 1,495)
// test encode_values ... bench: 3,567 ns/iter (+/- 478)
// test decode_values ... bench: 5,216 ns/iter (+/- 2,213)
// test encode_values ... bench: 3,080 ns/iter (+/- 56)
// test decode_values ... bench: 6,298 ns/iter (+/- 5,783)
// test encode_values ... bench: 2,568 ns/iter (+/- 1,879)

#[bench]
fn encode_values(b: &mut Bencher) {
Expand All @@ -42,10 +44,10 @@ fn encode_values(b: &mut Bencher) {
#[bench]
fn decode_values(b: &mut Bencher) {
let value = prepare_values();
let buffers = value.encode();
let buf = value.encode();
b.iter(|| {
let mut decoder = Decoder::new();
decoder.feed(&buffers).unwrap();
assert_eq!(decoder.read().unwrap(), value);
});
let mut decoder = Decoder::new(BufReader::new(buf.as_slice()));
assert_eq!(decoder.decode().unwrap(), value);
assert!(decoder.decode().is_err());
});
}
109 changes: 0 additions & 109 deletions src/error.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
//! RESP(REdis Serialization Protocol) Serialization for Rust.
pub use self::value::Value;
pub use self::error::{Error, ErrorCode, Result};
pub use self::serialize::{encode, encode_slice, Decoder};

mod value;
mod error;
mod serialize;
Loading

0 comments on commit 0d867b8

Please sign in to comment.