예제 #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
파일: sequence.go 프로젝트: gward/go-python
// 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))
}