File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626DecodeError .__module__ = 'cobs.cobs'
2727
2828from .._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 )
Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments