Message ID | 87f082bdf06e820e911256138a7380d0cf7019a2.1570456846.git.rosbrookn@ainfosec.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | generated Go libxl bindings using IDL | expand |
On 10/7/19 4:12 PM, Nick Rosbrook wrote: > From: Nick Rosbrook <rosbrookn@ainfosec.com> > > Define MsVmGenid as [int(C.LIBXL_MS_VM_GENID_LEN)]byte and implement fromC and toC functions. > > Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com> > --- > Cc: George Dunlap <george.dunlap@citrix.com> > Cc: Ian Jackson <ian.jackson@eu.citrix.com> > Cc: Wei Liu <wl@xen.org> > > tools/golang/xenlight/xenlight.go | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go > index 3b7824b284..6aca5b89c0 100644 > --- a/tools/golang/xenlight/xenlight.go > +++ b/tools/golang/xenlight/xenlight.go > @@ -216,6 +216,29 @@ func (mac *Mac) toC() (C.libxl_mac, error) { > return cmac, nil > } > > +// MsVmGenid represents a libxl_ms_vm_genid. > +type MsVmGenid [int(C.LIBXL_MS_VM_GENID_LEN)]byte > + > +func (mvg *MsVmGenid) fromC(cmvg *C.libxl_ms_vm_genid) error { > + b := (*[int(C.LIBXL_MS_VM_GENID_LEN)]C.uint8_t)(unsafe.Pointer(&cmvg.bytes[0])) > + > + for i, v := range b { > + mvg[i] = byte(v) > + } It's slightly annoying to have to do this loop, but I guess given that we have to technically cast each element of the array. Hopefully the compiler will eventually be able to figure out what's going on here and just do a memcpy. > + > + return nil > +} > + > +func (mvg *MsVmGenid) toC() (C.libxl_ms_vm_genid, error) { Hmm, I guess we want a pointer receiver here to make sure we don't end up doing a 16-byte copy. Reviewed-by: George Dunlap <george.dunlap@citrix.com> -George
diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 3b7824b284..6aca5b89c0 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -216,6 +216,29 @@ func (mac *Mac) toC() (C.libxl_mac, error) { return cmac, nil } +// MsVmGenid represents a libxl_ms_vm_genid. +type MsVmGenid [int(C.LIBXL_MS_VM_GENID_LEN)]byte + +func (mvg *MsVmGenid) fromC(cmvg *C.libxl_ms_vm_genid) error { + b := (*[int(C.LIBXL_MS_VM_GENID_LEN)]C.uint8_t)(unsafe.Pointer(&cmvg.bytes[0])) + + for i, v := range b { + mvg[i] = byte(v) + } + + return nil +} + +func (mvg *MsVmGenid) toC() (C.libxl_ms_vm_genid, error) { + var cmvg C.libxl_ms_vm_genid + + for i, v := range mvg { + cmvg.bytes[i] = C.uint8_t(v) + } + + return cmvg, nil +} + type Context struct { ctx *C.libxl_ctx logger *C.xentoollog_logger_stdiostream