Skip to content

Commit

Permalink
Merge pull request #61 from JarbasHiveMind/release-0.4.0a1
Browse files Browse the repository at this point in the history
Release 0.4.0a1
  • Loading branch information
JarbasAl authored Jan 8, 2025
2 parents 3767782 + 4f00277 commit d7b0e0c
Show file tree
Hide file tree
Showing 21 changed files with 1,302 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: "3.10"
- name: Install Build Tools
run: |
python -m pip install build wheel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: "3.10"
- name: Install Build Tools
run: |
python -m pip install build wheel
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Run UnitTests
on:
pull_request:
branches:
- dev
paths-ignore:
- 'hivemind_bus_client/version.py'
- '.github/**'
- '.gitignore'
- 'LICENSE'
- 'CHANGELOG.md'
- 'MANIFEST.in'
- 'README.md'
push:
branches:
- master
paths-ignore:
- 'hivemind_bus_client/version.py'
- '.github/**'
- '.gitignore'
- 'LICENSE'
- 'CHANGELOG.md'
- 'MANIFEST.in'
- 'README.md'
workflow_dispatch:

jobs:
unit_tests:
strategy:
matrix:
python-version: ["3.10", "3.11" ]
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v2
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt install python3-dev swig
python -m pip install build wheel
- name: Install repo
run: |
pip install -e .
- name: Install test dependencies
run: |
pip install -r test/requirements.txt
- name: Run unittests
run: |
pytest --cov=hivemind_bus_client --cov-report xml test
- name: Upload coverage
if: "${{ matrix.python-version == '3.11' }}"
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
uses: codecov/codecov-action@v2
22 changes: 19 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# Changelog

## [0.2.1a1](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/0.2.1a1) (2025-01-03)
## [0.4.0a1](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/0.4.0a1) (2025-01-08)

[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/0.2.0...0.2.1a1)
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/0.3.0a2...0.4.0a1)

**Merged pull requests:**

- fix:binarization\_protocol [\#53](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/53) ([JarbasAl](https://github.com/JarbasAl))
- feat:http client [\#60](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/60) ([JarbasAl](https://github.com/JarbasAl))

## [0.3.0a2](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/0.3.0a2) (2025-01-03)

[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/0.3.0a1...0.3.0a2)

**Merged pull requests:**

- chore:benchmark [\#57](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/57) ([JarbasAl](https://github.com/JarbasAl))

## [0.3.0a1](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/0.3.0a1) (2025-01-03)

[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/0.2.1...0.3.0a1)

**Merged pull requests:**

- feat:more encodings [\#55](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/55) ([JarbasAl](https://github.com/JarbasAl))



Expand Down
3 changes: 3 additions & 0 deletions hivemind_bus_client/encodings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from hivemind_bus_client.encodings.z85b import Z85B
from hivemind_bus_client.encodings.z85p import Z85P
from hivemind_bus_client.encodings.b91 import B91
100 changes: 100 additions & 0 deletions hivemind_bus_client/encodings/b91.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from typing import Union


class B91:
ALPHABET = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '#', '$',
'%', '&', '(', ')', '*', '+', ',', '.', '/', ':', ';', '<', '=',
'>', '?', '@', '[', ']', '^', '_', '`', '{', '|', '}', '~', '"'
]

DECODE_TABLE = {char: idx for idx, char in enumerate(ALPHABET)}

@classmethod
def decode(cls, encoded_data: Union[str, bytes], encoding: str = "utf-8") -> bytes:
"""
Decodes a Base91-encoded string into its original binary form.
Args:
encoded_data (Union[str, bytes]): Base91-encoded input data. If `bytes`, it is decoded as UTF-8.
encoding (str): The encoding to use if `encoded_data` is provided as a string. Default is 'utf-8'.
Returns:
bytes: The decoded binary data.
Raises:
ValueError: If the input contains invalid Base91 characters.
"""
if isinstance(encoded_data, bytes):
encoded_data = encoded_data.decode(encoding)

v = -1
b = 0
n = 0
out = bytearray()

for char in encoded_data:
if char not in cls.DECODE_TABLE:
raise ValueError(f"Invalid Base91 character: {char}")
c = cls.DECODE_TABLE[char]
if v < 0:
v = c
else:
v += c * 91
b |= v << n
n += 13 if (v & 8191) > 88 else 14
while n >= 8:
out.append(b & 255)
b >>= 8
n -= 8
v = -1

if v >= 0:
out.append((b | v << n) & 255)

return bytes(out)

@classmethod
def encode(cls, data: Union[bytes, str], encoding: str = "utf-8") -> bytes:
"""
Encodes binary data into a Base91-encoded string.
Args:
data (Union[bytes, str]): Input binary data to encode. If `str`, it is encoded as UTF-8.
encoding (str): The encoding to use if `data` is provided as a string. Default is 'utf-8'.
Returns:
str: The Base91-encoded string.
"""
if isinstance(data, str):
data = data.encode(encoding)

b = 0
n = 0
out = []

for byte in data:
b |= byte << n
n += 8
if n > 13:
v = b & 8191
if v > 88:
b >>= 13
n -= 13
else:
v = b & 16383
b >>= 14
n -= 14
out.append(cls.ALPHABET[v % 91])
out.append(cls.ALPHABET[v // 91])

if n:
out.append(cls.ALPHABET[b % 91])
if n > 7 or b > 90:
out.append(cls.ALPHABET[b // 91])

return ''.join(out).encode(encoding)
Loading

0 comments on commit d7b0e0c

Please sign in to comment.