-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
68 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--- | ||
major: 2 | ||
minor: 5 | ||
patch: 2 | ||
patch: 3 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
Test the 'io.fifo' module. | ||
""" | ||
|
||
# module under test | ||
from vcorelib.io import ByteFifo | ||
|
||
|
||
def test_bytes_fifo_basic(): | ||
"""Test basic interaction with a bytes FIFO.""" | ||
|
||
fifo = ByteFifo() | ||
|
||
assert fifo.pop(1) is None | ||
|
||
fifo.ingest(bytes(range(10))) | ||
|
||
assert fifo.pop(5) == bytes(range(5)) | ||
|
||
assert fifo.pop(5) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
A module implementing a simple bytes FIFO interface. | ||
""" | ||
|
||
# built-in | ||
from typing import Optional as _Optional | ||
|
||
|
||
class ByteFifo: | ||
"""A simple fifo for bytes.""" | ||
|
||
def __init__(self) -> None: | ||
"""Initialize this instance.""" | ||
|
||
self.data = bytes() | ||
self.size = 0 | ||
|
||
def ingest(self, data: bytes) -> None: | ||
"""Append new data to the end.""" | ||
|
||
self.data += data | ||
self.size = len(self.data) | ||
|
||
def pop(self, size: int) -> _Optional[bytes]: | ||
"""Attempt to read some number of bytes from the front.""" | ||
|
||
result = None | ||
|
||
if self.size >= size: | ||
result = self.data[:size] | ||
|
||
self.data = self.data[size:] | ||
self.size -= size | ||
|
||
return result |