Ejemplo n.º 1
0
// PyByteArray_AsBytesN returns the contents of bytearray as []bytes, size length
func PyByteArray_AsBytesN(self *PyObject, length int) []byte {
	blength := int(C._gopy_PyByteArray_GET_SIZE(topy(self)))
	if (blength < length) || (length < 0) {
		panic("bytearray length out of range")
	}
	c_str := C.PyByteArray_AsString(topy(self))
	return C.GoBytes(unsafe.Pointer(c_str), C.int(length))
}
Ejemplo n.º 2
0
// Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
// Macro version of PyByteArray_Size().
func PyByteArray_GET_SIZE(self *PyObject) int {
	return int(C._gopy_PyByteArray_GET_SIZE(topy(self)))
}
Ejemplo n.º 3
0
// PyByteArray_AsBytes returns the contents of bytearray as []bytes
func PyByteArray_AsBytes(self *PyObject) []byte {
	length := C._gopy_PyByteArray_GET_SIZE(topy(self))
	c_str := C.PyByteArray_AsString(topy(self))
	return C.GoBytes(unsafe.Pointer(c_str), C.int(length))
}