Skip to content

Instantly share code, notes, and snippets.

@tailhook
Created January 2, 2016 02:22
Show Gist options
  • Select an option

  • Save tailhook/1f9bc0d8e8a7afed70d5 to your computer and use it in GitHub Desktop.

Select an option

Save tailhook/1f9bc0d8e8a7afed70d5 to your computer and use it in GitHub Desktop.
// Function signature is simplified a bit
fn bytes_received(self, buf, ..) -> Response<..> {
match self {
PacketStart => (PacketLength, Bytes(4), next_timeout())
PacketLength => {
let len = buf.read_u32();
(PacketEnd, Bytes(len), next_timeout())
}
Packet => {
parse_packet(&buf[..]);
(PacketLength, Bytes(4), next_timeout())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment