@@ -277,6 +277,25 @@ otherwise parameter is a python list that we copy from
277277 g .pywrap .Outdent ()
278278 g .pywrap .Outdent ()
279279 }
280+
281+ if slNm == "Slice_byte" {
282+ g .pywrap .Printf ("@staticmethod\n " )
283+ g .pywrap .Printf ("def from_bytes(value):\n " )
284+ g .pywrap .Indent ()
285+ g .pywrap .Printf (`"""Create a Go []byte object from a Python bytes object"""
286+ ` )
287+ g .pywrap .Printf ("handle = _%s_from_bytes(value)\n " , qNm )
288+ g .pywrap .Printf ("return Slice_byte(handle=handle)\n " )
289+ g .pywrap .Outdent ()
290+ g .pywrap .Printf ("def __bytes__(self):\n " )
291+ g .pywrap .Indent ()
292+ g .pywrap .Printf (`"""Convert the slice to a bytes object."""
293+ ` )
294+ g .pywrap .Printf ("return _%s_to_bytes(self.handle)\n " , qNm )
295+ g .pywrap .Outdent ()
296+ g .pywrap .Outdent ()
297+
298+ }
280299 }
281300
282301 if ! extTypes || ! pyWrapOnly {
@@ -367,6 +386,33 @@ otherwise parameter is a python list that we copy from
367386
368387 g .pybuild .Printf ("mod.add_function('%s_append', None, [param('%s', 'handle'), param('%s', 'value'%s)])\n " , slNm , PyHandle , esym .cpyname , transfer_ownership )
369388 }
389+
390+ if slNm == "Slice_byte" {
391+ g .gofile .Printf ("//export Slice_byte_from_bytes\n " )
392+ g .gofile .Printf ("func Slice_byte_from_bytes(o *C.PyObject) CGoHandle {\n " )
393+ g .gofile .Indent ()
394+ g .gofile .Printf ("size := C.PyBytes_Size(o)\n " )
395+ g .gofile .Printf ("ptr := unsafe.Pointer(C.PyBytes_AsString(o))\n " )
396+ g .gofile .Printf ("data := make([]byte, size)\n " )
397+ g .gofile .Printf ("tmp := unsafe.Slice((*byte)(ptr), size)\n " )
398+ g .gofile .Printf ("copy(data, tmp)\n " )
399+ g .gofile .Printf ("return handleFromPtr_Slice_byte(&data)\n " )
400+ g .gofile .Outdent ()
401+ g .gofile .Printf ("}\n \n " )
402+
403+ g .gofile .Printf ("//export Slice_byte_to_bytes\n " )
404+ g .gofile .Printf ("func Slice_byte_to_bytes(handle CGoHandle) *C.PyObject {\n " )
405+ g .gofile .Indent ()
406+ g .gofile .Printf ("s := deptrFromHandle_Slice_byte(handle)\n " )
407+ g .gofile .Printf ("ptr := unsafe.Pointer(&s[0])\n " )
408+ g .gofile .Printf ("size := len(s)\n " )
409+ g .gofile .Printf ("return C.PyBytes_FromStringAndSize((*C.char)(ptr), C.long(size))\n " )
410+ g .gofile .Outdent ()
411+ g .gofile .Printf ("}\n \n " )
412+
413+ g .pybuild .Printf ("mod.add_function('Slice_byte_from_bytes', retval('%s'%s), [param('PyObject*', 'o', transfer_ownership=False)])\n " , PyHandle , caller_owns_ret )
414+ g .pybuild .Printf ("mod.add_function('Slice_byte_to_bytes', retval('PyObject*', caller_owns_return=True), [param('%s', 'handle')])\n " , PyHandle )
415+ }
370416 }
371417}
372418
0 commit comments