Skip to content

Commit 293b304

Browse files
committed
easier changes
1 parent b0e5c78 commit 293b304

3 files changed

Lines changed: 28 additions & 12 deletions

File tree

python3/cobs/cobs/__init__.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,3 @@
2626
DecodeError.__module__ = 'cobs.cobs'
2727

2828
from .._version import *
29-
30-
31-
def encoding_overhead(source_len):
32-
"""Calculates the maximum overhead when encoding a message with the given length.
33-
The overhead is a maximum of [n/254] bytes (one in 254 bytes) rounded up."""
34-
return (source_len + 254 - 1) // 254
35-
36-
37-
def max_encoded_length(source_len):
38-
"""Calculates how maximum possible size of an encoded message given the length of the
39-
source message."""
40-
return source_len + encoding_overhead(source_len)

python3/cobs/cobs/_cobs_py.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,17 @@ def decode(in_bytes):
8888
else:
8989
break
9090
return bytes(out_bytes)
91+
92+
93+
def encoding_overhead(source_len):
94+
"""Calculates the maximum overhead when encoding a message with the given length.
95+
The overhead is a maximum of [n/254] bytes (one in 254 bytes) rounded up."""
96+
if source_len == 0:
97+
return 1
98+
return (source_len + 253) // 254
99+
100+
101+
def max_encoded_length(source_len):
102+
"""Calculates how maximum possible size of an encoded message given the length of the
103+
source message."""
104+
return source_len + encoding_overhead(source_len)

python3/cobs/cobsr/_cobsr_py.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,17 @@ def decode(in_bytes):
9696
else:
9797
break
9898
return bytes(out_bytes)
99+
100+
101+
def encoding_overhead(source_len):
102+
"""Calculates the maximum overhead when encoding a message with the given length.
103+
The overhead is a maximum of [n/254] bytes (one in 254 bytes) rounded up."""
104+
if source_len == 0:
105+
return 1
106+
return (source_len + 253) // 254
107+
108+
109+
def max_encoded_length(source_len):
110+
"""Calculates how maximum possible size of an encoded message given the length of the
111+
source message."""
112+
return source_len + encoding_overhead(source_len)

0 commit comments

Comments
 (0)