move murmur3 tuple structures to namedtuples
PYTHON-601
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
|
from collections import namedtuple
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
|
|
||||||
|
BodyAndTail = namedtuple('BodyAndTail', ['body', 'tail', 'total_len'])
|
||||||
|
|
||||||
def body_and_tail(data):
|
def body_and_tail(data):
|
||||||
l = len(data)
|
l = len(data)
|
||||||
nblocks = l // 16
|
nblocks = l // 16
|
||||||
@@ -10,16 +13,16 @@ def body_and_tail(data):
|
|||||||
if nblocks:
|
if nblocks:
|
||||||
# we use '<', specifying little-endian byte order for data bigger than
|
# we use '<', specifying little-endian byte order for data bigger than
|
||||||
# a byte so behavior is the same on little- and big-endian platforms
|
# a byte so behavior is the same on little- and big-endian platforms
|
||||||
return (
|
return BodyAndTail(
|
||||||
struct.unpack_from('<' + ('qq' * nblocks), data),
|
body=struct.unpack_from('<' + ('qq' * nblocks), data),
|
||||||
struct.unpack_from('b' * tail, data, -tail),
|
tail=struct.unpack_from('b' * tail, data, -tail),
|
||||||
l
|
total_len=l
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return (
|
return BodyAndTail(
|
||||||
tuple(),
|
body=tuple(),
|
||||||
struct.unpack_from('b' * tail, data, -tail),
|
tail=struct.unpack_from('b' * tail, data, -tail),
|
||||||
l
|
total_len=l
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user