1 /** 2 * Mirror _bytearrayobject.h 3 * 4 * Type PyByteArrayObject represents a mutable array of bytes. 5 * The Python API is that of a sequence; 6 * the bytes are mapped to ints in [0, 256$(RPAREN). 7 * Bytes are not characters; they may be used to encode characters. 8 * The only way to go between bytes and str/unicode is via encoding 9 * and decoding. 10 * For the convenience of C programmers, the bytes type is considered 11 * to contain a char pointer, not an unsigned char pointer. 12 */ 13 module deimos.python.bytearrayobject; 14 15 import deimos.python.pyport; 16 import deimos.python.object; 17 18 extern(C): 19 // Python-header-file: Include/bytearrayobject.h: 20 21 version(Python_2_6_Or_Later) { 22 /// subclass of PyVarObject 23 /// Availability: >= 2.6 24 struct PyByteArrayObject { 25 mixin PyObject_VAR_HEAD!(); 26 version(Python_3_4_Or_Later) { 27 /// _ 28 Py_ssize_t ob_alloc; 29 /// _ 30 char* ob_bytes; 31 /// _ 32 char* ob_start; 33 /// _ 34 int ob_exports; 35 }else{ 36 /** how many buffer exports */ 37 int ob_exports; 38 /** How many bytes allocated */ 39 Py_ssize_t ob_alloc; 40 /// _ 41 char* ob_bytes; 42 } 43 44 } 45 46 /* Type object */ 47 /// Availability: >= 2.6 48 mixin(PyAPI_DATA!"PyTypeObject PyByteArray_Type"); 49 /// Availability: >= 2.6 50 mixin(PyAPI_DATA!"PyTypeObject PyByteArrayIter_Type"); 51 52 /** Type check macro 53 Availability: >= 2.6 54 */ 55 int PyByteArray_Check()(PyObject* self) { 56 return PyObject_TypeCheck(self, &PyByteArray_Type); 57 } 58 59 /** Type check macro 60 Availability: >= 2.6 61 */ 62 int PyByteArray_CheckExact()(PyObject* self) { 63 return Py_TYPE(self) == &PyByteArray_Type; 64 } 65 66 /* Direct API functions */ 67 /// Availability: >= 2.6 68 PyObject* PyByteArray_FromObject(PyObject*); 69 /// Availability: >= 2.6 70 PyObject* PyByteArray_Concat(PyObject*, PyObject*); 71 /// Availability: >= 2.6 72 PyObject* PyByteArray_FromStringAndSize(const char*, Py_ssize_t); 73 /// Availability: >= 2.6 74 Py_ssize_t PyByteArray_Size(PyObject*); 75 /// Availability: >= 2.6 76 char* PyByteArray_AsString(PyObject*); 77 /// Availability: >= 2.6 78 int PyByteArray_Resize(PyObject*, Py_ssize_t); 79 /// template trading safety for speed 80 /// Availability: >= 2.6 81 char* PyByteArray_AS_STRING()(PyObject* self) { 82 assert(PyByteArray_Check(self)); 83 if(Py_SIZE(self)) { 84 return (cast(PyByteArrayObject*) self).ob_bytes; 85 }else{ 86 return "\0".ptr; 87 } 88 } 89 /// template trading safety for speed 90 /// Availability: >= 2.6 91 auto PyByteArray_GET_SIZE()(PyObject* self) { 92 assert(PyByteArray_Check(self)); 93 return Py_SIZE(cast(PyVarObject*) self); 94 } 95 }