Skip to content

Commit 9d4a186

Browse files
committed
Bump dependencies
1 parent ba22119 commit 9d4a186

File tree

4 files changed

+115
-97
lines changed

4 files changed

+115
-97
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ codecov = { repository = "jonhoo/msql-srv", branch = "master", service = "github
2222
maintenance = { status = "experimental" }
2323

2424
[dependencies]
25-
nom = "4.2.3"
26-
mysql_common = "0.17"
25+
nom = "5.0.0"
26+
mysql_common = "0.18"
2727
byteorder = "1"
2828
chrono = "0.4"
2929

3030
[dev-dependencies]
3131
postgres = "0.15.2"
3232
mysql = "16.0.0"
33-
mysql_async = "0.19.0"
33+
mysql_async = "0.20.0"
3434
slab = "0.4.2"
3535
tokio = "0.1.19"
3636
futures = "0.1.26"

src/commands.rs

Lines changed: 66 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ pub struct ClientHandshake<'a> {
99
username: &'a [u8],
1010
}
1111

12-
named!(
13-
pub client_handshake<ClientHandshake>,
14-
do_parse!(
15-
cap: apply!(nom::le_u32,) >>
16-
maxps: apply!(nom::le_u32,) >>
17-
collation: take!(1) >>
18-
take!(23) >>
19-
username: take_until!(&b"\0"[..]) >>
20-
tag!(b"\0") >> //rustfmt
21-
(ClientHandshake {
12+
pub fn client_handshake(i: &[u8]) -> nom::IResult<&[u8], ClientHandshake> {
13+
let (i, cap) = nom::number::complete::le_u32(i)?;
14+
let (i, maxps) = nom::number::complete::le_u32(i)?;
15+
let (i, collation) = nom::bytes::complete::take(1u8)(i)?;
16+
let (i, _) = nom::bytes::complete::take(23u8)(i)?;
17+
let (i, username) = nom::bytes::complete::take_until(&b"\0"[..])(i)?;
18+
let (i, _) = nom::bytes::complete::tag(b"\0")(i)?;
19+
Ok((
20+
i,
21+
ClientHandshake {
2222
capabilities: CapabilityFlags::from_bits_truncate(cap),
2323
maxps,
2424
collation: u16::from(collation[0]),
2525
username,
26-
})
27-
)
28-
);
26+
},
27+
))
28+
}
2929

3030
#[derive(Debug, PartialEq, Eq)]
3131
pub enum Command<'a> {
@@ -47,48 +47,63 @@ pub enum Command<'a> {
4747
Quit,
4848
}
4949

50-
named!(
51-
execute<Command>,
52-
do_parse!(
53-
stmt: apply!(nom::le_u32,) >>
54-
_flags: take!(1) >>
55-
_iterations: apply!(nom::le_u32,) >>
56-
rest: apply!(nom::rest,) >> //rustfmt
57-
(Command::Execute {
58-
stmt,
59-
params: rest,
60-
})
61-
)
62-
);
50+
pub fn execute(i: &[u8]) -> nom::IResult<&[u8], Command> {
51+
let (i, stmt) = nom::number::complete::le_u32(i)?;
52+
let (i, _flags) = nom::bytes::complete::take(1u8)(i)?;
53+
let (i, _iterations) = nom::number::complete::le_u32(i)?;
54+
Ok((&[], Command::Execute { stmt, params: i }))
55+
}
6356

64-
named!(
65-
send_long_data<Command>,
66-
do_parse!(
67-
stmt: apply!(nom::le_u32,) >>
68-
param: apply!(nom::le_u16,) >>
69-
data: apply!(nom::rest,) >> // rustfmt
70-
(Command::SendLongData {
57+
pub fn send_long_data(i: &[u8]) -> nom::IResult<&[u8], Command> {
58+
let (i, stmt) = nom::number::complete::le_u32(i)?;
59+
let (i, param) = nom::number::complete::le_u16(i)?;
60+
Ok((
61+
&[],
62+
Command::SendLongData {
7163
stmt,
7264
param,
73-
data,
74-
})
75-
)
76-
);
65+
data: i,
66+
},
67+
))
68+
}
7769

78-
named!(
79-
pub parse<Command>,
80-
alt!(
81-
preceded!(tag!(&[CommandByte::COM_QUERY as u8]), apply!(nom::rest,)) => { |sql| Command::Query(sql) } |
82-
preceded!(tag!(&[CommandByte::COM_FIELD_LIST as u8]), apply!(nom::rest,)) => { |filter| Command::ListFields(filter) } |
83-
preceded!(tag!(&[CommandByte::COM_INIT_DB as u8]), apply!(nom::rest,)) => { |db| Command::Init(db) } |
84-
preceded!(tag!(&[CommandByte::COM_STMT_PREPARE as u8]), apply!(nom::rest,)) => { |sql| Command::Prepare(sql) } |
85-
preceded!(tag!(&[CommandByte::COM_STMT_EXECUTE as u8]), execute) |
86-
preceded!(tag!(&[CommandByte::COM_STMT_SEND_LONG_DATA as u8]), send_long_data) |
87-
preceded!(tag!(&[CommandByte::COM_STMT_CLOSE as u8]), apply!(nom::le_u32,)) => { |stmt| Command::Close(stmt)} |
88-
tag!(&[CommandByte::COM_QUIT as u8]) => { |_| Command::Quit } |
89-
tag!(&[CommandByte::COM_PING as u8]) => { |_| Command::Ping }
90-
)
91-
);
70+
pub fn parse(i: &[u8]) -> nom::IResult<&[u8], Command> {
71+
use nom::bytes::complete::tag;
72+
use nom::combinator::{map, rest};
73+
use nom::sequence::preceded;
74+
nom::branch::alt((
75+
map(
76+
preceded(tag(&[CommandByte::COM_QUERY as u8]), rest),
77+
Command::Query,
78+
),
79+
map(
80+
preceded(tag(&[CommandByte::COM_FIELD_LIST as u8]), rest),
81+
Command::ListFields,
82+
),
83+
map(
84+
preceded(tag(&[CommandByte::COM_INIT_DB as u8]), rest),
85+
Command::Init,
86+
),
87+
map(
88+
preceded(tag(&[CommandByte::COM_STMT_PREPARE as u8]), rest),
89+
Command::Prepare,
90+
),
91+
preceded(tag(&[CommandByte::COM_STMT_EXECUTE as u8]), execute),
92+
preceded(
93+
tag(&[CommandByte::COM_STMT_SEND_LONG_DATA as u8]),
94+
send_long_data,
95+
),
96+
map(
97+
preceded(
98+
tag(&[CommandByte::COM_STMT_CLOSE as u8]),
99+
nom::number::complete::le_u32,
100+
),
101+
Command::Close,
102+
),
103+
map(tag(&[CommandByte::COM_QUIT as u8]), |_| Command::Quit),
104+
map(tag(&[CommandByte::COM_PING as u8]), |_| Command::Ping),
105+
))(i)
106+
}
92107

93108
#[cfg(test)]
94109
mod tests {

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
extern crate byteorder;
9595
extern crate chrono;
9696
extern crate mysql_common as myc;
97-
#[macro_use]
9897
extern crate nom;
9998

10099
use std::collections::HashMap;

src/packet.rs

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use byteorder::{ByteOrder, LittleEndian};
2-
use nom::{self, IResult};
2+
use nom;
33
use std::io;
44
use std::io::prelude::*;
55

@@ -135,20 +135,22 @@ impl<R: Read> PacketReader<R> {
135135
}
136136
}
137137

138-
named!(
139-
fullpacket<(u8, &[u8])>,
140-
do_parse!(
141-
tag!(&[0xff, 0xff, 0xff]) >> seq: take!(1) >> bytes: take!(U24_MAX) >> (seq[0], bytes)
142-
)
143-
);
138+
pub fn fullpacket(i: &[u8]) -> nom::IResult<&[u8], (u8, &[u8])> {
139+
let (i, _) = nom::bytes::complete::tag(&[0xff, 0xff, 0xff])(i)?;
140+
let (i, seq) = nom::bytes::complete::take(1u8)(i)?;
141+
let (i, bytes) = nom::bytes::complete::take(U24_MAX)(i)?;
142+
Ok((i, (seq[0], bytes)))
143+
}
144144

145-
named!(
146-
onepacket<(u8, &[u8])>,
147-
do_parse!(
148-
length: apply!(nom::le_u24,) >> seq: take!(1) >> bytes: take!(length) >> (seq[0], bytes)
149-
)
150-
);
145+
pub fn onepacket(i: &[u8]) -> nom::IResult<&[u8], (u8, &[u8])> {
146+
let (i, length) = nom::number::complete::le_u24(i)?;
147+
let (i, seq) = nom::bytes::complete::take(1u8)(i)?;
148+
let (i, bytes) = nom::bytes::complete::take(length)(i)?;
149+
Ok((i, (seq[0], bytes)))
150+
}
151151

152+
// Clone because of https://github.com/Geal/nom/issues/1008
153+
#[derive(Clone)]
152154
pub struct Packet<'a>(&'a [u8], Vec<u8>);
153155

154156
impl<'a> Packet<'a> {
@@ -191,35 +193,37 @@ impl<'a> Deref for Packet<'a> {
191193
}
192194
}
193195

194-
fn packet<'a>(input: &'a [u8]) -> IResult<&'a [u8], (u8, Packet<'a>)> {
195-
do_parse!(
196-
input,
197-
full: fold_many0!(
198-
fullpacket,
199-
(0, None),
200-
|(seq, pkt): (_, Option<Packet<'a>>), (nseq, p)| {
201-
let pkt = if let Some(mut pkt) = pkt {
202-
assert_eq!(nseq, seq + 1);
203-
pkt.extend(p);
204-
Some(pkt)
205-
} else {
206-
Some(Packet(p, Vec::new()))
207-
};
208-
(nseq, pkt)
209-
}
210-
) >> last: onepacket
211-
>> ({
212-
let seq = last.0;
213-
let pkt = if let Some(mut pkt) = full.1 {
214-
assert_eq!(last.0, full.0 + 1);
215-
pkt.extend(last.1);
216-
pkt
217-
} else {
218-
Packet(last.1, Vec::new())
219-
};
220-
(seq, pkt)
221-
})
222-
)
196+
fn packet(i: &[u8]) -> nom::IResult<&[u8], (u8, Packet)> {
197+
nom::combinator::map(
198+
nom::sequence::pair(
199+
nom::multi::fold_many0(
200+
fullpacket,
201+
(0, None),
202+
|(seq, pkt): (_, Option<Packet>), (nseq, p)| {
203+
let pkt = if let Some(mut pkt) = pkt {
204+
assert_eq!(nseq, seq + 1);
205+
pkt.extend(p);
206+
Some(pkt)
207+
} else {
208+
Some(Packet(p, Vec::new()))
209+
};
210+
(nseq, pkt)
211+
},
212+
),
213+
onepacket,
214+
),
215+
move |(full, last)| {
216+
let seq = last.0;
217+
let pkt = if let Some(mut pkt) = full.1 {
218+
assert_eq!(last.0, full.0 + 1);
219+
pkt.extend(last.1);
220+
pkt
221+
} else {
222+
Packet(last.1, Vec::new())
223+
};
224+
(seq, pkt)
225+
},
226+
)(i)
223227
}
224228

225229
#[cfg(test)]

0 commit comments

Comments
 (0)