forked from DataDog/go-python3
-
Notifications
You must be signed in to change notification settings - Fork 50
/
byte_array.go
61 lines (49 loc) · 2.11 KB
/
byte_array.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Unless explicitly stated otherwise all files in this repository are licensed
under the MIT License.
This product includes software developed at Datadog (https://www.datadoghq.com/).
Copyright 2018 Datadog, Inc.
*/
package python3
/*
#include "Python.h"
#include "macro.h"
*/
import "C"
import "unsafe"
//ByteArray : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Type
var ByteArray = togo((*C.PyObject)(unsafe.Pointer(&C.PyByteArray_Type)))
//PyByteArray_Check : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Check
func PyByteArray_Check(o *PyObject) bool {
return C._go_PyByteArray_Check(toc(o)) != 0
}
//PyByteArray_CheckExact : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_CheckExact
func PyByteArray_CheckExact(o *PyObject) bool {
return C._go_PyByteArray_CheckExact(toc(o)) != 0
}
//PyByteArray_FromObject : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_FromObject
func PyByteArray_FromObject(o *PyObject) *PyObject {
return togo(C.PyByteArray_FromObject(toc(o)))
}
//PyByteArray_FromStringAndSize : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_FromStringAndSize
func PyByteArray_FromStringAndSize(str string) *PyObject {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
return togo(C.PyByteArray_FromStringAndSize(cstr, C.Py_ssize_t(len(str))))
}
//PyByteArray_Concat : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Concat
func PyByteArray_Concat(a, b *PyObject) *PyObject {
return togo(C.PyByteArray_Concat(toc(a), toc(b)))
}
//PyByteArray_Size : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Size
func PyByteArray_Size(o *PyObject) int {
return int(C.PyByteArray_Size(toc(o)))
}
//PyByteArray_AsString : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_AsString
func PyByteArray_AsString(o *PyObject) string {
return C.GoStringN(C.PyByteArray_AsString(toc(o)), C.int(C.PyByteArray_Size(toc(o))))
}
//PyByteArray_Resize : https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Resize
func PyByteArray_Resize(bytearray *PyObject, len int) {
C.PyByteArray_Resize(toc(bytearray), C.Py_ssize_t(len))
}