-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #14: Refactor: extract bencode tokenizer
ec6cc56 docs: update README (Jose Celano) 68d9915 refactor: rename json::BencodeParser to json::Generator (Jose Celano) a3c7c4b refactor: remove parent parser mod (Jose Celano) 3052d6a refactor: rename BencodeTOkenizer to Tokenizer (Jose Celano) 331c76e refactor: reorganize modules (Jose Celano) 9e0db6c refactor: remove writer from tokenizer string parser (Jose Celano) 0a05544 refactor: remove old int and str parsers with writers (Jose Celano) 75ffdb4 refactor: remove writer from tokenizer integer parser (Jose Celano) 77ad5af refactor: remove writer from main tokenizer (Jose Celano) f6a0584 refactor: duplicate integer and strig parser before removing writer (Jose Celano) 3a7ea5d refactor: extract mod tokenizer (Jose Celano) 63b9b73 refactor: extract struct BencodeTokenizer (Jose Celano) 83eeefd refactor: extract bencode tokenizer (Jose Celano) Pull request description: This refactoring changes the current implementation to extract the tokenizer. It splits parser logic into two types: - **Tokenizer**: It returns bencoded tokens. - **Generator**: It iterates over bencoded tokens to generate the JSON. **NOTES** - It keeps the custom recursivity (with explicit stack) for the time being, instead of using explicit recursivity like @da2ce7 did [here](#12 (comment)). I guess that could be changed later if we think it increases readability and maintainability. **SUBTASKS** - [x] Separate logic for tokenizer. - [x] Extract tokenizer. - [x] Remove `Writer` from the tokenizer. It's not needed. **PERFORMANCE** In the current version, bencoded strings are cached in memory before starting writing to the output (because we nned the whole string to check if it's a valid UTF-8). In this PR, bencoded integers are also cached in memory because the whole integer value is a token. This should not be a problem since integers are short, unlike strings. **FUTURE PRs** We could: - [ ] Implement the `Iterator` trait for the tokenizer. - [ ] Use recursion for the generator like @da2ce7's proposal [here](#12). - [ ] Implement another generator for TOML, for example. Check if this design can be easily extended to other output formats. ACKs for top commit: josecelano: ACK ec6cc56 Tree-SHA512: 9210211d802c8e19aef1f02f814b494c5919c7da81f299cf2c7f4d9fb12b4c63cbec4ac526996e6b1b3d69f75ca58894b9d64936bef2d9da851e70d51234c675
- Loading branch information
Showing
17 changed files
with
436 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.