picop.buffers#
Category facade: bytes / bytearray / array / memoryview / buffer / slice.
Typed buffer-adjacent Core helpers. Prefer bytes_len / bytes_contains /
bytes_eq from picop.hot for the common bytes hot path.
See Safety for borrowed C-string footguns.
- picop.buffers.bytes_check(p)#
Return True if
pisbytesor a subtype (PyBytes_Check). :type p:object:param p:- Return type:
- picop.buffers.bytes_check_exact(p)#
Return True if
type(p) is bytes(PyBytes_CheckExact). :type p:object:param p:- Return type:
- picop.buffers.bytes_len(b)#
Return
len(b)viaPyBytes_GET_SIZE. :type b:bytes:param b:- Return type:
- picop.buffers.bytes_size(b)#
Return
len(b)via checkedPyBytes_Size.Notes
Prefer
bytes_lenon a typedbyteshot path.
- picop.buffers.bytes_contains(haystack, needle)#
Return True if
needleis inhaystack.Notes
Uses
memchr/memmemunder 256B, else the builtininpath.
- picop.buffers.bytes_bytearray_eq(a, b)#
Return True if
bytes/bytearraycontents match.Notes
Either argument order is accepted; compares with
memcmpafter a length gate.
- picop.buffers.bytes_eq(a, b)#
Return True if
a == b.Notes
Identity/len short-circuit plus
memcmpon typedbytes.
- picop.buffers.bytes_ne(a, b)#
Return True if
a != b(inverse ofbytes_eq). :type a:bytes:param a: :type b:bytes:param b:- Return type:
- picop.buffers.bytes_startswith(s, prefix)#
Return True if typed
sbegins withprefix.Notes
Length gate plus
memcmpon the typed prefix region.
- picop.buffers.bytes_endswith(s, suffix)#
Return True if typed
sends withsuffix.Notes
Length gate plus tail
memcmpon the typed suffix region.
- picop.buffers.bytearray_check(p)#
Return True if
pis abytearrayor subtype (PyByteArray_Check). :type p:object:param p:- Return type:
- picop.buffers.bytearray_check_exact(p)#
Return True if
type(p) is bytearray(PyByteArray_CheckExact). :type p:object:param p:- Return type:
- picop.buffers.bytearray_eq(a, b)#
Return True if typed
bytearrayvalues are equal.Notes
Identity/len short-circuit plus
memcmp.
- picop.buffers.bytearray_ne(a, b)#
Return True if typed
bytearrayvalues differ (not bytearray_eq). :type a:bytearray:param a: :type b:bytearray:param b:- Return type:
- picop.buffers.bytearray_contains(haystack, needle)#
Return True if
needleis found in typedhaystack.Notes
Mirrors
bytes_containssearch strategy on a typedbytearray.
- picop.buffers.bytearray_len(ba)#
Return
len(ba)viaPyByteArray_GET_SIZE. :type ba:bytearray:param ba:- Return type:
- picop.buffers.bytearray_size(ba)#
Return
len(ba)via checkedPyByteArray_Size.Notes
Prefer
bytearray_lenon a typedbytearrayhot path.
- picop.buffers.array_check(p)#
Return True if
pis anarray.array(isinstance). :type p:object:param p:- Return type:
- picop.buffers.array_check_exact(p)#
Return True if
type(p) is array.array. :type p:object:param p:- Return type:
- picop.buffers.array_eq(a, b)#
Return True if typed
array.arrayvalues are equal.Notes
Compares typecode/len then
memcmp.
- picop.buffers.array_ne(a, b)#
Return True if typed
array.arrayvalues differ (not array_eq). :type a:array:param a: :type b:array:param b:- Return type:
- picop.buffers.array_clone(template, length, zero=True)#
Return a new array like
templatewithlengthitems.Notes
Optionally zero-fills the new buffer when
zerois true.
- picop.buffers.array_zero(a)#
Zero all elements of
aviamemset.Notes
Returns
0on success; errors raise. Do not use the status int as a bool.
- picop.buffers.memoryview_check(p)#
Return True if
pis amemoryview(PyMemoryView_Check). :type p:object:param p:- Return type:
- picop.buffers.memoryview_eq(a, b)#
Return True if views are equal.
Notes
C-contiguous buffers use a
memcmpfast path; otherwise falls back to richcompare.- Parameters:
a (
memoryview)b (
memoryview)
- Return type:
- picop.buffers.memoryview_ne(a, b)#
Return True if views differ.
Notes
Inverse of
memoryview_eq; same contig/richcompare rules.- Parameters:
a (
memoryview)b (
memoryview)
- Return type:
- picop.buffers.memoryview_from_object(obj)#
Return
memoryview(obj)viaPyMemoryView_FromObject. :type obj:object:param obj:- Return type:
- picop.buffers.buf_check(obj)#
Return True if
objsupports the buffer protocol (PyObject_CheckBuffer). :type obj:object:param obj:- Return type:
- picop.buffers.buf_eq(a, b)#
Return True if buffer-protocol views are equal.
Notes
C-contiguous buffers use
memcmp; otherwise memoryview richcompare. Format/size mismatch yieldsFalse.
- picop.buffers.slice_check(p)#
Return True if
pis aslice(PySlice_Check). :type p:object:param p:- Return type:
- picop.buffers.slice_eq(a, b)#
Return True if slices are equal.
Notes
Identity short-circuit plus richcompare.