picop.cybytes#
Fast bytes accessors.
- class picop.cybytes.BytesWriter#
Bases:
objectIncremental
bytesbuilder over CPython’s writer.max_sizeis a capacity hint, honoured on CPython 3.8-3.14 (internal_PyBytesWriter) and on 3.15+ (PyBytesWriter_Create+PyBytesWriter_Resize(writer, 0)reserve capacity without any pre-written content).size()reports bytes written;grow(),data()andfinish_with_size()are cimport-only direct-fill helpers.- __enter__()#
Return the writer.
- Return type:
- write(data)#
Append
data(bytes or bytearray) to the writer.
- picop.cybytes.bytes_bytearray_eq(a, b)#
Return True if
bytes/bytearraycontents match.Notes
Either argument order is accepted; compares with
memcmpafter a length gate.
- picop.cybytes.bytes_check_exact(p)#
Return True if
type(p) is bytes(PyBytes_CheckExact).
- picop.cybytes.bytes_contains(haystack, needle)#
Return True if
needleis inhaystack.Notes
Uses
memchr/memmemunder 256B, else the builtininpath.
- picop.cybytes.bytes_endswith(s, suffix)#
Return True if typed
sends withsuffix.Notes
Length gate plus tail
memcmpon the typed suffix region.
- picop.cybytes.bytes_eq(a, b)#
Return True if
a == b.Notes
Identity/len short-circuit plus
memcmpon typedbytes.
- picop.cybytes.bytes_from_object(o)#
Return
bytesfrom a buffer-protocol object (PyBytes_FromObject).
- picop.cybytes.bytes_len(b)#
Return
len(b)viaPyBytes_GET_SIZE.
- picop.cybytes.bytes_ne(a, b)#
Return True if
a != b(inverse ofbytes_eq).
- picop.cybytes.bytes_size(b)#
Return
len(b)via checkedPyBytes_Size.Notes
Prefer
bytes_lenon a typedbyteshot path.