mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 22:44:17 +00:00
Merge pull request #35 from VersBinarii/fix_bool
Decode boolean: check if enough bytes was received
This commit is contained in:
commit
0a5aacabd5
2 changed files with 12 additions and 4 deletions
|
@ -19,7 +19,11 @@ impl Encode<MySql> for bool {
|
|||
|
||||
impl Decode<MySql> for bool {
|
||||
fn decode(buf: &[u8]) -> Result<Self, DecodeError> {
|
||||
// FIXME: Return an error if the buffer size is not (at least) 1
|
||||
Ok(buf[0] != 0)
|
||||
match buf.len() {
|
||||
0 => Err(DecodeError::Message(Box::new(
|
||||
"Expected minimum 1 byte but received none.",
|
||||
))),
|
||||
_ => Ok(buf[0] != 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,11 @@ impl Encode<Postgres> for bool {
|
|||
|
||||
impl Decode<Postgres> for bool {
|
||||
fn decode(buf: &[u8]) -> Result<Self, DecodeError> {
|
||||
// FIXME: Return an error if the buffer size is not (at least) 1
|
||||
Ok(buf[0] != 0)
|
||||
match buf.len() {
|
||||
0 => Err(DecodeError::Message(Box::new(
|
||||
"Expected minimum 1 byte but received none.",
|
||||
))),
|
||||
_ => Ok(buf[0] != 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue