File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,23 @@ func PyByteArray_AsString(self *PyObject) string {
89
89
return C .GoString (c_str )
90
90
}
91
91
92
+ // PyByteArray_AsBytes returns the contents of bytearray as []bytes
93
+ func PyByteArray_AsBytes (self * PyObject ) []byte {
94
+ length := C ._gopy_PyByteArray_GET_SIZE (topy (self ))
95
+ c_str := C .PyByteArray_AsString (topy (self ))
96
+ return C .GoBytes (unsafe .Pointer (c_str ),C .int (length ))
97
+ }
98
+
99
+ // PyByteArray_AsBytesN returns the contents of bytearray as []bytes, size length
100
+ func PyByteArray_AsBytesN (self * PyObject , length int ) []byte {
101
+ blength := int (C ._gopy_PyByteArray_GET_SIZE (topy (self )))
102
+ if (blength < length ) || (length < 0 ) {
103
+ panic ("bytearray length out of range" )
104
+ }
105
+ c_str := C .PyByteArray_AsString (topy (self ))
106
+ return C .GoBytes (unsafe .Pointer (c_str ),C .int (length ))
107
+ }
108
+
92
109
// int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
93
110
// Resize the internal buffer of bytearray to len.
94
111
func PyByteArray_Resize (self * PyObject , sz int ) error {
You can’t perform that action at this time.
0 commit comments