Removed debug messages and added docs

next
Sayan Nandan 4 years ago
parent e8d1c0e90c
commit 79e3b9535f
No known key found for this signature in database
GPG Key ID: C31EFD7DDA12AEE0

@ -19,6 +19,8 @@
*
*/
//! This module provides methods to deserialize an incoming response packet
use corelib::de::*;
use corelib::terrapipe::*;
use std::fmt;
@ -59,7 +61,6 @@ impl Metaline {
if mline.len() < 7 {
return None;
}
println!("DEBUG: Got metaline");
let resp_type = match unsafe { mline.get_unchecked(0) } {
b'$' => ActionType::Pipeline,
b'*' => ActionType::Simple,
@ -69,15 +70,11 @@ impl Metaline {
// TODO(@ohsayan): Enable pipelined responses to be parsed
unimplemented!("Pipelined responses cannot be parsed yet");
}
println!("DEBUG: Got resptype");
let respcode = match RespCodes::from_utf8(unsafe { *mline.get_unchecked(2) }) {
Some(rc) => rc,
None => return None,
};
println!("DEBUG: Got respcode");
if let Some(sizes) = get_frame_sizes(unsafe { mline.get_unchecked(3..) }) {
println!("DEBUG: Got frame sizes");
println!("DEBUG: These are the sizes: '{:#?}'", sizes);
return Some(Metaline {
content_size: unsafe { *sizes.get_unchecked(0) },
metalayout_size: unsafe { *sizes.get_unchecked(1) },
@ -96,9 +93,7 @@ struct Metalayout(Vec<usize>);
impl Metalayout {
pub fn from_navigator(nav: &mut Navigator, mlayoutsize: usize) -> Option<Self> {
if let Some(layout) = nav.get_line(Some(mlayoutsize)) {
println!("DEBUG: Got layout line");
if let Some(skip_sequence) = get_skip_sequence(&layout) {
println!("DEBUG: Got skip sequence");
return Some(Metalayout(skip_sequence));
}
}
@ -126,7 +121,6 @@ impl Response {
}
if let Some(layout) = Metalayout::from_navigator(&mut nav, metaline.metalayout_size) {
if let Some(content) = nav.get_exact(metaline.content_size) {
println!("DEBUG: Got content");
let data = extract_idents(content, layout.0);
if is_other_error {
if data.len() == 1 {

@ -93,10 +93,6 @@ impl Connection {
// The connection was possibly reset
return ClientResult::Empty(0);
}
println!(
"The server gave: '{}'",
String::from_utf8_lossy(&self.buffer)
);
let nav = Navigator::new(&self.buffer);
Response::from_navigator(nav)
}

@ -19,5 +19,9 @@
*
*/
//! This module contains submodules for building:
//! - Queries (the `query` module)
//! - Responses (the `response` module)
pub mod query;
pub mod response;

@ -19,26 +19,41 @@
*
*/
//! # The `Query` module
//! This module can be used to build queries that can be sent to the database
//! server. It prepares packets following the Terrapipe protocol.
use crate::terrapipe::DEF_QMETALINE_BUFSIZE;
/// A `QueryBuilder` which enables building simple and pipelined queries
pub enum QueryBuilder {
/// A `SimpleQuery`
SimpleQuery,
// TODO(@ohsayan): Add pipelined queries here
}
impl QueryBuilder {
/// Instantiate a new `SimpleQuery` instance which can be used to build
/// queries
pub fn new_simple() -> SimpleQuery {
SimpleQuery::new()
}
}
/// A simple query is used for simple queries - queries that run only one command
pub struct SimpleQuery {
/// The metaline of the simple query
metaline: Vec<u8>,
/// The metalayout of the simple query
metalayout: Vec<u8>,
/// The dataframe of the simple query
dataframe: Vec<u8>,
}
impl SimpleQuery {
/// Create a new `SimpleQuery` object
pub fn new() -> Self {
let mut metaline = Vec::with_capacity(46);
let mut metaline = Vec::with_capacity(DEF_QMETALINE_BUFSIZE);
metaline.push(b'*');
metaline.push(b'!');
SimpleQuery {
@ -47,6 +62,9 @@ impl SimpleQuery {
dataframe: Vec::with_capacity(1024),
}
}
/// Add an item to the query packet
///
/// This accepts anything which can be turned into a sequence of bytes
pub fn add(&mut self, cmd: impl Into<Vec<u8>>) {
let cmd = cmd.into();
let l = cmd.len().to_string();
@ -55,6 +73,7 @@ impl SimpleQuery {
self.dataframe.extend(&cmd);
self.dataframe.push(b'\n');
}
/// Prepare a query packet that can be directly written to the socket
pub fn prepare_query(mut self) -> Vec<u8> {
self.metaline
.extend(self.dataframe.len().to_string().as_bytes());
@ -65,6 +84,7 @@ impl SimpleQuery {
self.metalayout.push(b'\n');
[self.metaline, self.metalayout, self.dataframe].concat()
}
/// Create a query from a command line input - usually separated by whitespaces
pub fn from_cmd(&mut self, cmd: String) {
let cmd: Vec<&str> = cmd.split_whitespace().collect();
cmd.into_iter().for_each(|val| self.add(val));

@ -19,6 +19,10 @@
*
*/
//! # The `Response` module
//! This module can be used to build responses that can be sent to clients.
//! It prepares packets following the Terrapipe protocol.
pub struct SResp {
metaline: Vec<u8>,
metalayout: Vec<u8>,

Loading…
Cancel
Save