Пример #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))
}
Пример #2
0
// char* PyByteArray_AsString(PyObject *bytearray)
// Return the contents of bytearray as a char array after checking for a NULL pointer.
func PyByteArray_AsString(self *PyObject) string {
	c_str := C.PyByteArray_AsString(topy(self))
	return C.GoString(c_str)
}
Пример #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))
}