gokeyname = xenlight_golang_fmt_name(keyname)
keytype = ty.keyvar.type.typename
gokeytype = xenlight_golang_fmt_name(keytype)
+ field_name = xenlight_golang_fmt_name('{}_union'.format(keyname))
interface_name = '{}_{}_union'.format(struct_name, keyname)
interface_name = xenlight_golang_fmt_name(interface_name, exported=False)
# Add to list of cases to make for the switch
# statement below.
+ cases[f.name] = (val, f.type)
+
if f.type is None:
continue
- cases[f.name] = val
-
# Define fromC func for 'union' struct.
typename = '{}_{}_union_{}'.format(struct_name,keyname,f.name)
gotypename = xenlight_golang_fmt_name(typename)
# Create switch statement to determine which 'union element'
# to populate in the Go struct.
- for case_name, case_val in cases.items():
+ for case_name, case_tuple in cases.items():
+ (case_val, case_type) = case_tuple
+
s += 'case {}:\n'.format(case_val)
+ if case_type is None:
+ s += "x.{} = nil\n".format(field_name)
+ continue
+
gotype = '{}_{}_union_{}'.format(struct_name,keyname,case_name)
gotype = xenlight_golang_fmt_name(gotype)
goname = '{}_{}'.format(keyname,case_name)
s += 'if err := {}.fromC(xc);'.format(goname)
s += 'err != nil {{\n return fmt.Errorf("converting field {}: %v", err) \n}}\n'.format(goname)
- field_name = xenlight_golang_fmt_name('{}_union'.format(keyname))
s += 'x.{} = {}\n'.format(field_name, goname)
# End switch statement
for f in ty.fields:
key_val = '{}_{}'.format(keytype, f.name)
key_val = xenlight_golang_fmt_name(key_val)
+
+ s += 'case {}:\n'.format(key_val)
+
if f.type is None:
+ s += "break\n"
continue
- s += 'case {}:\n'.format(key_val)
cgotype = '{}_{}_union_{}'.format(struct_name,keyname,f.name)
gotype = xenlight_golang_fmt_name(cgotype)
x.Rref = int(xc.rref)
x.Connection = ChannelConnection(xc.connection)
switch x.Connection {
+ case ChannelConnectionUnknown:
+ x.ConnectionUnion = nil
case ChannelConnectionPty:
var connectionPty ChannelinfoConnectionUnionPty
if err := connectionPty.fromC(xc); err != nil {
return fmt.Errorf("converting field connectionPty: %v", err)
}
x.ConnectionUnion = connectionPty
+ case ChannelConnectionSocket:
+ x.ConnectionUnion = nil
default:
return fmt.Errorf("invalid union key '%v'", x.Connection)
}
xc.rref = C.int(x.Rref)
xc.connection = C.libxl_channel_connection(x.Connection)
switch x.Connection {
+ case ChannelConnectionUnknown:
+ break
case ChannelConnectionPty:
tmp, ok := x.ConnectionUnion.(ChannelinfoConnectionUnionPty)
if !ok {
}
ptyBytes := C.GoBytes(unsafe.Pointer(&pty), C.sizeof_libxl_channelinfo_connection_union_pty)
copy(xc.u[:], ptyBytes)
+ case ChannelConnectionSocket:
+ break
default:
return fmt.Errorf("invalid union key '%v'", x.Connection)
}
return fmt.Errorf("converting field typePvh: %v", err)
}
x.TypeUnion = typePvh
+ case DomainTypeInvalid:
+ x.TypeUnion = nil
default:
return fmt.Errorf("invalid union key '%v'", x.Type)
}
}
pvhBytes := C.GoBytes(unsafe.Pointer(&pvh), C.sizeof_libxl_domain_build_info_type_union_pvh)
copy(xc.u[:], pvhBytes)
+ case DomainTypeInvalid:
+ break
default:
return fmt.Errorf("invalid union key '%v'", x.Type)
}
x.Name = C.GoString(xc.name)
x.Connection = ChannelConnection(xc.connection)
switch x.Connection {
+ case ChannelConnectionUnknown:
+ x.ConnectionUnion = nil
+ case ChannelConnectionPty:
+ x.ConnectionUnion = nil
case ChannelConnectionSocket:
var connectionSocket DeviceChannelConnectionUnionSocket
if err := connectionSocket.fromC(xc); err != nil {
}
xc.connection = C.libxl_channel_connection(x.Connection)
switch x.Connection {
+ case ChannelConnectionUnknown:
+ break
+ case ChannelConnectionPty:
+ break
case ChannelConnectionSocket:
tmp, ok := x.ConnectionUnion.(DeviceChannelConnectionUnionSocket)
if !ok {
return fmt.Errorf("converting field typeDomainShutdown: %v", err)
}
x.TypeUnion = typeDomainShutdown
+ case EventTypeDomainDeath:
+ x.TypeUnion = nil
case EventTypeDiskEject:
var typeDiskEject EventTypeUnionDiskEject
if err := typeDiskEject.fromC(xc); err != nil {
return fmt.Errorf("converting field typeOperationComplete: %v", err)
}
x.TypeUnion = typeOperationComplete
+ case EventTypeDomainCreateConsoleAvailable:
+ x.TypeUnion = nil
default:
return fmt.Errorf("invalid union key '%v'", x.Type)
}
domain_shutdown.shutdown_reason = C.uint8_t(tmp.ShutdownReason)
domain_shutdownBytes := C.GoBytes(unsafe.Pointer(&domain_shutdown), C.sizeof_libxl_event_type_union_domain_shutdown)
copy(xc.u[:], domain_shutdownBytes)
+ case EventTypeDomainDeath:
+ break
case EventTypeDiskEject:
tmp, ok := x.TypeUnion.(EventTypeUnionDiskEject)
if !ok {
operation_complete.rc = C.int(tmp.Rc)
operation_completeBytes := C.GoBytes(unsafe.Pointer(&operation_complete), C.sizeof_libxl_event_type_union_operation_complete)
copy(xc.u[:], operation_completeBytes)
+ case EventTypeDomainCreateConsoleAvailable:
+ break
default:
return fmt.Errorf("invalid union key '%v'", x.Type)
}