[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen staging] golang/xenlight: re-factor Uuid type implementation



commit 685001ee947f0c37ebf8c6bd9ad99bd570221a63
Author:     Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>
AuthorDate: Mon Dec 16 18:08:06 2019 +0000
Commit:     George Dunlap <george.dunlap@xxxxxxxxxx>
CommitDate: Mon Dec 16 18:08:06 2019 +0000

    golang/xenlight: re-factor Uuid type implementation
    
    Re-define Uuid as [16]byte and implement fromC, toC, and String functions.
    
    Signed-off-by: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>
    Reviewed-by: George Dunlap <george.dunlap@xxxxxxxxxx>
---
 tools/golang/xenlight/xenlight.go | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/tools/golang/xenlight/xenlight.go 
b/tools/golang/xenlight/xenlight.go
index 6b87bf857d..f9c2f84c81 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -86,7 +86,38 @@ type Devid int
 
 type MemKB uint64
 
-type Uuid C.libxl_uuid
+// Uuid is a domain UUID.
+type Uuid [16]byte
+
+// String formats a Uuid in the form "xxxx-xx-xx-xx-xxxxxx".
+func (u Uuid) String() string {
+       s := "%x%x%x%x-%x%x-%x%x-%x%x-%x%x%x%x%x%x"
+       opts := make([]interface{}, 16)
+
+       for i, v := range u {
+               opts[i] = v
+       }
+
+       return fmt.Sprintf(s, opts...)
+}
+
+func (u *Uuid) fromC(c *C.libxl_uuid) error {
+       for i := range *u {
+               u[i] = byte(c.uuid[i])
+       }
+
+       return nil
+}
+
+func (u *Uuid) toC() (C.libxl_uuid, error) {
+       var c C.libxl_uuid
+
+       for i, v := range u {
+               c.uuid[i] = C.uint8_t(v)
+       }
+
+       return c, nil
+}
 
 // defboolVal represents a defbool value.
 type defboolVal int
@@ -495,7 +526,7 @@ type Dominfo struct {
 func (cdi *C.libxl_dominfo) toGo() (di *Dominfo) {
 
        di = &Dominfo{}
-       di.Uuid = Uuid(cdi.uuid)
+       di.Uuid.fromC(&cdi.uuid)
        di.Domid = Domid(cdi.domid)
        di.Ssidref = uint32(cdi.ssidref)
        di.SsidLabel = C.GoString(cdi.ssid_label)
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.