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

Re: [Xen-devel] [RFC] Generating Go bindings for libxl



George,

> Are you up for taking a stab at something like `gengotypes.py`?

I have was able to make a bit of progress on this over the weekend. I've started
`gengotypes.py` in my branch[1]; the portion which generates `xenlight_types.go`
(the counterpart to _libxl_types.h) is mostly working. 

The main exception is that I am not certain how the `KeyedUnion` type from the 
IDL
should be translated for Go. One option is to do something similar to the 
`oneof` field 
in gRPC's protobuf messages[2]. Essentially, we would define a separate struct 
for each
of the structs that belong to the union. Then, where a union would be used in 
C, we use
an interface type which the previously defined structs implement. E.g.

type isDomainTypeStruct interface {
        isDomainTypeStruct()
}

type domainTypeHVMStruct struct {
        ...
}

func (d domainTypeHVMStruct) isDomainTypeStruct() {}

type DomainBuildInfo struct {
        ...
        Type DomainType
        dts    isDomainTypeStruct
}

It is a bit ugly, but I think it's semantically the closest to 'KeyedUnion'. 
What are your thoughts?

-NR

[1] https://github.com/enr0n/xen/blob/gen-go-types/tools/golang/gengotypes.py
[2] https://developers.google.com/protocol-buffers/docs/proto3#oneof
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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