Skip to content

Commit b3daab2

Browse files
committed
Upgrade client to use binary strings
1 parent 69677c1 commit b3daab2

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

Cargo.toml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
[package]
2-
name = "skytable"
3-
version = "0.4.0"
42
authors = ["Sayan Nandan <[email protected]>"]
5-
edition = "2018"
6-
readme = "README.md"
3+
categories = []
74
description = "Official Rust client driver for Skytable"
8-
license = "Apache-2.0"
95
documentation = "https://docs.rs/skytable"
10-
repository = "https://github.com/skytable/client-rust"
11-
categories = []
6+
edition = "2018"
127
keywords = ["skytable", "driver", "client", "database", "nosql"]
8+
license = "Apache-2.0"
9+
name = "skytable"
10+
readme = "README.md"
11+
repository = "https://github.com/skytable/client-rust"
12+
version = "0.4.0"
1313

1414
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1515

1616
[features]
17-
default = ["sync"]
17+
aio-ssl = ["tokio-openssl", "openssl"]
18+
aio-sslv = ["tokio-openssl", "openssl/vendored"]
1819
async = ["bytes", "tokio"]
19-
sync = []
20-
dbg = []
2120
const-gen = []
21+
dbg = []
22+
default = ["sync"]
2223
ssl = ["openssl"]
2324
sslv = ["openssl/vendored"]
24-
aio-ssl = ["tokio-openssl", "openssl"]
25-
aio-sslv = ["tokio-openssl", "openssl/vendored"]
25+
sync = []
2626

2727
[dependencies]
28-
bytes = { version="1.0.1", optional=true }
29-
tokio = { version="1.7.1", features=["net", "io-util", "io-std"], optional=true }
30-
openssl = { version="0.10.35", optional=true }
31-
tokio-openssl = { version="0.6.2", optional=true }
28+
bytes = {version = "1.0.1", optional = true}
29+
openssl = {version = "0.10.35", optional = true}
30+
tokio = {version = "1.9.0", features = ["net", "io-util", "io-std"], optional = true}
31+
tokio-openssl = {version = "0.6.2", optional = true}
3232
[package.metadata.docs.rs]
3333
all-features = true
3434
rustdoc-args = ["--cfg", "docsrs"]

src/actions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
//! use skytable::{actions::Actions, Connection};
3434
//! let mut con = Connection::new("127.0.0.1", 2003).unwrap();
3535
//! con.set("x", "100").unwrap();
36-
//! assert_eq!(con.get("x").unwrap(), "100".to_owned());
36+
//! assert_eq!(con.get("x").unwrap(), Vec::from("100"));
3737
//!
3838
//! ```
3939
@@ -173,7 +173,7 @@ implement_actions!(
173173
Response::Item(Element::RespCode(RespCode::Okay)) => {}
174174
}
175175
/// Get the value of a key
176-
fn get(key: impl IntoSkyhashBytes + 's) -> String {
176+
fn get(key: impl IntoSkyhashBytes + 's) -> Vec<u8> {
177177
{ Query::from("get").arg(key)}
178178
Response::Item(Element::String(st)) => st
179179
}
@@ -185,7 +185,7 @@ implement_actions!(
185185
/// Returns a vector of keys
186186
///
187187
/// Do note that the order might be completely meaningless
188-
fn lskeys(count: usize) -> Vec<String> {
188+
fn lskeys(count: usize) -> Vec<Vec<u8>> {
189189
{ Query::from("lskeys").arg(count)}
190190
Response::Item(Element::FlatArray(arr)) => arr
191191
}

src/deserializer.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ pub(super) struct Parser<'a> {
6565
pub enum Element {
6666
/// Arrays can be nested! Their `<tsymbol>` is `&`
6767
Array(Vec<Element>),
68-
/// A String value; `<tsymbol>` is `+`
69-
String(String),
68+
/// A binary/unicode string value; `<tsymbol>` is `+`
69+
String(Vec<u8>),
7070
/// An unsigned integer value; `<tsymbol>` is `:`
7171
UnsignedInt(u64),
7272
/// A non-recursive String array; tsymbol: `_`
73-
FlatArray(Vec<String>),
73+
FlatArray(Vec<Vec<u8>>),
7474
/// A response code
7575
RespCode(RespCode),
7676
}
@@ -280,9 +280,9 @@ impl<'a> Parser<'a> {
280280
}
281281
}
282282
/// The cursor should have passed the `+` tsymbol
283-
fn parse_next_string(&mut self) -> ParseResult<String> {
283+
fn parse_next_string(&mut self) -> ParseResult<Vec<u8>> {
284284
let our_string_chunk = self.__get_next_element()?;
285-
let our_string = String::from_utf8_lossy(&our_string_chunk).to_string();
285+
let our_string = Vec::from(our_string_chunk);
286286
if self.will_cursor_give_linefeed()? {
287287
// there is a lf after the end of the string; great!
288288
// let's skip that now
@@ -337,7 +337,7 @@ impl<'a> Parser<'a> {
337337
}
338338
}
339339
/// The cursor should have passed the tsymbol
340-
fn parse_next_flat_array(&mut self) -> ParseResult<Vec<String>> {
340+
fn parse_next_flat_array(&mut self) -> ParseResult<Vec<Vec<u8>>> {
341341
let (start, stop) = self.read_line();
342342
if let Some(our_size_chunk) = self.buffer.get(start..stop) {
343343
let array_size = Self::parse_into_usize(&our_size_chunk)?;

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,15 @@
5757
//! let mut con = Connection::new("127.0.0.1", 2003)?;
5858
//! let query = Query::from("heya");
5959
//! let res = con.run_simple_query(&query)?;
60-
//! assert_eq!(res, Response::Item(Element::String("HEY!".to_owned())));
60+
//! assert_eq!(res, Response::Item(Element::String(Vec::from("HEY"))));
6161
//! Ok(())
6262
//! }
6363
//! ```
6464
//!
65+
//! **And why was our string a [`Vec`]?**
66+
//! That's because the server sends a binary string with arbitrary bytes. The returned value may
67+
//! or may not be unicode, and this depends on the data type you set for your table.
68+
//!
6569
//! Way to go &mdash; you're all set! Now go ahead and run more advanced queries!
6670
//!
6771
//! ## Going advanced

0 commit comments

Comments
 (0)