[v2,08/22] golang/xenlight: define MsVmGenid builtin type
diff mbox series

Message ID 25ebb96e473b1405d202f4334725fd68cb882c38.1573840474.git.rosbrookn@ainfosec.com
State New
Headers show
Series
  • generated Go libxl bindings using IDL
Related show

Commit Message

Nick Rosbrook Nov. 15, 2019, 7:44 p.m. UTC
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>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
---
 tools/golang/xenlight/xenlight.go | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

George Dunlap Dec. 4, 2019, 5 p.m. UTC | #1
On 11/15/19 7:44 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>
> Reviewed-by: George Dunlap <george.dunlap@citrix.com>
> ---
>  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 eb0d309543..108b50124a 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)
> +	}

Sorry to come back to this -- is there a reason we can't just do
something like this?

func (u *Uuid) fromC(c *C.libxl_uuid) error {
	for i := range *u {
		u[i] = byte(c.uuid[i])
	}

	return nil
}

I.e., the only reason we seem to be doing the cast is to have an
appropriate type to range over; but we can just range over `*u` instead.

 -George

Patch
diff mbox series

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index eb0d309543..108b50124a 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