Skip to content

Commit

Permalink
(trying) revert changes in decode_from_file for ResponseMessage and A…
Browse files Browse the repository at this point in the history
…piMessage
  • Loading branch information
morenol committed May 14, 2021
1 parent c0c4b75 commit 33209a0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/protocol/fluvio-protocol-api/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::default::Default;
use std::io::Error as IoError;
use std::io::ErrorKind;
use std::fs::File;
use std::io::Cursor;
use std::path::Path;
Expand All @@ -9,6 +10,7 @@ use std::fmt;
use std::convert::TryFrom;

use log::debug;
use log::trace;

use crate::core::Decoder;
use crate::core::Encoder;
Expand Down Expand Up @@ -53,6 +55,17 @@ pub trait ApiMessage: Sized + Default {
let data = buffer.to_vec();
let mut src = Cursor::new(&data);

let mut size: i32 = 0;
size.decode(&mut src, 0)?;
trace!("decoded request size: {} bytes", size);

if src.remaining() < size as usize {
return Err(IoError::new(
ErrorKind::UnexpectedEof,
"not enought bytes for request message",
));
}

Self::decode_from(&mut src)
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/protocol/fluvio-protocol-api/src/response.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fs::File;
use std::io::Cursor;
use std::io::Error as IoError;
use std::io::ErrorKind;
use std::io::Read;
use std::path::Path;

Expand Down Expand Up @@ -67,6 +68,18 @@ where

let mut src = Cursor::new(&data);

// ResponseMessage implementation of fluvio_protocol::storage::FileWrite trait first encodes the length
// of the ResponseMessage
let mut size: i32 = 0;
size.decode(&mut src, version)?;
trace!("decoded response size: {} bytes", size);

if src.remaining() < size as usize {
return Err(IoError::new(
ErrorKind::UnexpectedEof,
"not enought for response",
));
}
Self::decode_from(&mut src, version)
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/protocol/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ where
}
}

/// This is same as encoding in the ResponseMessage but can encode async file slice
/// This is same as encoding in the ResponseMessage but first
/// includes the lenght and can encode async file slice
impl<P> FileWrite for ResponseMessage<P>
where
P: FileWrite + Default,
Expand Down Expand Up @@ -84,6 +85,8 @@ where
}
}

/// This is same as encoding in the RequestMessage but first
/// includes the lenght and can encode async file slice
impl<R> FileWrite for RequestMessage<R>
where
R: FileWrite + Default + Request,
Expand All @@ -94,15 +97,15 @@ where
data: &mut Vec<StoreValue>,
version: Version,
) -> Result<(), IoError> {
trace!("file encoding response message");
trace!("file encoding request message");
let len = self.write_size(version) as i32;
trace!("file encoding response len: {}", len);
trace!("file encoding request len: {}", len);
len.encode(dest, version)?;

trace!("file encoding header");
self.header.encode(dest, version)?;

trace!("encoding response");
trace!("encoding request");
self.request.file_encode(dest, data, version)?;
Ok(())
}
Expand Down

0 comments on commit 33209a0

Please sign in to comment.