1- # cython: boundscheck=False
2- # cython: wraparound=False
3- # cython: overflowcheck=False
4- # cython: cdivision=True
5-
61import struct
7- import numpy as np
82
93from numcodecs.abc import Codec
104from numcodecs.compat import ensure_contiguous_ndarray
@@ -14,6 +8,7 @@ from libc.stdint cimport uint8_t, uint16_t, uint32_t
148cdef extern from " _fletcher.c" :
159 uint32_t H5_checksum_fletcher32(const void * _data, size_t _len)
1610
11+
1712class Fletcher32 (Codec ):
1813 """ The fletcher checksum with 16-bit words and 32-bit output
1914
@@ -26,12 +21,14 @@ class Fletcher32(Codec):
2621 codec_id = " fletcher32"
2722
2823 def encode (self , buf ):
24+ """ Return buffer plus 4-byte fletcher checksum"""
2925 buf = ensure_contiguous_ndarray(buf).ravel().view(' uint8' )
3026 cdef const uint8_t[::1 ] b_ptr = buf
3127 val = H5_checksum_fletcher32(& b_ptr[0 ], buf.nbytes)
3228 return buf.tobytes() + struct .pack(" <I" , val)
3329
3430 def decode (self , buf , out = None ):
31+ """ Check fletcher checksum, and return buffer without it"""
3532 b = ensure_contiguous_ndarray(buf).view(' uint8' )
3633 cdef const uint8_t[::1 ] b_ptr = b
3734 val = H5_checksum_fletcher32(& b_ptr[0 ], b.nbytes - 4 )
0 commit comments