Parsing the Redis Serialization Protocol (RESP) in Rust with nom (Part 2)
In this live coding session, we continue our project focused on parsing the Redis protocol in Rust using the nom library. We tackle various data types within the protocol, including integers, strings, arrays, and more complex structures like maps and sets.
We summarize our progress from the previous session, where we implemented parsers for simple data types and created a library exposing an enum called "value" representing different types of data.
The discussion covers addressing issues encountered with implementing more complex data types like maps and sets, parsing complete messages versus individual values within those messages, and optimizing parsing efficiency. We engage with viewers' questions and suggestions throughout the session, enhancing the collaborative learning experience.
Later, we implement a refactoring using the alt combinator to simplify and improve the code structure. We discuss parsing arrays in the Redis protocol and handle special cases like null values.
The conversation also explores parsing floating-point numbers, including positive and negative infinity and NaN. We discuss the nuances of handling these special values and consider potential improvements to the parsing functionality.
In the final segment, we patch the parsing functionality to handle special floating-point values and discuss plans for publishing our work on GitHub as a library. We invite feedback and contributions from viewers and express gratitude for their collaboration.
Chapters:
00:00:00 Intro
00:01:17 Recap of what we did in the previous stream
00:05:39 Solving the problem with unashable types for our recursive data structure
00:13:10 Creating a higher-level function to parse messages
00:25:10 Changing our first character matching structure with the nom `alt` combinator
00:29:34 Implementing parsing for the array data type
00:46:08 Implementing parsing for the NULL data type
00:50:40 Implementing parsing for the boolean data type
00:57:49 Implementing parsing for the double data type
01:29:20 Quick overview of the repository including our GitHub actions for testing and publishing the crate
01:30:52 Closing
⛓️ Links:
- Our previous session in the series: https://youtu.be/t9P_aOAP2s4
- Our repo (tinyresp): https://github.com/lmammino/tinyresp
- nom documentation: https://docs.rs/nom
- nom combinators cheatsheet: https://github.com/rust-bakery/nom/blob/main/doc/choosing_a_combinator.md
- nom error management cheatsheet: https://github.com/rust-bakery/nom/blob/main/doc/error_management.md
- nom official examples: https://github.com/rust-bakery/nom/tree/main/examples
- examples from this presentation: https://play.rust-lang.org/?
version=stable&mode=debug&edition=2021&gist=f2db795f7b887f9a2257f950863ee1f5
- The Redis Serialization Protocol (RESP) Spec: https://redis.io/docs/reference/protocol-spec/
➡️ Follow us on Twitch for more live streams at https://twitch.tv/loige
#Rust #Parsing #NOM #RedisProtocol #LiveStream #Twitch #LiveCoding