...

Source file src/victortoso.com/qapi-go/pkg/qapi/unions.go

Documentation: victortoso.com/qapi-go/pkg/qapi

     1  package qapi
     2  
     3  import (
     4  	"encoding/json"
     5  	"errors"
     6  	"fmt"
     7  	"strings"
     8  )
     9  
    10  // Captures the address of a socket, which could also be a named file descriptor
    11  //
    12  // Note: This type is deprecated in favor of SocketAddress.  The
    13  // difference between SocketAddressLegacy and SocketAddress is that the
    14  // latter is has fewer {} on the wire.
    15  //
    16  // Since: 1.3
    17  type SocketAddressLegacyBase struct {
    18  	Type SocketAddressType `json:"type"`
    19  }
    20  
    21  // Captures the address of a socket, which could also be a named file descriptor
    22  //
    23  // Note: This type is deprecated in favor of SocketAddress.  The
    24  // difference between SocketAddressLegacy and SocketAddress is that the
    25  // latter is has fewer {} on the wire.
    26  //
    27  // Since: 1.3
    28  type SocketAddressLegacy struct {
    29  	// Base type for this struct
    30  	SocketAddressLegacyBase
    31  	// Value based on @type, possible types:
    32  	// * InetSocketAddressWrapper
    33  	// * UnixSocketAddressWrapper
    34  	// * VsockSocketAddressWrapper
    35  	// * StringWrapper
    36  	Value Any
    37  }
    38  
    39  func (s SocketAddressLegacy) MarshalJSON() ([]byte, error) {
    40  	base, err := json.Marshal(s.SocketAddressLegacyBase)
    41  	if err != nil {
    42  		return nil, err
    43  	}
    44  
    45  	typestr := fmt.Sprintf("%T", s.Value)
    46  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
    47  
    48  	// "The branches need not cover all possible enum values"
    49  	// This means that on Marshal, we can safely ignore empty values
    50  	if typestr == "<nil>" {
    51  		return []byte(base), nil
    52  	}
    53  
    54  	// Runtime check for supported value types
    55  	if typestr != "StringWrapper" &&
    56  		typestr != "InetSocketAddressWrapper" &&
    57  		typestr != "UnixSocketAddressWrapper" &&
    58  		typestr != "VsockSocketAddressWrapper" {
    59  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
    60  	}
    61  	value, err := json.Marshal(s.Value)
    62  	if err != nil {
    63  		return nil, err
    64  	}
    65  
    66  	// Workaround to avoid checking s.Value being empty
    67  	if string(value) == "{}" {
    68  		return []byte(base), nil
    69  	}
    70  
    71  	// Removes the last '}' from base and the first '{' from value, in order to
    72  	// return a single JSON object.
    73  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
    74  	return []byte(result), nil
    75  }
    76  
    77  func (s *SocketAddressLegacy) UnmarshalJSON(data []byte) error {
    78  
    79  	var base SocketAddressLegacyBase
    80  	if err := json.Unmarshal(data, &base); err != nil {
    81  		return err
    82  	}
    83  	s.SocketAddressLegacyBase = base
    84  
    85  	switch base.Type {
    86  	case SocketAddressTypeFd:
    87  		value := StringWrapper{}
    88  		if err := json.Unmarshal(data, &value); err != nil {
    89  			return err
    90  		}
    91  		s.Value = value
    92  	case SocketAddressTypeInet:
    93  		value := InetSocketAddressWrapper{}
    94  		if err := json.Unmarshal(data, &value); err != nil {
    95  			return err
    96  		}
    97  		s.Value = value
    98  	case SocketAddressTypeUnix:
    99  		value := UnixSocketAddressWrapper{}
   100  		if err := json.Unmarshal(data, &value); err != nil {
   101  			return err
   102  		}
   103  		s.Value = value
   104  	case SocketAddressTypeVsock:
   105  		value := VsockSocketAddressWrapper{}
   106  		if err := json.Unmarshal(data, &value); err != nil {
   107  			return err
   108  		}
   109  		s.Value = value
   110  
   111  	default:
   112  		fmt.Println("Failed to decode SocketAddressLegacy", base.Type)
   113  	}
   114  
   115  	return nil
   116  }
   117  
   118  // Captures the address of a socket, which could also be a named file
   119  // descriptor
   120  //
   121  // Since: 2.9
   122  type SocketAddressBase struct {
   123  	Type SocketAddressType `json:"type"` // Transport type
   124  }
   125  
   126  // Captures the address of a socket, which could also be a named file
   127  // descriptor
   128  //
   129  // Since: 2.9
   130  type SocketAddress struct {
   131  	// Base type for this struct
   132  	SocketAddressBase
   133  	// Value based on @type, possible types:
   134  	// * InetSocketAddress
   135  	// * UnixSocketAddress
   136  	// * VsockSocketAddress
   137  	// * String
   138  	Value Any
   139  }
   140  
   141  func (s SocketAddress) MarshalJSON() ([]byte, error) {
   142  	base, err := json.Marshal(s.SocketAddressBase)
   143  	if err != nil {
   144  		return nil, err
   145  	}
   146  
   147  	typestr := fmt.Sprintf("%T", s.Value)
   148  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
   149  
   150  	// "The branches need not cover all possible enum values"
   151  	// This means that on Marshal, we can safely ignore empty values
   152  	if typestr == "<nil>" {
   153  		return []byte(base), nil
   154  	}
   155  
   156  	// Runtime check for supported value types
   157  	if typestr != "String" &&
   158  		typestr != "InetSocketAddress" &&
   159  		typestr != "UnixSocketAddress" &&
   160  		typestr != "VsockSocketAddress" {
   161  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
   162  	}
   163  	value, err := json.Marshal(s.Value)
   164  	if err != nil {
   165  		return nil, err
   166  	}
   167  
   168  	// Workaround to avoid checking s.Value being empty
   169  	if string(value) == "{}" {
   170  		return []byte(base), nil
   171  	}
   172  
   173  	// Removes the last '}' from base and the first '{' from value, in order to
   174  	// return a single JSON object.
   175  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
   176  	return []byte(result), nil
   177  }
   178  
   179  func (s *SocketAddress) UnmarshalJSON(data []byte) error {
   180  
   181  	var base SocketAddressBase
   182  	if err := json.Unmarshal(data, &base); err != nil {
   183  		return err
   184  	}
   185  	s.SocketAddressBase = base
   186  
   187  	switch base.Type {
   188  	case SocketAddressTypeFd:
   189  		value := String{}
   190  		if err := json.Unmarshal(data, &value); err != nil {
   191  			return err
   192  		}
   193  		s.Value = value
   194  	case SocketAddressTypeInet:
   195  		value := InetSocketAddress{}
   196  		if err := json.Unmarshal(data, &value); err != nil {
   197  			return err
   198  		}
   199  		s.Value = value
   200  	case SocketAddressTypeUnix:
   201  		value := UnixSocketAddress{}
   202  		if err := json.Unmarshal(data, &value); err != nil {
   203  			return err
   204  		}
   205  		s.Value = value
   206  	case SocketAddressTypeVsock:
   207  		value := VsockSocketAddress{}
   208  		if err := json.Unmarshal(data, &value); err != nil {
   209  			return err
   210  		}
   211  		s.Value = value
   212  
   213  	default:
   214  		fmt.Println("Failed to decode SocketAddress", base.Type)
   215  	}
   216  
   217  	return nil
   218  }
   219  
   220  // Information about a guest panic
   221  //
   222  // Since: 2.9
   223  type GuestPanicInformationBase struct {
   224  	Type GuestPanicInformationType `json:"type"` // Crash type that defines the hypervisor specific information
   225  }
   226  
   227  // Information about a guest panic
   228  //
   229  // Since: 2.9
   230  type GuestPanicInformation struct {
   231  	// Base type for this struct
   232  	GuestPanicInformationBase
   233  	// Value based on @type, possible types:
   234  	// * GuestPanicInformationHyperV
   235  	// * GuestPanicInformationS390
   236  	Value Any
   237  }
   238  
   239  func (s GuestPanicInformation) MarshalJSON() ([]byte, error) {
   240  	base, err := json.Marshal(s.GuestPanicInformationBase)
   241  	if err != nil {
   242  		return nil, err
   243  	}
   244  
   245  	typestr := fmt.Sprintf("%T", s.Value)
   246  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
   247  
   248  	// "The branches need not cover all possible enum values"
   249  	// This means that on Marshal, we can safely ignore empty values
   250  	if typestr == "<nil>" {
   251  		return []byte(base), nil
   252  	}
   253  
   254  	// Runtime check for supported value types
   255  	if typestr != "GuestPanicInformationHyperV" &&
   256  		typestr != "GuestPanicInformationS390" {
   257  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
   258  	}
   259  	value, err := json.Marshal(s.Value)
   260  	if err != nil {
   261  		return nil, err
   262  	}
   263  
   264  	// Workaround to avoid checking s.Value being empty
   265  	if string(value) == "{}" {
   266  		return []byte(base), nil
   267  	}
   268  
   269  	// Removes the last '}' from base and the first '{' from value, in order to
   270  	// return a single JSON object.
   271  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
   272  	return []byte(result), nil
   273  }
   274  
   275  func (s *GuestPanicInformation) UnmarshalJSON(data []byte) error {
   276  
   277  	var base GuestPanicInformationBase
   278  	if err := json.Unmarshal(data, &base); err != nil {
   279  		return err
   280  	}
   281  	s.GuestPanicInformationBase = base
   282  
   283  	switch base.Type {
   284  	case GuestPanicInformationTypeHyperV:
   285  		value := GuestPanicInformationHyperV{}
   286  		if err := json.Unmarshal(data, &value); err != nil {
   287  			return err
   288  		}
   289  		s.Value = value
   290  	case GuestPanicInformationTypeS390:
   291  		value := GuestPanicInformationS390{}
   292  		if err := json.Unmarshal(data, &value); err != nil {
   293  			return err
   294  		}
   295  		s.Value = value
   296  
   297  	default:
   298  		fmt.Println("Failed to decode GuestPanicInformation", base.Type)
   299  	}
   300  
   301  	return nil
   302  }
   303  
   304  // The options that are available for all encryption formats
   305  // when opening an existing volume
   306  //
   307  // Since: 2.6
   308  type QCryptoBlockOpenOptions struct {
   309  	// Base type for this struct
   310  	QCryptoBlockOptionsBase
   311  	// Value based on @format, possible types:
   312  	// * QCryptoBlockOptionsQCow
   313  	// * QCryptoBlockOptionsLUKS
   314  	Value Any
   315  }
   316  
   317  func (s QCryptoBlockOpenOptions) MarshalJSON() ([]byte, error) {
   318  	base, err := json.Marshal(s.QCryptoBlockOptionsBase)
   319  	if err != nil {
   320  		return nil, err
   321  	}
   322  
   323  	typestr := fmt.Sprintf("%T", s.Value)
   324  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
   325  
   326  	// "The branches need not cover all possible enum values"
   327  	// This means that on Marshal, we can safely ignore empty values
   328  	if typestr == "<nil>" {
   329  		return []byte(base), nil
   330  	}
   331  
   332  	// Runtime check for supported value types
   333  	if typestr != "QCryptoBlockOptionsLUKS" &&
   334  		typestr != "QCryptoBlockOptionsQCow" {
   335  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
   336  	}
   337  	value, err := json.Marshal(s.Value)
   338  	if err != nil {
   339  		return nil, err
   340  	}
   341  
   342  	// Workaround to avoid checking s.Value being empty
   343  	if string(value) == "{}" {
   344  		return []byte(base), nil
   345  	}
   346  
   347  	// Removes the last '}' from base and the first '{' from value, in order to
   348  	// return a single JSON object.
   349  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
   350  	return []byte(result), nil
   351  }
   352  
   353  func (s *QCryptoBlockOpenOptions) UnmarshalJSON(data []byte) error {
   354  
   355  	var base QCryptoBlockOptionsBase
   356  	if err := json.Unmarshal(data, &base); err != nil {
   357  		return err
   358  	}
   359  	s.QCryptoBlockOptionsBase = base
   360  
   361  	switch base.Format {
   362  	case QCryptoBlockFormatLuks:
   363  		value := QCryptoBlockOptionsLUKS{}
   364  		if err := json.Unmarshal(data, &value); err != nil {
   365  			return err
   366  		}
   367  		s.Value = value
   368  	case QCryptoBlockFormatQcow:
   369  		value := QCryptoBlockOptionsQCow{}
   370  		if err := json.Unmarshal(data, &value); err != nil {
   371  			return err
   372  		}
   373  		s.Value = value
   374  
   375  	default:
   376  		fmt.Println("Failed to decode QCryptoBlockOpenOptions", base.Format)
   377  	}
   378  
   379  	return nil
   380  }
   381  
   382  // The options that are available for all encryption formats
   383  // when initializing a new volume
   384  //
   385  // Since: 2.6
   386  type QCryptoBlockCreateOptions struct {
   387  	// Base type for this struct
   388  	QCryptoBlockOptionsBase
   389  	// Value based on @format, possible types:
   390  	// * QCryptoBlockOptionsQCow
   391  	// * QCryptoBlockCreateOptionsLUKS
   392  	Value Any
   393  }
   394  
   395  func (s QCryptoBlockCreateOptions) MarshalJSON() ([]byte, error) {
   396  	base, err := json.Marshal(s.QCryptoBlockOptionsBase)
   397  	if err != nil {
   398  		return nil, err
   399  	}
   400  
   401  	typestr := fmt.Sprintf("%T", s.Value)
   402  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
   403  
   404  	// "The branches need not cover all possible enum values"
   405  	// This means that on Marshal, we can safely ignore empty values
   406  	if typestr == "<nil>" {
   407  		return []byte(base), nil
   408  	}
   409  
   410  	// Runtime check for supported value types
   411  	if typestr != "QCryptoBlockCreateOptionsLUKS" &&
   412  		typestr != "QCryptoBlockOptionsQCow" {
   413  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
   414  	}
   415  	value, err := json.Marshal(s.Value)
   416  	if err != nil {
   417  		return nil, err
   418  	}
   419  
   420  	// Workaround to avoid checking s.Value being empty
   421  	if string(value) == "{}" {
   422  		return []byte(base), nil
   423  	}
   424  
   425  	// Removes the last '}' from base and the first '{' from value, in order to
   426  	// return a single JSON object.
   427  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
   428  	return []byte(result), nil
   429  }
   430  
   431  func (s *QCryptoBlockCreateOptions) UnmarshalJSON(data []byte) error {
   432  
   433  	var base QCryptoBlockOptionsBase
   434  	if err := json.Unmarshal(data, &base); err != nil {
   435  		return err
   436  	}
   437  	s.QCryptoBlockOptionsBase = base
   438  
   439  	switch base.Format {
   440  	case QCryptoBlockFormatLuks:
   441  		value := QCryptoBlockCreateOptionsLUKS{}
   442  		if err := json.Unmarshal(data, &value); err != nil {
   443  			return err
   444  		}
   445  		s.Value = value
   446  	case QCryptoBlockFormatQcow:
   447  		value := QCryptoBlockOptionsQCow{}
   448  		if err := json.Unmarshal(data, &value); err != nil {
   449  			return err
   450  		}
   451  		s.Value = value
   452  
   453  	default:
   454  		fmt.Println("Failed to decode QCryptoBlockCreateOptions", base.Format)
   455  	}
   456  
   457  	return nil
   458  }
   459  
   460  // Information about the block encryption options
   461  //
   462  // Since: 2.7
   463  type QCryptoBlockInfo struct {
   464  	// Base type for this struct
   465  	QCryptoBlockInfoBase
   466  	// Value based on @format, possible types:
   467  	// * QCryptoBlockInfoLUKS
   468  	Value Any
   469  }
   470  
   471  func (s QCryptoBlockInfo) MarshalJSON() ([]byte, error) {
   472  	base, err := json.Marshal(s.QCryptoBlockInfoBase)
   473  	if err != nil {
   474  		return nil, err
   475  	}
   476  
   477  	typestr := fmt.Sprintf("%T", s.Value)
   478  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
   479  
   480  	// "The branches need not cover all possible enum values"
   481  	// This means that on Marshal, we can safely ignore empty values
   482  	if typestr == "<nil>" {
   483  		return []byte(base), nil
   484  	}
   485  
   486  	// Runtime check for supported value types
   487  	if typestr != "QCryptoBlockInfoLUKS" {
   488  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
   489  	}
   490  	value, err := json.Marshal(s.Value)
   491  	if err != nil {
   492  		return nil, err
   493  	}
   494  
   495  	// Workaround to avoid checking s.Value being empty
   496  	if string(value) == "{}" {
   497  		return []byte(base), nil
   498  	}
   499  
   500  	// Removes the last '}' from base and the first '{' from value, in order to
   501  	// return a single JSON object.
   502  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
   503  	return []byte(result), nil
   504  }
   505  
   506  func (s *QCryptoBlockInfo) UnmarshalJSON(data []byte) error {
   507  
   508  	var base QCryptoBlockInfoBase
   509  	if err := json.Unmarshal(data, &base); err != nil {
   510  		return err
   511  	}
   512  	s.QCryptoBlockInfoBase = base
   513  
   514  	switch base.Format {
   515  	case QCryptoBlockFormatLuks:
   516  		value := QCryptoBlockInfoLUKS{}
   517  		if err := json.Unmarshal(data, &value); err != nil {
   518  			return err
   519  		}
   520  		s.Value = value
   521  
   522  	default:
   523  		fmt.Println("Failed to decode QCryptoBlockInfo", base.Format)
   524  	}
   525  
   526  	return nil
   527  }
   528  
   529  // The options that are available for all encryption formats
   530  // when amending encryption settings
   531  //
   532  // Since: 5.1
   533  type QCryptoBlockAmendOptions struct {
   534  	// Base type for this struct
   535  	QCryptoBlockOptionsBase
   536  	// Value based on @format, possible types:
   537  	// * QCryptoBlockAmendOptionsLUKS
   538  	Value Any
   539  }
   540  
   541  func (s QCryptoBlockAmendOptions) MarshalJSON() ([]byte, error) {
   542  	base, err := json.Marshal(s.QCryptoBlockOptionsBase)
   543  	if err != nil {
   544  		return nil, err
   545  	}
   546  
   547  	typestr := fmt.Sprintf("%T", s.Value)
   548  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
   549  
   550  	// "The branches need not cover all possible enum values"
   551  	// This means that on Marshal, we can safely ignore empty values
   552  	if typestr == "<nil>" {
   553  		return []byte(base), nil
   554  	}
   555  
   556  	// Runtime check for supported value types
   557  	if typestr != "QCryptoBlockAmendOptionsLUKS" {
   558  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
   559  	}
   560  	value, err := json.Marshal(s.Value)
   561  	if err != nil {
   562  		return nil, err
   563  	}
   564  
   565  	// Workaround to avoid checking s.Value being empty
   566  	if string(value) == "{}" {
   567  		return []byte(base), nil
   568  	}
   569  
   570  	// Removes the last '}' from base and the first '{' from value, in order to
   571  	// return a single JSON object.
   572  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
   573  	return []byte(result), nil
   574  }
   575  
   576  func (s *QCryptoBlockAmendOptions) UnmarshalJSON(data []byte) error {
   577  
   578  	var base QCryptoBlockOptionsBase
   579  	if err := json.Unmarshal(data, &base); err != nil {
   580  		return err
   581  	}
   582  	s.QCryptoBlockOptionsBase = base
   583  
   584  	switch base.Format {
   585  	case QCryptoBlockFormatLuks:
   586  		value := QCryptoBlockAmendOptionsLUKS{}
   587  		if err := json.Unmarshal(data, &value); err != nil {
   588  			return err
   589  		}
   590  		s.Value = value
   591  
   592  	default:
   593  		fmt.Println("Failed to decode QCryptoBlockAmendOptions", base.Format)
   594  	}
   595  
   596  	return nil
   597  }
   598  
   599  // Since: 2.10
   600  type ImageInfoSpecificQCow2Encryption struct {
   601  	// Base type for this struct
   602  	ImageInfoSpecificQCow2EncryptionBase
   603  	// Value based on @format, possible types:
   604  	// * QCryptoBlockInfoLUKS
   605  	Value Any
   606  }
   607  
   608  func (s ImageInfoSpecificQCow2Encryption) MarshalJSON() ([]byte, error) {
   609  	base, err := json.Marshal(s.ImageInfoSpecificQCow2EncryptionBase)
   610  	if err != nil {
   611  		return nil, err
   612  	}
   613  
   614  	typestr := fmt.Sprintf("%T", s.Value)
   615  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
   616  
   617  	// "The branches need not cover all possible enum values"
   618  	// This means that on Marshal, we can safely ignore empty values
   619  	if typestr == "<nil>" {
   620  		return []byte(base), nil
   621  	}
   622  
   623  	// Runtime check for supported value types
   624  	if typestr != "QCryptoBlockInfoLUKS" {
   625  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
   626  	}
   627  	value, err := json.Marshal(s.Value)
   628  	if err != nil {
   629  		return nil, err
   630  	}
   631  
   632  	// Workaround to avoid checking s.Value being empty
   633  	if string(value) == "{}" {
   634  		return []byte(base), nil
   635  	}
   636  
   637  	// Removes the last '}' from base and the first '{' from value, in order to
   638  	// return a single JSON object.
   639  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
   640  	return []byte(result), nil
   641  }
   642  
   643  func (s *ImageInfoSpecificQCow2Encryption) UnmarshalJSON(data []byte) error {
   644  
   645  	var base ImageInfoSpecificQCow2EncryptionBase
   646  	if err := json.Unmarshal(data, &base); err != nil {
   647  		return err
   648  	}
   649  	s.ImageInfoSpecificQCow2EncryptionBase = base
   650  
   651  	switch base.Format {
   652  	case BlockdevQcow2EncryptionFormatLuks:
   653  		value := QCryptoBlockInfoLUKS{}
   654  		if err := json.Unmarshal(data, &value); err != nil {
   655  			return err
   656  		}
   657  		s.Value = value
   658  
   659  	default:
   660  		fmt.Println("Failed to decode ImageInfoSpecificQCow2Encryption", base.Format)
   661  	}
   662  
   663  	return nil
   664  }
   665  
   666  // A discriminated record of image format specific information structures.
   667  //
   668  // Since: 1.7
   669  type ImageInfoSpecificBase struct {
   670  	Type ImageInfoSpecificKind `json:"type"`
   671  }
   672  
   673  // A discriminated record of image format specific information structures.
   674  //
   675  // Since: 1.7
   676  type ImageInfoSpecific struct {
   677  	// Base type for this struct
   678  	ImageInfoSpecificBase
   679  	// Value based on @type, possible types:
   680  	// * ImageInfoSpecificQCow2Wrapper
   681  	// * ImageInfoSpecificVmdkWrapper
   682  	// * ImageInfoSpecificLUKSWrapper
   683  	// * ImageInfoSpecificRbdWrapper
   684  	Value Any
   685  }
   686  
   687  func (s ImageInfoSpecific) MarshalJSON() ([]byte, error) {
   688  	base, err := json.Marshal(s.ImageInfoSpecificBase)
   689  	if err != nil {
   690  		return nil, err
   691  	}
   692  
   693  	typestr := fmt.Sprintf("%T", s.Value)
   694  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
   695  
   696  	// "The branches need not cover all possible enum values"
   697  	// This means that on Marshal, we can safely ignore empty values
   698  	if typestr == "<nil>" {
   699  		return []byte(base), nil
   700  	}
   701  
   702  	// Runtime check for supported value types
   703  	if typestr != "ImageInfoSpecificLUKSWrapper" &&
   704  		typestr != "ImageInfoSpecificQCow2Wrapper" &&
   705  		typestr != "ImageInfoSpecificRbdWrapper" &&
   706  		typestr != "ImageInfoSpecificVmdkWrapper" {
   707  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
   708  	}
   709  	value, err := json.Marshal(s.Value)
   710  	if err != nil {
   711  		return nil, err
   712  	}
   713  
   714  	// Workaround to avoid checking s.Value being empty
   715  	if string(value) == "{}" {
   716  		return []byte(base), nil
   717  	}
   718  
   719  	// Removes the last '}' from base and the first '{' from value, in order to
   720  	// return a single JSON object.
   721  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
   722  	return []byte(result), nil
   723  }
   724  
   725  func (s *ImageInfoSpecific) UnmarshalJSON(data []byte) error {
   726  
   727  	var base ImageInfoSpecificBase
   728  	if err := json.Unmarshal(data, &base); err != nil {
   729  		return err
   730  	}
   731  	s.ImageInfoSpecificBase = base
   732  
   733  	switch base.Type {
   734  	case ImageInfoSpecificKindLuks:
   735  		value := ImageInfoSpecificLUKSWrapper{}
   736  		if err := json.Unmarshal(data, &value); err != nil {
   737  			return err
   738  		}
   739  		s.Value = value
   740  	case ImageInfoSpecificKindQcow2:
   741  		value := ImageInfoSpecificQCow2Wrapper{}
   742  		if err := json.Unmarshal(data, &value); err != nil {
   743  			return err
   744  		}
   745  		s.Value = value
   746  	case ImageInfoSpecificKindRbd:
   747  		value := ImageInfoSpecificRbdWrapper{}
   748  		if err := json.Unmarshal(data, &value); err != nil {
   749  			return err
   750  		}
   751  		s.Value = value
   752  	case ImageInfoSpecificKindVmdk:
   753  		value := ImageInfoSpecificVmdkWrapper{}
   754  		if err := json.Unmarshal(data, &value); err != nil {
   755  			return err
   756  		}
   757  		s.Value = value
   758  
   759  	default:
   760  		fmt.Println("Failed to decode ImageInfoSpecific", base.Type)
   761  	}
   762  
   763  	return nil
   764  }
   765  
   766  // Block driver specific statistics
   767  //
   768  // Since: 4.2
   769  type BlockStatsSpecificBase struct {
   770  	Driver BlockdevDriver `json:"driver"`
   771  }
   772  
   773  // Block driver specific statistics
   774  //
   775  // Since: 4.2
   776  type BlockStatsSpecific struct {
   777  	// Base type for this struct
   778  	BlockStatsSpecificBase
   779  	// Value based on @driver, possible types:
   780  	// * BlockStatsSpecificFile
   781  	// * BlockStatsSpecificFile
   782  	// * BlockStatsSpecificNvme
   783  	Value Any
   784  }
   785  
   786  func (s BlockStatsSpecific) MarshalJSON() ([]byte, error) {
   787  	base, err := json.Marshal(s.BlockStatsSpecificBase)
   788  	if err != nil {
   789  		return nil, err
   790  	}
   791  
   792  	typestr := fmt.Sprintf("%T", s.Value)
   793  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
   794  
   795  	// "The branches need not cover all possible enum values"
   796  	// This means that on Marshal, we can safely ignore empty values
   797  	if typestr == "<nil>" {
   798  		return []byte(base), nil
   799  	}
   800  
   801  	// Runtime check for supported value types
   802  	if typestr != "BlockStatsSpecificFile" &&
   803  		typestr != "BlockStatsSpecificNvme" {
   804  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
   805  	}
   806  	value, err := json.Marshal(s.Value)
   807  	if err != nil {
   808  		return nil, err
   809  	}
   810  
   811  	// Workaround to avoid checking s.Value being empty
   812  	if string(value) == "{}" {
   813  		return []byte(base), nil
   814  	}
   815  
   816  	// Removes the last '}' from base and the first '{' from value, in order to
   817  	// return a single JSON object.
   818  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
   819  	return []byte(result), nil
   820  }
   821  
   822  func (s *BlockStatsSpecific) UnmarshalJSON(data []byte) error {
   823  
   824  	var base BlockStatsSpecificBase
   825  	if err := json.Unmarshal(data, &base); err != nil {
   826  		return err
   827  	}
   828  	s.BlockStatsSpecificBase = base
   829  
   830  	switch base.Driver {
   831  	case BlockdevDriverFile:
   832  		value := BlockStatsSpecificFile{}
   833  		if err := json.Unmarshal(data, &value); err != nil {
   834  			return err
   835  		}
   836  		s.Value = value
   837  	case BlockdevDriverHost_Device:
   838  		value := BlockStatsSpecificFile{}
   839  		if err := json.Unmarshal(data, &value); err != nil {
   840  			return err
   841  		}
   842  		s.Value = value
   843  	case BlockdevDriverNvme:
   844  		value := BlockStatsSpecificNvme{}
   845  		if err := json.Unmarshal(data, &value); err != nil {
   846  			return err
   847  		}
   848  		s.Value = value
   849  
   850  	default:
   851  		fmt.Println("Failed to decode BlockStatsSpecific", base.Driver)
   852  	}
   853  
   854  	return nil
   855  }
   856  
   857  // Since: 2.10
   858  type BlockdevQcowEncryptionBase struct {
   859  	Format BlockdevQcowEncryptionFormat `json:"format"`
   860  }
   861  
   862  // Since: 2.10
   863  type BlockdevQcowEncryption struct {
   864  	// Base type for this struct
   865  	BlockdevQcowEncryptionBase
   866  	// Value based on @format, possible types:
   867  	// * QCryptoBlockOptionsQCow
   868  	Value Any
   869  }
   870  
   871  func (s BlockdevQcowEncryption) MarshalJSON() ([]byte, error) {
   872  	base, err := json.Marshal(s.BlockdevQcowEncryptionBase)
   873  	if err != nil {
   874  		return nil, err
   875  	}
   876  
   877  	typestr := fmt.Sprintf("%T", s.Value)
   878  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
   879  
   880  	// "The branches need not cover all possible enum values"
   881  	// This means that on Marshal, we can safely ignore empty values
   882  	if typestr == "<nil>" {
   883  		return []byte(base), nil
   884  	}
   885  
   886  	// Runtime check for supported value types
   887  	if typestr != "QCryptoBlockOptionsQCow" {
   888  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
   889  	}
   890  	value, err := json.Marshal(s.Value)
   891  	if err != nil {
   892  		return nil, err
   893  	}
   894  
   895  	// Workaround to avoid checking s.Value being empty
   896  	if string(value) == "{}" {
   897  		return []byte(base), nil
   898  	}
   899  
   900  	// Removes the last '}' from base and the first '{' from value, in order to
   901  	// return a single JSON object.
   902  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
   903  	return []byte(result), nil
   904  }
   905  
   906  func (s *BlockdevQcowEncryption) UnmarshalJSON(data []byte) error {
   907  
   908  	var base BlockdevQcowEncryptionBase
   909  	if err := json.Unmarshal(data, &base); err != nil {
   910  		return err
   911  	}
   912  	s.BlockdevQcowEncryptionBase = base
   913  
   914  	switch base.Format {
   915  	case BlockdevQcowEncryptionFormatAes:
   916  		value := QCryptoBlockOptionsQCow{}
   917  		if err := json.Unmarshal(data, &value); err != nil {
   918  			return err
   919  		}
   920  		s.Value = value
   921  
   922  	default:
   923  		fmt.Println("Failed to decode BlockdevQcowEncryption", base.Format)
   924  	}
   925  
   926  	return nil
   927  }
   928  
   929  // Since: 2.10
   930  type BlockdevQcow2EncryptionBase struct {
   931  	Format BlockdevQcow2EncryptionFormat `json:"format"`
   932  }
   933  
   934  // Since: 2.10
   935  type BlockdevQcow2Encryption struct {
   936  	// Base type for this struct
   937  	BlockdevQcow2EncryptionBase
   938  	// Value based on @format, possible types:
   939  	// * QCryptoBlockOptionsQCow
   940  	// * QCryptoBlockOptionsLUKS
   941  	Value Any
   942  }
   943  
   944  func (s BlockdevQcow2Encryption) MarshalJSON() ([]byte, error) {
   945  	base, err := json.Marshal(s.BlockdevQcow2EncryptionBase)
   946  	if err != nil {
   947  		return nil, err
   948  	}
   949  
   950  	typestr := fmt.Sprintf("%T", s.Value)
   951  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
   952  
   953  	// "The branches need not cover all possible enum values"
   954  	// This means that on Marshal, we can safely ignore empty values
   955  	if typestr == "<nil>" {
   956  		return []byte(base), nil
   957  	}
   958  
   959  	// Runtime check for supported value types
   960  	if typestr != "QCryptoBlockOptionsQCow" &&
   961  		typestr != "QCryptoBlockOptionsLUKS" {
   962  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
   963  	}
   964  	value, err := json.Marshal(s.Value)
   965  	if err != nil {
   966  		return nil, err
   967  	}
   968  
   969  	// Workaround to avoid checking s.Value being empty
   970  	if string(value) == "{}" {
   971  		return []byte(base), nil
   972  	}
   973  
   974  	// Removes the last '}' from base and the first '{' from value, in order to
   975  	// return a single JSON object.
   976  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
   977  	return []byte(result), nil
   978  }
   979  
   980  func (s *BlockdevQcow2Encryption) UnmarshalJSON(data []byte) error {
   981  
   982  	var base BlockdevQcow2EncryptionBase
   983  	if err := json.Unmarshal(data, &base); err != nil {
   984  		return err
   985  	}
   986  	s.BlockdevQcow2EncryptionBase = base
   987  
   988  	switch base.Format {
   989  	case BlockdevQcow2EncryptionFormatAes:
   990  		value := QCryptoBlockOptionsQCow{}
   991  		if err := json.Unmarshal(data, &value); err != nil {
   992  			return err
   993  		}
   994  		s.Value = value
   995  	case BlockdevQcow2EncryptionFormatLuks:
   996  		value := QCryptoBlockOptionsLUKS{}
   997  		if err := json.Unmarshal(data, &value); err != nil {
   998  			return err
   999  		}
  1000  		s.Value = value
  1001  
  1002  	default:
  1003  		fmt.Println("Failed to decode BlockdevQcow2Encryption", base.Format)
  1004  	}
  1005  
  1006  	return nil
  1007  }
  1008  
  1009  // Since: 2.12
  1010  type SshHostKeyCheckBase struct {
  1011  	Mode SshHostKeyCheckMode `json:"mode"`
  1012  }
  1013  
  1014  // Since: 2.12
  1015  type SshHostKeyCheck struct {
  1016  	// Base type for this struct
  1017  	SshHostKeyCheckBase
  1018  	// Value based on @mode, possible types:
  1019  	// * SshHostKeyHash
  1020  	Value Any
  1021  }
  1022  
  1023  func (s SshHostKeyCheck) MarshalJSON() ([]byte, error) {
  1024  	base, err := json.Marshal(s.SshHostKeyCheckBase)
  1025  	if err != nil {
  1026  		return nil, err
  1027  	}
  1028  
  1029  	typestr := fmt.Sprintf("%T", s.Value)
  1030  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  1031  
  1032  	// "The branches need not cover all possible enum values"
  1033  	// This means that on Marshal, we can safely ignore empty values
  1034  	if typestr == "<nil>" {
  1035  		return []byte(base), nil
  1036  	}
  1037  
  1038  	// Runtime check for supported value types
  1039  	if typestr != "SshHostKeyHash" {
  1040  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  1041  	}
  1042  	value, err := json.Marshal(s.Value)
  1043  	if err != nil {
  1044  		return nil, err
  1045  	}
  1046  
  1047  	// Workaround to avoid checking s.Value being empty
  1048  	if string(value) == "{}" {
  1049  		return []byte(base), nil
  1050  	}
  1051  
  1052  	// Removes the last '}' from base and the first '{' from value, in order to
  1053  	// return a single JSON object.
  1054  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  1055  	return []byte(result), nil
  1056  }
  1057  
  1058  func (s *SshHostKeyCheck) UnmarshalJSON(data []byte) error {
  1059  
  1060  	var base SshHostKeyCheckBase
  1061  	if err := json.Unmarshal(data, &base); err != nil {
  1062  		return err
  1063  	}
  1064  	s.SshHostKeyCheckBase = base
  1065  
  1066  	switch base.Mode {
  1067  	case SshHostKeyCheckModeHash:
  1068  		value := SshHostKeyHash{}
  1069  		if err := json.Unmarshal(data, &value); err != nil {
  1070  			return err
  1071  		}
  1072  		s.Value = value
  1073  
  1074  	default:
  1075  		fmt.Println("Failed to decode SshHostKeyCheck", base.Mode)
  1076  	}
  1077  
  1078  	return nil
  1079  }
  1080  
  1081  // Since: 6.1
  1082  type RbdEncryptionOptionsBase struct {
  1083  	Format RbdImageEncryptionFormat `json:"format"`
  1084  }
  1085  
  1086  // Since: 6.1
  1087  type RbdEncryptionOptions struct {
  1088  	// Base type for this struct
  1089  	RbdEncryptionOptionsBase
  1090  	// Value based on @format, possible types:
  1091  	// * RbdEncryptionOptionsLUKS
  1092  	// * RbdEncryptionOptionsLUKS2
  1093  	Value Any
  1094  }
  1095  
  1096  func (s RbdEncryptionOptions) MarshalJSON() ([]byte, error) {
  1097  	base, err := json.Marshal(s.RbdEncryptionOptionsBase)
  1098  	if err != nil {
  1099  		return nil, err
  1100  	}
  1101  
  1102  	typestr := fmt.Sprintf("%T", s.Value)
  1103  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  1104  
  1105  	// "The branches need not cover all possible enum values"
  1106  	// This means that on Marshal, we can safely ignore empty values
  1107  	if typestr == "<nil>" {
  1108  		return []byte(base), nil
  1109  	}
  1110  
  1111  	// Runtime check for supported value types
  1112  	if typestr != "RbdEncryptionOptionsLUKS" &&
  1113  		typestr != "RbdEncryptionOptionsLUKS2" {
  1114  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  1115  	}
  1116  	value, err := json.Marshal(s.Value)
  1117  	if err != nil {
  1118  		return nil, err
  1119  	}
  1120  
  1121  	// Workaround to avoid checking s.Value being empty
  1122  	if string(value) == "{}" {
  1123  		return []byte(base), nil
  1124  	}
  1125  
  1126  	// Removes the last '}' from base and the first '{' from value, in order to
  1127  	// return a single JSON object.
  1128  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  1129  	return []byte(result), nil
  1130  }
  1131  
  1132  func (s *RbdEncryptionOptions) UnmarshalJSON(data []byte) error {
  1133  
  1134  	var base RbdEncryptionOptionsBase
  1135  	if err := json.Unmarshal(data, &base); err != nil {
  1136  		return err
  1137  	}
  1138  	s.RbdEncryptionOptionsBase = base
  1139  
  1140  	switch base.Format {
  1141  	case RbdImageEncryptionFormatLuks:
  1142  		value := RbdEncryptionOptionsLUKS{}
  1143  		if err := json.Unmarshal(data, &value); err != nil {
  1144  			return err
  1145  		}
  1146  		s.Value = value
  1147  	case RbdImageEncryptionFormatLuks2:
  1148  		value := RbdEncryptionOptionsLUKS2{}
  1149  		if err := json.Unmarshal(data, &value); err != nil {
  1150  			return err
  1151  		}
  1152  		s.Value = value
  1153  
  1154  	default:
  1155  		fmt.Println("Failed to decode RbdEncryptionOptions", base.Format)
  1156  	}
  1157  
  1158  	return nil
  1159  }
  1160  
  1161  // Since: 6.1
  1162  type RbdEncryptionCreateOptionsBase struct {
  1163  	Format RbdImageEncryptionFormat `json:"format"`
  1164  }
  1165  
  1166  // Since: 6.1
  1167  type RbdEncryptionCreateOptions struct {
  1168  	// Base type for this struct
  1169  	RbdEncryptionCreateOptionsBase
  1170  	// Value based on @format, possible types:
  1171  	// * RbdEncryptionCreateOptionsLUKS
  1172  	// * RbdEncryptionCreateOptionsLUKS2
  1173  	Value Any
  1174  }
  1175  
  1176  func (s RbdEncryptionCreateOptions) MarshalJSON() ([]byte, error) {
  1177  	base, err := json.Marshal(s.RbdEncryptionCreateOptionsBase)
  1178  	if err != nil {
  1179  		return nil, err
  1180  	}
  1181  
  1182  	typestr := fmt.Sprintf("%T", s.Value)
  1183  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  1184  
  1185  	// "The branches need not cover all possible enum values"
  1186  	// This means that on Marshal, we can safely ignore empty values
  1187  	if typestr == "<nil>" {
  1188  		return []byte(base), nil
  1189  	}
  1190  
  1191  	// Runtime check for supported value types
  1192  	if typestr != "RbdEncryptionCreateOptionsLUKS" &&
  1193  		typestr != "RbdEncryptionCreateOptionsLUKS2" {
  1194  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  1195  	}
  1196  	value, err := json.Marshal(s.Value)
  1197  	if err != nil {
  1198  		return nil, err
  1199  	}
  1200  
  1201  	// Workaround to avoid checking s.Value being empty
  1202  	if string(value) == "{}" {
  1203  		return []byte(base), nil
  1204  	}
  1205  
  1206  	// Removes the last '}' from base and the first '{' from value, in order to
  1207  	// return a single JSON object.
  1208  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  1209  	return []byte(result), nil
  1210  }
  1211  
  1212  func (s *RbdEncryptionCreateOptions) UnmarshalJSON(data []byte) error {
  1213  
  1214  	var base RbdEncryptionCreateOptionsBase
  1215  	if err := json.Unmarshal(data, &base); err != nil {
  1216  		return err
  1217  	}
  1218  	s.RbdEncryptionCreateOptionsBase = base
  1219  
  1220  	switch base.Format {
  1221  	case RbdImageEncryptionFormatLuks:
  1222  		value := RbdEncryptionCreateOptionsLUKS{}
  1223  		if err := json.Unmarshal(data, &value); err != nil {
  1224  			return err
  1225  		}
  1226  		s.Value = value
  1227  	case RbdImageEncryptionFormatLuks2:
  1228  		value := RbdEncryptionCreateOptionsLUKS2{}
  1229  		if err := json.Unmarshal(data, &value); err != nil {
  1230  			return err
  1231  		}
  1232  		s.Value = value
  1233  
  1234  	default:
  1235  		fmt.Println("Failed to decode RbdEncryptionCreateOptions", base.Format)
  1236  	}
  1237  
  1238  	return nil
  1239  }
  1240  
  1241  // Options for creating a block device.  Many options are available for all
  1242  // block devices, independent of the block driver:
  1243  //
  1244  // None: Remaining options are determined by the block driver.
  1245  //
  1246  // Since: 2.9
  1247  type BlockdevOptionsBase struct {
  1248  	Driver       BlockdevDriver               `json:"driver"`                   // block driver name
  1249  	NodeName     *string                      `json:"node-name,omitempty"`      // the node name of the new node (Since 2.0). This option is required on the top level of blockdev-add. Valid node names start with an alphabetic character and may contain only alphanumeric characters, '-', '.' and '_'. Their maximum length is 31 characters.
  1250  	Discard      *BlockdevDiscardOptions      `json:"discard,omitempty"`        // discard-related options (default: ignore)
  1251  	Cache        *BlockdevCacheOptions        `json:"cache,omitempty"`          // cache-related options
  1252  	ReadOnly     *bool                        `json:"read-only,omitempty"`      // whether the block device should be read-only (default: false). Note that some block drivers support only read-only access, either generally or in certain configurations. In this case, the default value does not work and the option must be specified explicitly.
  1253  	AutoReadOnly *bool                        `json:"auto-read-only,omitempty"` // if true and @read-only is false, QEMU may automatically decide not to open the image read-write as requested, but fall back to read-only instead (and switch between the modes later), e.g. depending on whether the image file is writable or whether a writing user is attached to the node (default: false, since 3.1)
  1254  	ForceShare   *bool                        `json:"force-share,omitempty"`    // force share all permission on added nodes. Requires read-only=true. (Since 2.10)
  1255  	DetectZeroes *BlockdevDetectZeroesOptions `json:"detect-zeroes,omitempty"`  // detect and optimize zero writes (Since 2.1) (default: off)
  1256  }
  1257  
  1258  // Options for creating a block device.  Many options are available for all
  1259  // block devices, independent of the block driver:
  1260  //
  1261  // None: Remaining options are determined by the block driver.
  1262  //
  1263  // Since: 2.9
  1264  type BlockdevOptions struct {
  1265  	// Base type for this struct
  1266  	BlockdevOptionsBase
  1267  	// Value based on @driver, possible types:
  1268  	// * BlockdevOptionsBlkdebug
  1269  	// * BlockdevOptionsBlklogwrites
  1270  	// * BlockdevOptionsBlkverify
  1271  	// * BlockdevOptionsBlkreplay
  1272  	// * BlockdevOptionsGenericFormat
  1273  	// * BlockdevOptionsGenericFormat
  1274  	// * BlockdevOptionsGenericFormat
  1275  	// * BlockdevOptionsCbw
  1276  	// * BlockdevOptionsCor
  1277  	// * BlockdevOptionsGenericFormat
  1278  	// * BlockdevOptionsFile
  1279  	// * BlockdevOptionsCurlFtp
  1280  	// * BlockdevOptionsCurlFtps
  1281  	// * BlockdevOptionsGluster
  1282  	// * BlockdevOptionsFile
  1283  	// * BlockdevOptionsFile
  1284  	// * BlockdevOptionsCurlHttp
  1285  	// * BlockdevOptionsCurlHttps
  1286  	// * BlockdevOptionsIscsi
  1287  	// * BlockdevOptionsLUKS
  1288  	// * BlockdevOptionsNbd
  1289  	// * BlockdevOptionsNfs
  1290  	// * BlockdevOptionsNull
  1291  	// * BlockdevOptionsNull
  1292  	// * BlockdevOptionsNVMe
  1293  	// * BlockdevOptionsGenericFormat
  1294  	// * BlockdevOptionsPreallocate
  1295  	// * BlockdevOptionsQcow2
  1296  	// * BlockdevOptionsQcow
  1297  	// * BlockdevOptionsGenericCOWFormat
  1298  	// * BlockdevOptionsQuorum
  1299  	// * BlockdevOptionsRaw
  1300  	// * BlockdevOptionsRbd
  1301  	// * BlockdevOptionsReplication
  1302  	// * BlockdevOptionsGenericFormat
  1303  	// * BlockdevOptionsSsh
  1304  	// * BlockdevOptionsThrottle
  1305  	// * BlockdevOptionsGenericFormat
  1306  	// * BlockdevOptionsGenericFormat
  1307  	// * BlockdevOptionsGenericCOWFormat
  1308  	// * BlockdevOptionsGenericFormat
  1309  	// * BlockdevOptionsVVFAT
  1310  	Value Any
  1311  }
  1312  
  1313  func (s BlockdevOptions) MarshalJSON() ([]byte, error) {
  1314  	base, err := json.Marshal(s.BlockdevOptionsBase)
  1315  	if err != nil {
  1316  		return nil, err
  1317  	}
  1318  
  1319  	typestr := fmt.Sprintf("%T", s.Value)
  1320  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  1321  
  1322  	// "The branches need not cover all possible enum values"
  1323  	// This means that on Marshal, we can safely ignore empty values
  1324  	if typestr == "<nil>" {
  1325  		return []byte(base), nil
  1326  	}
  1327  
  1328  	// Runtime check for supported value types
  1329  	if typestr != "BlockdevOptionsBlkdebug" &&
  1330  		typestr != "BlockdevOptionsBlklogwrites" &&
  1331  		typestr != "BlockdevOptionsBlkreplay" &&
  1332  		typestr != "BlockdevOptionsBlkverify" &&
  1333  		typestr != "BlockdevOptionsGenericFormat" &&
  1334  		typestr != "BlockdevOptionsCbw" &&
  1335  		typestr != "BlockdevOptionsCor" &&
  1336  		typestr != "BlockdevOptionsFile" &&
  1337  		typestr != "BlockdevOptionsCurlFtp" &&
  1338  		typestr != "BlockdevOptionsCurlFtps" &&
  1339  		typestr != "BlockdevOptionsGluster" &&
  1340  		typestr != "BlockdevOptionsCurlHttp" &&
  1341  		typestr != "BlockdevOptionsCurlHttps" &&
  1342  		typestr != "BlockdevOptionsIscsi" &&
  1343  		typestr != "BlockdevOptionsLUKS" &&
  1344  		typestr != "BlockdevOptionsNbd" &&
  1345  		typestr != "BlockdevOptionsNfs" &&
  1346  		typestr != "BlockdevOptionsNull" &&
  1347  		typestr != "BlockdevOptionsNVMe" &&
  1348  		typestr != "BlockdevOptionsPreallocate" &&
  1349  		typestr != "BlockdevOptionsQcow" &&
  1350  		typestr != "BlockdevOptionsQcow2" &&
  1351  		typestr != "BlockdevOptionsGenericCOWFormat" &&
  1352  		typestr != "BlockdevOptionsQuorum" &&
  1353  		typestr != "BlockdevOptionsRaw" &&
  1354  		typestr != "BlockdevOptionsRbd" &&
  1355  		typestr != "BlockdevOptionsReplication" &&
  1356  		typestr != "BlockdevOptionsSsh" &&
  1357  		typestr != "BlockdevOptionsThrottle" &&
  1358  		typestr != "BlockdevOptionsVVFAT" {
  1359  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  1360  	}
  1361  	value, err := json.Marshal(s.Value)
  1362  	if err != nil {
  1363  		return nil, err
  1364  	}
  1365  
  1366  	// Workaround to avoid checking s.Value being empty
  1367  	if string(value) == "{}" {
  1368  		return []byte(base), nil
  1369  	}
  1370  
  1371  	// Removes the last '}' from base and the first '{' from value, in order to
  1372  	// return a single JSON object.
  1373  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  1374  	return []byte(result), nil
  1375  }
  1376  
  1377  func (s *BlockdevOptions) UnmarshalJSON(data []byte) error {
  1378  
  1379  	var base BlockdevOptionsBase
  1380  	if err := json.Unmarshal(data, &base); err != nil {
  1381  		return err
  1382  	}
  1383  	s.BlockdevOptionsBase = base
  1384  
  1385  	switch base.Driver {
  1386  	case BlockdevDriverBlkdebug:
  1387  		value := BlockdevOptionsBlkdebug{}
  1388  		if err := json.Unmarshal(data, &value); err != nil {
  1389  			return err
  1390  		}
  1391  		s.Value = value
  1392  	case BlockdevDriverBlklogwrites:
  1393  		value := BlockdevOptionsBlklogwrites{}
  1394  		if err := json.Unmarshal(data, &value); err != nil {
  1395  			return err
  1396  		}
  1397  		s.Value = value
  1398  	case BlockdevDriverBlkreplay:
  1399  		value := BlockdevOptionsBlkreplay{}
  1400  		if err := json.Unmarshal(data, &value); err != nil {
  1401  			return err
  1402  		}
  1403  		s.Value = value
  1404  	case BlockdevDriverBlkverify:
  1405  		value := BlockdevOptionsBlkverify{}
  1406  		if err := json.Unmarshal(data, &value); err != nil {
  1407  			return err
  1408  		}
  1409  		s.Value = value
  1410  	case BlockdevDriverBochs:
  1411  		value := BlockdevOptionsGenericFormat{}
  1412  		if err := json.Unmarshal(data, &value); err != nil {
  1413  			return err
  1414  		}
  1415  		s.Value = value
  1416  	case BlockdevDriverCloop:
  1417  		value := BlockdevOptionsGenericFormat{}
  1418  		if err := json.Unmarshal(data, &value); err != nil {
  1419  			return err
  1420  		}
  1421  		s.Value = value
  1422  	case BlockdevDriverCompress:
  1423  		value := BlockdevOptionsGenericFormat{}
  1424  		if err := json.Unmarshal(data, &value); err != nil {
  1425  			return err
  1426  		}
  1427  		s.Value = value
  1428  	case BlockdevDriverCopyBeforeWrite:
  1429  		value := BlockdevOptionsCbw{}
  1430  		if err := json.Unmarshal(data, &value); err != nil {
  1431  			return err
  1432  		}
  1433  		s.Value = value
  1434  	case BlockdevDriverCopyOnRead:
  1435  		value := BlockdevOptionsCor{}
  1436  		if err := json.Unmarshal(data, &value); err != nil {
  1437  			return err
  1438  		}
  1439  		s.Value = value
  1440  	case BlockdevDriverDmg:
  1441  		value := BlockdevOptionsGenericFormat{}
  1442  		if err := json.Unmarshal(data, &value); err != nil {
  1443  			return err
  1444  		}
  1445  		s.Value = value
  1446  	case BlockdevDriverFile:
  1447  		value := BlockdevOptionsFile{}
  1448  		if err := json.Unmarshal(data, &value); err != nil {
  1449  			return err
  1450  		}
  1451  		s.Value = value
  1452  	case BlockdevDriverFtp:
  1453  		value := BlockdevOptionsCurlFtp{}
  1454  		if err := json.Unmarshal(data, &value); err != nil {
  1455  			return err
  1456  		}
  1457  		s.Value = value
  1458  	case BlockdevDriverFtps:
  1459  		value := BlockdevOptionsCurlFtps{}
  1460  		if err := json.Unmarshal(data, &value); err != nil {
  1461  			return err
  1462  		}
  1463  		s.Value = value
  1464  	case BlockdevDriverGluster:
  1465  		value := BlockdevOptionsGluster{}
  1466  		if err := json.Unmarshal(data, &value); err != nil {
  1467  			return err
  1468  		}
  1469  		s.Value = value
  1470  	case BlockdevDriverHost_Cdrom:
  1471  		value := BlockdevOptionsFile{}
  1472  		if err := json.Unmarshal(data, &value); err != nil {
  1473  			return err
  1474  		}
  1475  		s.Value = value
  1476  	case BlockdevDriverHost_Device:
  1477  		value := BlockdevOptionsFile{}
  1478  		if err := json.Unmarshal(data, &value); err != nil {
  1479  			return err
  1480  		}
  1481  		s.Value = value
  1482  	case BlockdevDriverHttp:
  1483  		value := BlockdevOptionsCurlHttp{}
  1484  		if err := json.Unmarshal(data, &value); err != nil {
  1485  			return err
  1486  		}
  1487  		s.Value = value
  1488  	case BlockdevDriverHttps:
  1489  		value := BlockdevOptionsCurlHttps{}
  1490  		if err := json.Unmarshal(data, &value); err != nil {
  1491  			return err
  1492  		}
  1493  		s.Value = value
  1494  	case BlockdevDriverIscsi:
  1495  		value := BlockdevOptionsIscsi{}
  1496  		if err := json.Unmarshal(data, &value); err != nil {
  1497  			return err
  1498  		}
  1499  		s.Value = value
  1500  	case BlockdevDriverLuks:
  1501  		value := BlockdevOptionsLUKS{}
  1502  		if err := json.Unmarshal(data, &value); err != nil {
  1503  			return err
  1504  		}
  1505  		s.Value = value
  1506  	case BlockdevDriverNbd:
  1507  		value := BlockdevOptionsNbd{}
  1508  		if err := json.Unmarshal(data, &value); err != nil {
  1509  			return err
  1510  		}
  1511  		s.Value = value
  1512  	case BlockdevDriverNfs:
  1513  		value := BlockdevOptionsNfs{}
  1514  		if err := json.Unmarshal(data, &value); err != nil {
  1515  			return err
  1516  		}
  1517  		s.Value = value
  1518  	case BlockdevDriverNullAio:
  1519  		value := BlockdevOptionsNull{}
  1520  		if err := json.Unmarshal(data, &value); err != nil {
  1521  			return err
  1522  		}
  1523  		s.Value = value
  1524  	case BlockdevDriverNullCo:
  1525  		value := BlockdevOptionsNull{}
  1526  		if err := json.Unmarshal(data, &value); err != nil {
  1527  			return err
  1528  		}
  1529  		s.Value = value
  1530  	case BlockdevDriverNvme:
  1531  		value := BlockdevOptionsNVMe{}
  1532  		if err := json.Unmarshal(data, &value); err != nil {
  1533  			return err
  1534  		}
  1535  		s.Value = value
  1536  	case BlockdevDriverParallels:
  1537  		value := BlockdevOptionsGenericFormat{}
  1538  		if err := json.Unmarshal(data, &value); err != nil {
  1539  			return err
  1540  		}
  1541  		s.Value = value
  1542  	case BlockdevDriverPreallocate:
  1543  		value := BlockdevOptionsPreallocate{}
  1544  		if err := json.Unmarshal(data, &value); err != nil {
  1545  			return err
  1546  		}
  1547  		s.Value = value
  1548  	case BlockdevDriverQcow:
  1549  		value := BlockdevOptionsQcow{}
  1550  		if err := json.Unmarshal(data, &value); err != nil {
  1551  			return err
  1552  		}
  1553  		s.Value = value
  1554  	case BlockdevDriverQcow2:
  1555  		value := BlockdevOptionsQcow2{}
  1556  		if err := json.Unmarshal(data, &value); err != nil {
  1557  			return err
  1558  		}
  1559  		s.Value = value
  1560  	case BlockdevDriverQed:
  1561  		value := BlockdevOptionsGenericCOWFormat{}
  1562  		if err := json.Unmarshal(data, &value); err != nil {
  1563  			return err
  1564  		}
  1565  		s.Value = value
  1566  	case BlockdevDriverQuorum:
  1567  		value := BlockdevOptionsQuorum{}
  1568  		if err := json.Unmarshal(data, &value); err != nil {
  1569  			return err
  1570  		}
  1571  		s.Value = value
  1572  	case BlockdevDriverRaw:
  1573  		value := BlockdevOptionsRaw{}
  1574  		if err := json.Unmarshal(data, &value); err != nil {
  1575  			return err
  1576  		}
  1577  		s.Value = value
  1578  	case BlockdevDriverRbd:
  1579  		value := BlockdevOptionsRbd{}
  1580  		if err := json.Unmarshal(data, &value); err != nil {
  1581  			return err
  1582  		}
  1583  		s.Value = value
  1584  	case BlockdevDriverReplication:
  1585  		value := BlockdevOptionsReplication{}
  1586  		if err := json.Unmarshal(data, &value); err != nil {
  1587  			return err
  1588  		}
  1589  		s.Value = value
  1590  	case BlockdevDriverSnapshotAccess:
  1591  		value := BlockdevOptionsGenericFormat{}
  1592  		if err := json.Unmarshal(data, &value); err != nil {
  1593  			return err
  1594  		}
  1595  		s.Value = value
  1596  	case BlockdevDriverSsh:
  1597  		value := BlockdevOptionsSsh{}
  1598  		if err := json.Unmarshal(data, &value); err != nil {
  1599  			return err
  1600  		}
  1601  		s.Value = value
  1602  	case BlockdevDriverThrottle:
  1603  		value := BlockdevOptionsThrottle{}
  1604  		if err := json.Unmarshal(data, &value); err != nil {
  1605  			return err
  1606  		}
  1607  		s.Value = value
  1608  	case BlockdevDriverVdi:
  1609  		value := BlockdevOptionsGenericFormat{}
  1610  		if err := json.Unmarshal(data, &value); err != nil {
  1611  			return err
  1612  		}
  1613  		s.Value = value
  1614  	case BlockdevDriverVhdx:
  1615  		value := BlockdevOptionsGenericFormat{}
  1616  		if err := json.Unmarshal(data, &value); err != nil {
  1617  			return err
  1618  		}
  1619  		s.Value = value
  1620  	case BlockdevDriverVmdk:
  1621  		value := BlockdevOptionsGenericCOWFormat{}
  1622  		if err := json.Unmarshal(data, &value); err != nil {
  1623  			return err
  1624  		}
  1625  		s.Value = value
  1626  	case BlockdevDriverVpc:
  1627  		value := BlockdevOptionsGenericFormat{}
  1628  		if err := json.Unmarshal(data, &value); err != nil {
  1629  			return err
  1630  		}
  1631  		s.Value = value
  1632  	case BlockdevDriverVvfat:
  1633  		value := BlockdevOptionsVVFAT{}
  1634  		if err := json.Unmarshal(data, &value); err != nil {
  1635  			return err
  1636  		}
  1637  		s.Value = value
  1638  
  1639  	default:
  1640  		fmt.Println("Failed to decode BlockdevOptions", base.Driver)
  1641  	}
  1642  
  1643  	return nil
  1644  }
  1645  
  1646  // Options for creating an image format on a given node.
  1647  //
  1648  // Since: 2.12
  1649  type BlockdevCreateOptionsBase struct {
  1650  	Driver BlockdevDriver `json:"driver"` // block driver to create the image format
  1651  }
  1652  
  1653  // Options for creating an image format on a given node.
  1654  //
  1655  // Since: 2.12
  1656  type BlockdevCreateOptions struct {
  1657  	// Base type for this struct
  1658  	BlockdevCreateOptionsBase
  1659  	// Value based on @driver, possible types:
  1660  	// * BlockdevCreateOptionsFile
  1661  	// * BlockdevCreateOptionsGluster
  1662  	// * BlockdevCreateOptionsLUKS
  1663  	// * BlockdevCreateOptionsNfs
  1664  	// * BlockdevCreateOptionsParallels
  1665  	// * BlockdevCreateOptionsQcow
  1666  	// * BlockdevCreateOptionsQcow2
  1667  	// * BlockdevCreateOptionsQed
  1668  	// * BlockdevCreateOptionsRbd
  1669  	// * BlockdevCreateOptionsSsh
  1670  	// * BlockdevCreateOptionsVdi
  1671  	// * BlockdevCreateOptionsVhdx
  1672  	// * BlockdevCreateOptionsVmdk
  1673  	// * BlockdevCreateOptionsVpc
  1674  	Value Any
  1675  }
  1676  
  1677  func (s BlockdevCreateOptions) MarshalJSON() ([]byte, error) {
  1678  	base, err := json.Marshal(s.BlockdevCreateOptionsBase)
  1679  	if err != nil {
  1680  		return nil, err
  1681  	}
  1682  
  1683  	typestr := fmt.Sprintf("%T", s.Value)
  1684  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  1685  
  1686  	// "The branches need not cover all possible enum values"
  1687  	// This means that on Marshal, we can safely ignore empty values
  1688  	if typestr == "<nil>" {
  1689  		return []byte(base), nil
  1690  	}
  1691  
  1692  	// Runtime check for supported value types
  1693  	if typestr != "BlockdevCreateOptionsFile" &&
  1694  		typestr != "BlockdevCreateOptionsGluster" &&
  1695  		typestr != "BlockdevCreateOptionsLUKS" &&
  1696  		typestr != "BlockdevCreateOptionsNfs" &&
  1697  		typestr != "BlockdevCreateOptionsParallels" &&
  1698  		typestr != "BlockdevCreateOptionsQcow" &&
  1699  		typestr != "BlockdevCreateOptionsQcow2" &&
  1700  		typestr != "BlockdevCreateOptionsQed" &&
  1701  		typestr != "BlockdevCreateOptionsRbd" &&
  1702  		typestr != "BlockdevCreateOptionsSsh" &&
  1703  		typestr != "BlockdevCreateOptionsVdi" &&
  1704  		typestr != "BlockdevCreateOptionsVhdx" &&
  1705  		typestr != "BlockdevCreateOptionsVmdk" &&
  1706  		typestr != "BlockdevCreateOptionsVpc" {
  1707  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  1708  	}
  1709  	value, err := json.Marshal(s.Value)
  1710  	if err != nil {
  1711  		return nil, err
  1712  	}
  1713  
  1714  	// Workaround to avoid checking s.Value being empty
  1715  	if string(value) == "{}" {
  1716  		return []byte(base), nil
  1717  	}
  1718  
  1719  	// Removes the last '}' from base and the first '{' from value, in order to
  1720  	// return a single JSON object.
  1721  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  1722  	return []byte(result), nil
  1723  }
  1724  
  1725  func (s *BlockdevCreateOptions) UnmarshalJSON(data []byte) error {
  1726  
  1727  	var base BlockdevCreateOptionsBase
  1728  	if err := json.Unmarshal(data, &base); err != nil {
  1729  		return err
  1730  	}
  1731  	s.BlockdevCreateOptionsBase = base
  1732  
  1733  	switch base.Driver {
  1734  	case BlockdevDriverFile:
  1735  		value := BlockdevCreateOptionsFile{}
  1736  		if err := json.Unmarshal(data, &value); err != nil {
  1737  			return err
  1738  		}
  1739  		s.Value = value
  1740  	case BlockdevDriverGluster:
  1741  		value := BlockdevCreateOptionsGluster{}
  1742  		if err := json.Unmarshal(data, &value); err != nil {
  1743  			return err
  1744  		}
  1745  		s.Value = value
  1746  	case BlockdevDriverLuks:
  1747  		value := BlockdevCreateOptionsLUKS{}
  1748  		if err := json.Unmarshal(data, &value); err != nil {
  1749  			return err
  1750  		}
  1751  		s.Value = value
  1752  	case BlockdevDriverNfs:
  1753  		value := BlockdevCreateOptionsNfs{}
  1754  		if err := json.Unmarshal(data, &value); err != nil {
  1755  			return err
  1756  		}
  1757  		s.Value = value
  1758  	case BlockdevDriverParallels:
  1759  		value := BlockdevCreateOptionsParallels{}
  1760  		if err := json.Unmarshal(data, &value); err != nil {
  1761  			return err
  1762  		}
  1763  		s.Value = value
  1764  	case BlockdevDriverQcow:
  1765  		value := BlockdevCreateOptionsQcow{}
  1766  		if err := json.Unmarshal(data, &value); err != nil {
  1767  			return err
  1768  		}
  1769  		s.Value = value
  1770  	case BlockdevDriverQcow2:
  1771  		value := BlockdevCreateOptionsQcow2{}
  1772  		if err := json.Unmarshal(data, &value); err != nil {
  1773  			return err
  1774  		}
  1775  		s.Value = value
  1776  	case BlockdevDriverQed:
  1777  		value := BlockdevCreateOptionsQed{}
  1778  		if err := json.Unmarshal(data, &value); err != nil {
  1779  			return err
  1780  		}
  1781  		s.Value = value
  1782  	case BlockdevDriverRbd:
  1783  		value := BlockdevCreateOptionsRbd{}
  1784  		if err := json.Unmarshal(data, &value); err != nil {
  1785  			return err
  1786  		}
  1787  		s.Value = value
  1788  	case BlockdevDriverSsh:
  1789  		value := BlockdevCreateOptionsSsh{}
  1790  		if err := json.Unmarshal(data, &value); err != nil {
  1791  			return err
  1792  		}
  1793  		s.Value = value
  1794  	case BlockdevDriverVdi:
  1795  		value := BlockdevCreateOptionsVdi{}
  1796  		if err := json.Unmarshal(data, &value); err != nil {
  1797  			return err
  1798  		}
  1799  		s.Value = value
  1800  	case BlockdevDriverVhdx:
  1801  		value := BlockdevCreateOptionsVhdx{}
  1802  		if err := json.Unmarshal(data, &value); err != nil {
  1803  			return err
  1804  		}
  1805  		s.Value = value
  1806  	case BlockdevDriverVmdk:
  1807  		value := BlockdevCreateOptionsVmdk{}
  1808  		if err := json.Unmarshal(data, &value); err != nil {
  1809  			return err
  1810  		}
  1811  		s.Value = value
  1812  	case BlockdevDriverVpc:
  1813  		value := BlockdevCreateOptionsVpc{}
  1814  		if err := json.Unmarshal(data, &value); err != nil {
  1815  			return err
  1816  		}
  1817  		s.Value = value
  1818  
  1819  	default:
  1820  		fmt.Println("Failed to decode BlockdevCreateOptions", base.Driver)
  1821  	}
  1822  
  1823  	return nil
  1824  }
  1825  
  1826  // Options for amending an image format
  1827  //
  1828  // Since: 5.1
  1829  type BlockdevAmendOptionsBase struct {
  1830  	Driver BlockdevDriver `json:"driver"` // Block driver of the node to amend.
  1831  }
  1832  
  1833  // Options for amending an image format
  1834  //
  1835  // Since: 5.1
  1836  type BlockdevAmendOptions struct {
  1837  	// Base type for this struct
  1838  	BlockdevAmendOptionsBase
  1839  	// Value based on @driver, possible types:
  1840  	// * BlockdevAmendOptionsLUKS
  1841  	// * BlockdevAmendOptionsQcow2
  1842  	Value Any
  1843  }
  1844  
  1845  func (s BlockdevAmendOptions) MarshalJSON() ([]byte, error) {
  1846  	base, err := json.Marshal(s.BlockdevAmendOptionsBase)
  1847  	if err != nil {
  1848  		return nil, err
  1849  	}
  1850  
  1851  	typestr := fmt.Sprintf("%T", s.Value)
  1852  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  1853  
  1854  	// "The branches need not cover all possible enum values"
  1855  	// This means that on Marshal, we can safely ignore empty values
  1856  	if typestr == "<nil>" {
  1857  		return []byte(base), nil
  1858  	}
  1859  
  1860  	// Runtime check for supported value types
  1861  	if typestr != "BlockdevAmendOptionsLUKS" &&
  1862  		typestr != "BlockdevAmendOptionsQcow2" {
  1863  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  1864  	}
  1865  	value, err := json.Marshal(s.Value)
  1866  	if err != nil {
  1867  		return nil, err
  1868  	}
  1869  
  1870  	// Workaround to avoid checking s.Value being empty
  1871  	if string(value) == "{}" {
  1872  		return []byte(base), nil
  1873  	}
  1874  
  1875  	// Removes the last '}' from base and the first '{' from value, in order to
  1876  	// return a single JSON object.
  1877  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  1878  	return []byte(result), nil
  1879  }
  1880  
  1881  func (s *BlockdevAmendOptions) UnmarshalJSON(data []byte) error {
  1882  
  1883  	var base BlockdevAmendOptionsBase
  1884  	if err := json.Unmarshal(data, &base); err != nil {
  1885  		return err
  1886  	}
  1887  	s.BlockdevAmendOptionsBase = base
  1888  
  1889  	switch base.Driver {
  1890  	case BlockdevDriverLuks:
  1891  		value := BlockdevAmendOptionsLUKS{}
  1892  		if err := json.Unmarshal(data, &value); err != nil {
  1893  			return err
  1894  		}
  1895  		s.Value = value
  1896  	case BlockdevDriverQcow2:
  1897  		value := BlockdevAmendOptionsQcow2{}
  1898  		if err := json.Unmarshal(data, &value); err != nil {
  1899  			return err
  1900  		}
  1901  		s.Value = value
  1902  
  1903  	default:
  1904  		fmt.Println("Failed to decode BlockdevAmendOptions", base.Driver)
  1905  	}
  1906  
  1907  	return nil
  1908  }
  1909  
  1910  // Describes a block export, i.e. how single node should be exported on an
  1911  // external interface.
  1912  //
  1913  // Since: 4.2
  1914  type BlockExportOptionsBase struct {
  1915  	Type          BlockExportType `json:"type"`
  1916  	Id            string          `json:"id"`                       // A unique identifier for the block export (across all export types)
  1917  	FixedIothread *bool           `json:"fixed-iothread,omitempty"` // True prevents the block node from being moved to another thread while the export is active. If true and @iothread is given, export creation fails if the block node cannot be moved to the iothread. The default is false. (since: 5.2)
  1918  	Iothread      *string         `json:"iothread,omitempty"`       // The name of the iothread object where the export will run. The default is to use the thread currently associated with the block node. (since: 5.2)
  1919  	NodeName      string          `json:"node-name"`                // The node name of the block node to be exported (since: 5.2)
  1920  	Writable      *bool           `json:"writable,omitempty"`       // True if clients should be able to write to the export (default false)
  1921  	Writethrough  *bool           `json:"writethrough,omitempty"`   // If true, caches are flushed after every write request to the export before completion is signalled. (since: 5.2; default: false)
  1922  }
  1923  
  1924  // Describes a block export, i.e. how single node should be exported on an
  1925  // external interface.
  1926  //
  1927  // Since: 4.2
  1928  type BlockExportOptions struct {
  1929  	// Base type for this struct
  1930  	BlockExportOptionsBase
  1931  	// Value based on @type, possible types:
  1932  	// * BlockExportOptionsNbd
  1933  	// * BlockExportOptionsVhostUserBlk
  1934  	// * BlockExportOptionsFuse
  1935  	Value Any
  1936  }
  1937  
  1938  func (s BlockExportOptions) MarshalJSON() ([]byte, error) {
  1939  	base, err := json.Marshal(s.BlockExportOptionsBase)
  1940  	if err != nil {
  1941  		return nil, err
  1942  	}
  1943  
  1944  	typestr := fmt.Sprintf("%T", s.Value)
  1945  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  1946  
  1947  	// "The branches need not cover all possible enum values"
  1948  	// This means that on Marshal, we can safely ignore empty values
  1949  	if typestr == "<nil>" {
  1950  		return []byte(base), nil
  1951  	}
  1952  
  1953  	// Runtime check for supported value types
  1954  	if typestr != "BlockExportOptionsFuse" &&
  1955  		typestr != "BlockExportOptionsNbd" &&
  1956  		typestr != "BlockExportOptionsVhostUserBlk" {
  1957  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  1958  	}
  1959  	value, err := json.Marshal(s.Value)
  1960  	if err != nil {
  1961  		return nil, err
  1962  	}
  1963  
  1964  	// Workaround to avoid checking s.Value being empty
  1965  	if string(value) == "{}" {
  1966  		return []byte(base), nil
  1967  	}
  1968  
  1969  	// Removes the last '}' from base and the first '{' from value, in order to
  1970  	// return a single JSON object.
  1971  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  1972  	return []byte(result), nil
  1973  }
  1974  
  1975  func (s *BlockExportOptions) UnmarshalJSON(data []byte) error {
  1976  
  1977  	var base BlockExportOptionsBase
  1978  	if err := json.Unmarshal(data, &base); err != nil {
  1979  		return err
  1980  	}
  1981  	s.BlockExportOptionsBase = base
  1982  
  1983  	switch base.Type {
  1984  	case BlockExportTypeFuse:
  1985  		value := BlockExportOptionsFuse{}
  1986  		if err := json.Unmarshal(data, &value); err != nil {
  1987  			return err
  1988  		}
  1989  		s.Value = value
  1990  	case BlockExportTypeNbd:
  1991  		value := BlockExportOptionsNbd{}
  1992  		if err := json.Unmarshal(data, &value); err != nil {
  1993  			return err
  1994  		}
  1995  		s.Value = value
  1996  	case BlockExportTypeVhostUserBlk:
  1997  		value := BlockExportOptionsVhostUserBlk{}
  1998  		if err := json.Unmarshal(data, &value); err != nil {
  1999  			return err
  2000  		}
  2001  		s.Value = value
  2002  
  2003  	default:
  2004  		fmt.Println("Failed to decode BlockExportOptions", base.Type)
  2005  	}
  2006  
  2007  	return nil
  2008  }
  2009  
  2010  // Configuration info for the new chardev backend.
  2011  //
  2012  // Since: 1.4
  2013  type ChardevBackendBase struct {
  2014  	Type ChardevBackendKind `json:"type"`
  2015  }
  2016  
  2017  // Configuration info for the new chardev backend.
  2018  //
  2019  // Since: 1.4
  2020  type ChardevBackend struct {
  2021  	// Base type for this struct
  2022  	ChardevBackendBase
  2023  	// Value based on @type, possible types:
  2024  	// * ChardevFileWrapper
  2025  	// * ChardevHostdevWrapper
  2026  	// * ChardevHostdevWrapper
  2027  	// * ChardevHostdevWrapper
  2028  	// * ChardevSocketWrapper
  2029  	// * ChardevUdpWrapper
  2030  	// * ChardevCommonWrapper
  2031  	// * ChardevCommonWrapper
  2032  	// * ChardevMuxWrapper
  2033  	// * ChardevCommonWrapper
  2034  	// * ChardevCommonWrapper
  2035  	// * ChardevCommonWrapper
  2036  	// * ChardevCommonWrapper
  2037  	// * ChardevStdioWrapper
  2038  	// * ChardevCommonWrapper
  2039  	// * ChardevSpiceChannelWrapper
  2040  	// * ChardevSpicePortWrapper
  2041  	// * ChardevQemuVDAgentWrapper
  2042  	// * ChardevDBusWrapper
  2043  	// * ChardevVCWrapper
  2044  	// * ChardevRingbufWrapper
  2045  	// * ChardevRingbufWrapper
  2046  	Value Any
  2047  }
  2048  
  2049  func (s ChardevBackend) MarshalJSON() ([]byte, error) {
  2050  	base, err := json.Marshal(s.ChardevBackendBase)
  2051  	if err != nil {
  2052  		return nil, err
  2053  	}
  2054  
  2055  	typestr := fmt.Sprintf("%T", s.Value)
  2056  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  2057  
  2058  	// "The branches need not cover all possible enum values"
  2059  	// This means that on Marshal, we can safely ignore empty values
  2060  	if typestr == "<nil>" {
  2061  		return []byte(base), nil
  2062  	}
  2063  
  2064  	// Runtime check for supported value types
  2065  	if typestr != "ChardevCommonWrapper" &&
  2066  		typestr != "ChardevDBusWrapper" &&
  2067  		typestr != "ChardevFileWrapper" &&
  2068  		typestr != "ChardevRingbufWrapper" &&
  2069  		typestr != "ChardevMuxWrapper" &&
  2070  		typestr != "ChardevHostdevWrapper" &&
  2071  		typestr != "ChardevQemuVDAgentWrapper" &&
  2072  		typestr != "ChardevSocketWrapper" &&
  2073  		typestr != "ChardevSpicePortWrapper" &&
  2074  		typestr != "ChardevSpiceChannelWrapper" &&
  2075  		typestr != "ChardevStdioWrapper" &&
  2076  		typestr != "ChardevUdpWrapper" &&
  2077  		typestr != "ChardevVCWrapper" {
  2078  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  2079  	}
  2080  	value, err := json.Marshal(s.Value)
  2081  	if err != nil {
  2082  		return nil, err
  2083  	}
  2084  
  2085  	// Workaround to avoid checking s.Value being empty
  2086  	if string(value) == "{}" {
  2087  		return []byte(base), nil
  2088  	}
  2089  
  2090  	// Removes the last '}' from base and the first '{' from value, in order to
  2091  	// return a single JSON object.
  2092  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  2093  	return []byte(result), nil
  2094  }
  2095  
  2096  func (s *ChardevBackend) UnmarshalJSON(data []byte) error {
  2097  
  2098  	var base ChardevBackendBase
  2099  	if err := json.Unmarshal(data, &base); err != nil {
  2100  		return err
  2101  	}
  2102  	s.ChardevBackendBase = base
  2103  
  2104  	switch base.Type {
  2105  	case ChardevBackendKindBraille:
  2106  		value := ChardevCommonWrapper{}
  2107  		if err := json.Unmarshal(data, &value); err != nil {
  2108  			return err
  2109  		}
  2110  		s.Value = value
  2111  	case ChardevBackendKindConsole:
  2112  		value := ChardevCommonWrapper{}
  2113  		if err := json.Unmarshal(data, &value); err != nil {
  2114  			return err
  2115  		}
  2116  		s.Value = value
  2117  	case ChardevBackendKindDbus:
  2118  		value := ChardevDBusWrapper{}
  2119  		if err := json.Unmarshal(data, &value); err != nil {
  2120  			return err
  2121  		}
  2122  		s.Value = value
  2123  	case ChardevBackendKindFile:
  2124  		value := ChardevFileWrapper{}
  2125  		if err := json.Unmarshal(data, &value); err != nil {
  2126  			return err
  2127  		}
  2128  		s.Value = value
  2129  	case ChardevBackendKindMemory:
  2130  		value := ChardevRingbufWrapper{}
  2131  		if err := json.Unmarshal(data, &value); err != nil {
  2132  			return err
  2133  		}
  2134  		s.Value = value
  2135  	case ChardevBackendKindMsmouse:
  2136  		value := ChardevCommonWrapper{}
  2137  		if err := json.Unmarshal(data, &value); err != nil {
  2138  			return err
  2139  		}
  2140  		s.Value = value
  2141  	case ChardevBackendKindMux:
  2142  		value := ChardevMuxWrapper{}
  2143  		if err := json.Unmarshal(data, &value); err != nil {
  2144  			return err
  2145  		}
  2146  		s.Value = value
  2147  	case ChardevBackendKindNull:
  2148  		value := ChardevCommonWrapper{}
  2149  		if err := json.Unmarshal(data, &value); err != nil {
  2150  			return err
  2151  		}
  2152  		s.Value = value
  2153  	case ChardevBackendKindParallel:
  2154  		value := ChardevHostdevWrapper{}
  2155  		if err := json.Unmarshal(data, &value); err != nil {
  2156  			return err
  2157  		}
  2158  		s.Value = value
  2159  	case ChardevBackendKindPipe:
  2160  		value := ChardevHostdevWrapper{}
  2161  		if err := json.Unmarshal(data, &value); err != nil {
  2162  			return err
  2163  		}
  2164  		s.Value = value
  2165  	case ChardevBackendKindPty:
  2166  		value := ChardevCommonWrapper{}
  2167  		if err := json.Unmarshal(data, &value); err != nil {
  2168  			return err
  2169  		}
  2170  		s.Value = value
  2171  	case ChardevBackendKindQemuVdagent:
  2172  		value := ChardevQemuVDAgentWrapper{}
  2173  		if err := json.Unmarshal(data, &value); err != nil {
  2174  			return err
  2175  		}
  2176  		s.Value = value
  2177  	case ChardevBackendKindRingbuf:
  2178  		value := ChardevRingbufWrapper{}
  2179  		if err := json.Unmarshal(data, &value); err != nil {
  2180  			return err
  2181  		}
  2182  		s.Value = value
  2183  	case ChardevBackendKindSerial:
  2184  		value := ChardevHostdevWrapper{}
  2185  		if err := json.Unmarshal(data, &value); err != nil {
  2186  			return err
  2187  		}
  2188  		s.Value = value
  2189  	case ChardevBackendKindSocket:
  2190  		value := ChardevSocketWrapper{}
  2191  		if err := json.Unmarshal(data, &value); err != nil {
  2192  			return err
  2193  		}
  2194  		s.Value = value
  2195  	case ChardevBackendKindSpiceport:
  2196  		value := ChardevSpicePortWrapper{}
  2197  		if err := json.Unmarshal(data, &value); err != nil {
  2198  			return err
  2199  		}
  2200  		s.Value = value
  2201  	case ChardevBackendKindSpicevmc:
  2202  		value := ChardevSpiceChannelWrapper{}
  2203  		if err := json.Unmarshal(data, &value); err != nil {
  2204  			return err
  2205  		}
  2206  		s.Value = value
  2207  	case ChardevBackendKindStdio:
  2208  		value := ChardevStdioWrapper{}
  2209  		if err := json.Unmarshal(data, &value); err != nil {
  2210  			return err
  2211  		}
  2212  		s.Value = value
  2213  	case ChardevBackendKindTestdev:
  2214  		value := ChardevCommonWrapper{}
  2215  		if err := json.Unmarshal(data, &value); err != nil {
  2216  			return err
  2217  		}
  2218  		s.Value = value
  2219  	case ChardevBackendKindUdp:
  2220  		value := ChardevUdpWrapper{}
  2221  		if err := json.Unmarshal(data, &value); err != nil {
  2222  			return err
  2223  		}
  2224  		s.Value = value
  2225  	case ChardevBackendKindVc:
  2226  		value := ChardevVCWrapper{}
  2227  		if err := json.Unmarshal(data, &value); err != nil {
  2228  			return err
  2229  		}
  2230  		s.Value = value
  2231  	case ChardevBackendKindWctablet:
  2232  		value := ChardevCommonWrapper{}
  2233  		if err := json.Unmarshal(data, &value); err != nil {
  2234  			return err
  2235  		}
  2236  		s.Value = value
  2237  
  2238  	default:
  2239  		fmt.Println("Failed to decode ChardevBackend", base.Type)
  2240  	}
  2241  
  2242  	return nil
  2243  }
  2244  
  2245  // Captures the configuration of a network device.
  2246  //
  2247  // Since: 1.2
  2248  //
  2249  // 'l2tpv3' - since 2.1
  2250  type NetdevBase struct {
  2251  	Id   string          `json:"id"`   // identifier for monitor commands.
  2252  	Type NetClientDriver `json:"type"` // Specify the driver used for interpreting remaining arguments.
  2253  }
  2254  
  2255  // Captures the configuration of a network device.
  2256  //
  2257  // Since: 1.2
  2258  //
  2259  // 'l2tpv3' - since 2.1
  2260  type Netdev struct {
  2261  	// Base type for this struct
  2262  	NetdevBase
  2263  	// Value based on @type, possible types:
  2264  	// * NetLegacyNicOptions
  2265  	// * NetdevUserOptions
  2266  	// * NetdevTapOptions
  2267  	// * NetdevL2TPv3Options
  2268  	// * NetdevSocketOptions
  2269  	// * NetdevVdeOptions
  2270  	// * NetdevBridgeOptions
  2271  	// * NetdevHubPortOptions
  2272  	// * NetdevNetmapOptions
  2273  	// * NetdevVhostUserOptions
  2274  	// * NetdevVhostVDPAOptions
  2275  	Value Any
  2276  }
  2277  
  2278  func (s Netdev) MarshalJSON() ([]byte, error) {
  2279  	base, err := json.Marshal(s.NetdevBase)
  2280  	if err != nil {
  2281  		return nil, err
  2282  	}
  2283  
  2284  	typestr := fmt.Sprintf("%T", s.Value)
  2285  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  2286  
  2287  	// "The branches need not cover all possible enum values"
  2288  	// This means that on Marshal, we can safely ignore empty values
  2289  	if typestr == "<nil>" {
  2290  		return []byte(base), nil
  2291  	}
  2292  
  2293  	// Runtime check for supported value types
  2294  	if typestr != "NetdevBridgeOptions" &&
  2295  		typestr != "NetdevHubPortOptions" &&
  2296  		typestr != "NetdevL2TPv3Options" &&
  2297  		typestr != "NetdevNetmapOptions" &&
  2298  		typestr != "NetLegacyNicOptions" &&
  2299  		typestr != "NetdevSocketOptions" &&
  2300  		typestr != "NetdevTapOptions" &&
  2301  		typestr != "NetdevUserOptions" &&
  2302  		typestr != "NetdevVdeOptions" &&
  2303  		typestr != "NetdevVhostUserOptions" &&
  2304  		typestr != "NetdevVhostVDPAOptions" {
  2305  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  2306  	}
  2307  	value, err := json.Marshal(s.Value)
  2308  	if err != nil {
  2309  		return nil, err
  2310  	}
  2311  
  2312  	// Workaround to avoid checking s.Value being empty
  2313  	if string(value) == "{}" {
  2314  		return []byte(base), nil
  2315  	}
  2316  
  2317  	// Removes the last '}' from base and the first '{' from value, in order to
  2318  	// return a single JSON object.
  2319  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  2320  	return []byte(result), nil
  2321  }
  2322  
  2323  func (s *Netdev) UnmarshalJSON(data []byte) error {
  2324  
  2325  	var base NetdevBase
  2326  	if err := json.Unmarshal(data, &base); err != nil {
  2327  		return err
  2328  	}
  2329  	s.NetdevBase = base
  2330  
  2331  	switch base.Type {
  2332  	case NetClientDriverBridge:
  2333  		value := NetdevBridgeOptions{}
  2334  		if err := json.Unmarshal(data, &value); err != nil {
  2335  			return err
  2336  		}
  2337  		s.Value = value
  2338  	case NetClientDriverHubport:
  2339  		value := NetdevHubPortOptions{}
  2340  		if err := json.Unmarshal(data, &value); err != nil {
  2341  			return err
  2342  		}
  2343  		s.Value = value
  2344  	case NetClientDriverL2Tpv3:
  2345  		value := NetdevL2TPv3Options{}
  2346  		if err := json.Unmarshal(data, &value); err != nil {
  2347  			return err
  2348  		}
  2349  		s.Value = value
  2350  	case NetClientDriverNetmap:
  2351  		value := NetdevNetmapOptions{}
  2352  		if err := json.Unmarshal(data, &value); err != nil {
  2353  			return err
  2354  		}
  2355  		s.Value = value
  2356  	case NetClientDriverNic:
  2357  		value := NetLegacyNicOptions{}
  2358  		if err := json.Unmarshal(data, &value); err != nil {
  2359  			return err
  2360  		}
  2361  		s.Value = value
  2362  	case NetClientDriverSocket:
  2363  		value := NetdevSocketOptions{}
  2364  		if err := json.Unmarshal(data, &value); err != nil {
  2365  			return err
  2366  		}
  2367  		s.Value = value
  2368  	case NetClientDriverTap:
  2369  		value := NetdevTapOptions{}
  2370  		if err := json.Unmarshal(data, &value); err != nil {
  2371  			return err
  2372  		}
  2373  		s.Value = value
  2374  	case NetClientDriverUser:
  2375  		value := NetdevUserOptions{}
  2376  		if err := json.Unmarshal(data, &value); err != nil {
  2377  			return err
  2378  		}
  2379  		s.Value = value
  2380  	case NetClientDriverVde:
  2381  		value := NetdevVdeOptions{}
  2382  		if err := json.Unmarshal(data, &value); err != nil {
  2383  			return err
  2384  		}
  2385  		s.Value = value
  2386  	case NetClientDriverVhostUser:
  2387  		value := NetdevVhostUserOptions{}
  2388  		if err := json.Unmarshal(data, &value); err != nil {
  2389  			return err
  2390  		}
  2391  		s.Value = value
  2392  	case NetClientDriverVhostVdpa:
  2393  		value := NetdevVhostVDPAOptions{}
  2394  		if err := json.Unmarshal(data, &value); err != nil {
  2395  			return err
  2396  		}
  2397  		s.Value = value
  2398  
  2399  	default:
  2400  		fmt.Println("Failed to decode Netdev", base.Type)
  2401  	}
  2402  
  2403  	return nil
  2404  }
  2405  
  2406  // A union referencing different TPM backend types' configuration options
  2407  //
  2408  // Since: 1.5
  2409  type TpmTypeOptionsBase struct {
  2410  	Type TpmType `json:"type"` // - 'passthrough' The configuration options for the TPM passthrough type - 'emulator' The configuration options for TPM emulator backend type
  2411  }
  2412  
  2413  // A union referencing different TPM backend types' configuration options
  2414  //
  2415  // Since: 1.5
  2416  type TpmTypeOptions struct {
  2417  	// Base type for this struct
  2418  	TpmTypeOptionsBase
  2419  	// Value based on @type, possible types:
  2420  	// * TPMPassthroughOptionsWrapper
  2421  	// * TPMEmulatorOptionsWrapper
  2422  	Value Any
  2423  }
  2424  
  2425  func (s TpmTypeOptions) MarshalJSON() ([]byte, error) {
  2426  	base, err := json.Marshal(s.TpmTypeOptionsBase)
  2427  	if err != nil {
  2428  		return nil, err
  2429  	}
  2430  
  2431  	typestr := fmt.Sprintf("%T", s.Value)
  2432  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  2433  
  2434  	// "The branches need not cover all possible enum values"
  2435  	// This means that on Marshal, we can safely ignore empty values
  2436  	if typestr == "<nil>" {
  2437  		return []byte(base), nil
  2438  	}
  2439  
  2440  	// Runtime check for supported value types
  2441  	if typestr != "TPMEmulatorOptionsWrapper" &&
  2442  		typestr != "TPMPassthroughOptionsWrapper" {
  2443  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  2444  	}
  2445  	value, err := json.Marshal(s.Value)
  2446  	if err != nil {
  2447  		return nil, err
  2448  	}
  2449  
  2450  	// Workaround to avoid checking s.Value being empty
  2451  	if string(value) == "{}" {
  2452  		return []byte(base), nil
  2453  	}
  2454  
  2455  	// Removes the last '}' from base and the first '{' from value, in order to
  2456  	// return a single JSON object.
  2457  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  2458  	return []byte(result), nil
  2459  }
  2460  
  2461  func (s *TpmTypeOptions) UnmarshalJSON(data []byte) error {
  2462  
  2463  	var base TpmTypeOptionsBase
  2464  	if err := json.Unmarshal(data, &base); err != nil {
  2465  		return err
  2466  	}
  2467  	s.TpmTypeOptionsBase = base
  2468  
  2469  	switch base.Type {
  2470  	case TpmTypeEmulator:
  2471  		value := TPMEmulatorOptionsWrapper{}
  2472  		if err := json.Unmarshal(data, &value); err != nil {
  2473  			return err
  2474  		}
  2475  		s.Value = value
  2476  	case TpmTypePassthrough:
  2477  		value := TPMPassthroughOptionsWrapper{}
  2478  		if err := json.Unmarshal(data, &value); err != nil {
  2479  			return err
  2480  		}
  2481  		s.Value = value
  2482  
  2483  	default:
  2484  		fmt.Println("Failed to decode TpmTypeOptions", base.Type)
  2485  	}
  2486  
  2487  	return nil
  2488  }
  2489  
  2490  // Options for set_password.
  2491  //
  2492  // Since: 7.0
  2493  type SetPasswordOptionsBase struct {
  2494  	Protocol  DisplayProtocol    `json:"protocol"`            // - 'vnc' to modify the VNC server password - 'spice' to modify the Spice server password
  2495  	Password  string             `json:"password"`            // the new password
  2496  	Connected *SetPasswordAction `json:"connected,omitempty"` // How to handle existing clients when changing the password. If nothing is specified, defaults to 'keep'. For VNC, only 'keep' is currently implemented.
  2497  }
  2498  
  2499  // Options for set_password.
  2500  //
  2501  // Since: 7.0
  2502  type SetPasswordOptions struct {
  2503  	// Base type for this struct
  2504  	SetPasswordOptionsBase
  2505  	// Value based on @protocol, possible types:
  2506  	// * SetPasswordOptionsVnc
  2507  	Value Any
  2508  }
  2509  
  2510  func (s SetPasswordOptions) MarshalJSON() ([]byte, error) {
  2511  	base, err := json.Marshal(s.SetPasswordOptionsBase)
  2512  	if err != nil {
  2513  		return nil, err
  2514  	}
  2515  
  2516  	typestr := fmt.Sprintf("%T", s.Value)
  2517  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  2518  
  2519  	// "The branches need not cover all possible enum values"
  2520  	// This means that on Marshal, we can safely ignore empty values
  2521  	if typestr == "<nil>" {
  2522  		return []byte(base), nil
  2523  	}
  2524  
  2525  	// Runtime check for supported value types
  2526  	if typestr != "SetPasswordOptionsVnc" {
  2527  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  2528  	}
  2529  	value, err := json.Marshal(s.Value)
  2530  	if err != nil {
  2531  		return nil, err
  2532  	}
  2533  
  2534  	// Workaround to avoid checking s.Value being empty
  2535  	if string(value) == "{}" {
  2536  		return []byte(base), nil
  2537  	}
  2538  
  2539  	// Removes the last '}' from base and the first '{' from value, in order to
  2540  	// return a single JSON object.
  2541  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  2542  	return []byte(result), nil
  2543  }
  2544  
  2545  func (s *SetPasswordOptions) UnmarshalJSON(data []byte) error {
  2546  
  2547  	var base SetPasswordOptionsBase
  2548  	if err := json.Unmarshal(data, &base); err != nil {
  2549  		return err
  2550  	}
  2551  	s.SetPasswordOptionsBase = base
  2552  
  2553  	switch base.Protocol {
  2554  	case DisplayProtocolVnc:
  2555  		value := SetPasswordOptionsVnc{}
  2556  		if err := json.Unmarshal(data, &value); err != nil {
  2557  			return err
  2558  		}
  2559  		s.Value = value
  2560  
  2561  	default:
  2562  		fmt.Println("Failed to decode SetPasswordOptions", base.Protocol)
  2563  	}
  2564  
  2565  	return nil
  2566  }
  2567  
  2568  // General options for expire_password.
  2569  //
  2570  // Notes: Time is relative to the server and currently there is no way to
  2571  // coordinate server time with client time.  It is not recommended to
  2572  // use the absolute time version of the @time parameter unless you're
  2573  // sure you are on the same machine as the QEMU instance.
  2574  //
  2575  // Since: 7.0
  2576  type ExpirePasswordOptionsBase struct {
  2577  	Protocol DisplayProtocol `json:"protocol"` // - 'vnc' to modify the VNC server expiration - 'spice' to modify the Spice server expiration
  2578  	Time     string          `json:"time"`     // when to expire the password. - 'now' to expire the password immediately - 'never' to cancel password expiration - '+INT' where INT is the number of seconds from now (integer) - 'INT' where INT is the absolute time in seconds
  2579  }
  2580  
  2581  // General options for expire_password.
  2582  //
  2583  // Notes: Time is relative to the server and currently there is no way to
  2584  // coordinate server time with client time.  It is not recommended to
  2585  // use the absolute time version of the @time parameter unless you're
  2586  // sure you are on the same machine as the QEMU instance.
  2587  //
  2588  // Since: 7.0
  2589  type ExpirePasswordOptions struct {
  2590  	// Base type for this struct
  2591  	ExpirePasswordOptionsBase
  2592  	// Value based on @protocol, possible types:
  2593  	// * ExpirePasswordOptionsVnc
  2594  	Value Any
  2595  }
  2596  
  2597  func (s ExpirePasswordOptions) MarshalJSON() ([]byte, error) {
  2598  	base, err := json.Marshal(s.ExpirePasswordOptionsBase)
  2599  	if err != nil {
  2600  		return nil, err
  2601  	}
  2602  
  2603  	typestr := fmt.Sprintf("%T", s.Value)
  2604  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  2605  
  2606  	// "The branches need not cover all possible enum values"
  2607  	// This means that on Marshal, we can safely ignore empty values
  2608  	if typestr == "<nil>" {
  2609  		return []byte(base), nil
  2610  	}
  2611  
  2612  	// Runtime check for supported value types
  2613  	if typestr != "ExpirePasswordOptionsVnc" {
  2614  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  2615  	}
  2616  	value, err := json.Marshal(s.Value)
  2617  	if err != nil {
  2618  		return nil, err
  2619  	}
  2620  
  2621  	// Workaround to avoid checking s.Value being empty
  2622  	if string(value) == "{}" {
  2623  		return []byte(base), nil
  2624  	}
  2625  
  2626  	// Removes the last '}' from base and the first '{' from value, in order to
  2627  	// return a single JSON object.
  2628  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  2629  	return []byte(result), nil
  2630  }
  2631  
  2632  func (s *ExpirePasswordOptions) UnmarshalJSON(data []byte) error {
  2633  
  2634  	var base ExpirePasswordOptionsBase
  2635  	if err := json.Unmarshal(data, &base); err != nil {
  2636  		return err
  2637  	}
  2638  	s.ExpirePasswordOptionsBase = base
  2639  
  2640  	switch base.Protocol {
  2641  	case DisplayProtocolVnc:
  2642  		value := ExpirePasswordOptionsVnc{}
  2643  		if err := json.Unmarshal(data, &value); err != nil {
  2644  			return err
  2645  		}
  2646  		s.Value = value
  2647  
  2648  	default:
  2649  		fmt.Println("Failed to decode ExpirePasswordOptions", base.Protocol)
  2650  	}
  2651  
  2652  	return nil
  2653  }
  2654  
  2655  // Represents a keyboard key.
  2656  //
  2657  // Since: 1.3
  2658  type KeyValueBase struct {
  2659  	Type KeyValueKind `json:"type"`
  2660  }
  2661  
  2662  // Represents a keyboard key.
  2663  //
  2664  // Since: 1.3
  2665  type KeyValue struct {
  2666  	// Base type for this struct
  2667  	KeyValueBase
  2668  	// Value based on @type, possible types:
  2669  	// * IntWrapper
  2670  	// * QKeyCodeWrapper
  2671  	Value Any
  2672  }
  2673  
  2674  func (s KeyValue) MarshalJSON() ([]byte, error) {
  2675  	base, err := json.Marshal(s.KeyValueBase)
  2676  	if err != nil {
  2677  		return nil, err
  2678  	}
  2679  
  2680  	typestr := fmt.Sprintf("%T", s.Value)
  2681  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  2682  
  2683  	// "The branches need not cover all possible enum values"
  2684  	// This means that on Marshal, we can safely ignore empty values
  2685  	if typestr == "<nil>" {
  2686  		return []byte(base), nil
  2687  	}
  2688  
  2689  	// Runtime check for supported value types
  2690  	if typestr != "IntWrapper" &&
  2691  		typestr != "QKeyCodeWrapper" {
  2692  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  2693  	}
  2694  	value, err := json.Marshal(s.Value)
  2695  	if err != nil {
  2696  		return nil, err
  2697  	}
  2698  
  2699  	// Workaround to avoid checking s.Value being empty
  2700  	if string(value) == "{}" {
  2701  		return []byte(base), nil
  2702  	}
  2703  
  2704  	// Removes the last '}' from base and the first '{' from value, in order to
  2705  	// return a single JSON object.
  2706  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  2707  	return []byte(result), nil
  2708  }
  2709  
  2710  func (s *KeyValue) UnmarshalJSON(data []byte) error {
  2711  
  2712  	var base KeyValueBase
  2713  	if err := json.Unmarshal(data, &base); err != nil {
  2714  		return err
  2715  	}
  2716  	s.KeyValueBase = base
  2717  
  2718  	switch base.Type {
  2719  	case KeyValueKindNumber:
  2720  		value := IntWrapper{}
  2721  		if err := json.Unmarshal(data, &value); err != nil {
  2722  			return err
  2723  		}
  2724  		s.Value = value
  2725  	case KeyValueKindQcode:
  2726  		value := QKeyCodeWrapper{}
  2727  		if err := json.Unmarshal(data, &value); err != nil {
  2728  			return err
  2729  		}
  2730  		s.Value = value
  2731  
  2732  	default:
  2733  		fmt.Println("Failed to decode KeyValue", base.Type)
  2734  	}
  2735  
  2736  	return nil
  2737  }
  2738  
  2739  // Input event union.
  2740  //
  2741  // Since: 2.0
  2742  type InputEventBase struct {
  2743  	Type InputEventKind `json:"type"` // the input type, one of: - 'key': Input event of Keyboard - 'btn': Input event of pointer buttons - 'rel': Input event of relative pointer motion - 'abs': Input event of absolute pointer motion
  2744  }
  2745  
  2746  // Input event union.
  2747  //
  2748  // Since: 2.0
  2749  type InputEvent struct {
  2750  	// Base type for this struct
  2751  	InputEventBase
  2752  	// Value based on @type, possible types:
  2753  	// * InputKeyEventWrapper
  2754  	// * InputBtnEventWrapper
  2755  	// * InputMoveEventWrapper
  2756  	// * InputMoveEventWrapper
  2757  	Value Any
  2758  }
  2759  
  2760  func (s InputEvent) MarshalJSON() ([]byte, error) {
  2761  	base, err := json.Marshal(s.InputEventBase)
  2762  	if err != nil {
  2763  		return nil, err
  2764  	}
  2765  
  2766  	typestr := fmt.Sprintf("%T", s.Value)
  2767  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  2768  
  2769  	// "The branches need not cover all possible enum values"
  2770  	// This means that on Marshal, we can safely ignore empty values
  2771  	if typestr == "<nil>" {
  2772  		return []byte(base), nil
  2773  	}
  2774  
  2775  	// Runtime check for supported value types
  2776  	if typestr != "InputMoveEventWrapper" &&
  2777  		typestr != "InputBtnEventWrapper" &&
  2778  		typestr != "InputKeyEventWrapper" {
  2779  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  2780  	}
  2781  	value, err := json.Marshal(s.Value)
  2782  	if err != nil {
  2783  		return nil, err
  2784  	}
  2785  
  2786  	// Workaround to avoid checking s.Value being empty
  2787  	if string(value) == "{}" {
  2788  		return []byte(base), nil
  2789  	}
  2790  
  2791  	// Removes the last '}' from base and the first '{' from value, in order to
  2792  	// return a single JSON object.
  2793  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  2794  	return []byte(result), nil
  2795  }
  2796  
  2797  func (s *InputEvent) UnmarshalJSON(data []byte) error {
  2798  
  2799  	var base InputEventBase
  2800  	if err := json.Unmarshal(data, &base); err != nil {
  2801  		return err
  2802  	}
  2803  	s.InputEventBase = base
  2804  
  2805  	switch base.Type {
  2806  	case InputEventKindAbs:
  2807  		value := InputMoveEventWrapper{}
  2808  		if err := json.Unmarshal(data, &value); err != nil {
  2809  			return err
  2810  		}
  2811  		s.Value = value
  2812  	case InputEventKindBtn:
  2813  		value := InputBtnEventWrapper{}
  2814  		if err := json.Unmarshal(data, &value); err != nil {
  2815  			return err
  2816  		}
  2817  		s.Value = value
  2818  	case InputEventKindKey:
  2819  		value := InputKeyEventWrapper{}
  2820  		if err := json.Unmarshal(data, &value); err != nil {
  2821  			return err
  2822  		}
  2823  		s.Value = value
  2824  	case InputEventKindRel:
  2825  		value := InputMoveEventWrapper{}
  2826  		if err := json.Unmarshal(data, &value); err != nil {
  2827  			return err
  2828  		}
  2829  		s.Value = value
  2830  
  2831  	default:
  2832  		fmt.Println("Failed to decode InputEvent", base.Type)
  2833  	}
  2834  
  2835  	return nil
  2836  }
  2837  
  2838  // Display (user interface) options.
  2839  //
  2840  // Since: 2.12
  2841  type DisplayOptionsBase struct {
  2842  	Type        DisplayType    `json:"type"`                   // Which DisplayType qemu should use.
  2843  	FullScreen  *bool          `json:"full-screen,omitempty"`  // Start user interface in fullscreen mode (default: off).
  2844  	WindowClose *bool          `json:"window-close,omitempty"` // Allow to quit qemu with window close button (default: on).
  2845  	ShowCursor  *bool          `json:"show-cursor,omitempty"`  // Force showing the mouse cursor (default: off). (since: 5.0)
  2846  	Gl          *DisplayGLMode `json:"gl,omitempty"`           // Enable OpenGL support (default: off).
  2847  }
  2848  
  2849  // Display (user interface) options.
  2850  //
  2851  // Since: 2.12
  2852  type DisplayOptions struct {
  2853  	// Base type for this struct
  2854  	DisplayOptionsBase
  2855  	// Value based on @type, possible types:
  2856  	// * DisplayGTK
  2857  	// * DisplayCocoa
  2858  	// * DisplayCurses
  2859  	// * DisplayEGLHeadless
  2860  	// * DisplayDBus
  2861  	Value Any
  2862  }
  2863  
  2864  func (s DisplayOptions) MarshalJSON() ([]byte, error) {
  2865  	base, err := json.Marshal(s.DisplayOptionsBase)
  2866  	if err != nil {
  2867  		return nil, err
  2868  	}
  2869  
  2870  	typestr := fmt.Sprintf("%T", s.Value)
  2871  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  2872  
  2873  	// "The branches need not cover all possible enum values"
  2874  	// This means that on Marshal, we can safely ignore empty values
  2875  	if typestr == "<nil>" {
  2876  		return []byte(base), nil
  2877  	}
  2878  
  2879  	// Runtime check for supported value types
  2880  	if typestr != "DisplayCocoa" &&
  2881  		typestr != "DisplayCurses" &&
  2882  		typestr != "DisplayDBus" &&
  2883  		typestr != "DisplayEGLHeadless" &&
  2884  		typestr != "DisplayGTK" {
  2885  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  2886  	}
  2887  	value, err := json.Marshal(s.Value)
  2888  	if err != nil {
  2889  		return nil, err
  2890  	}
  2891  
  2892  	// Workaround to avoid checking s.Value being empty
  2893  	if string(value) == "{}" {
  2894  		return []byte(base), nil
  2895  	}
  2896  
  2897  	// Removes the last '}' from base and the first '{' from value, in order to
  2898  	// return a single JSON object.
  2899  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  2900  	return []byte(result), nil
  2901  }
  2902  
  2903  func (s *DisplayOptions) UnmarshalJSON(data []byte) error {
  2904  
  2905  	var base DisplayOptionsBase
  2906  	if err := json.Unmarshal(data, &base); err != nil {
  2907  		return err
  2908  	}
  2909  	s.DisplayOptionsBase = base
  2910  
  2911  	switch base.Type {
  2912  	case DisplayTypeCocoa:
  2913  		value := DisplayCocoa{}
  2914  		if err := json.Unmarshal(data, &value); err != nil {
  2915  			return err
  2916  		}
  2917  		s.Value = value
  2918  	case DisplayTypeCurses:
  2919  		value := DisplayCurses{}
  2920  		if err := json.Unmarshal(data, &value); err != nil {
  2921  			return err
  2922  		}
  2923  		s.Value = value
  2924  	case DisplayTypeDbus:
  2925  		value := DisplayDBus{}
  2926  		if err := json.Unmarshal(data, &value); err != nil {
  2927  			return err
  2928  		}
  2929  		s.Value = value
  2930  	case DisplayTypeEglHeadless:
  2931  		value := DisplayEGLHeadless{}
  2932  		if err := json.Unmarshal(data, &value); err != nil {
  2933  			return err
  2934  		}
  2935  		s.Value = value
  2936  	case DisplayTypeGtk:
  2937  		value := DisplayGTK{}
  2938  		if err := json.Unmarshal(data, &value); err != nil {
  2939  			return err
  2940  		}
  2941  		s.Value = value
  2942  
  2943  	default:
  2944  		fmt.Println("Failed to decode DisplayOptions", base.Type)
  2945  	}
  2946  
  2947  	return nil
  2948  }
  2949  
  2950  // Options of the display configuration reload.
  2951  //
  2952  // Since: 6.0
  2953  type DisplayReloadOptionsBase struct {
  2954  	Type DisplayReloadType `json:"type"` // Specify the display type.
  2955  }
  2956  
  2957  // Options of the display configuration reload.
  2958  //
  2959  // Since: 6.0
  2960  type DisplayReloadOptions struct {
  2961  	// Base type for this struct
  2962  	DisplayReloadOptionsBase
  2963  	// Value based on @type, possible types:
  2964  	// * DisplayReloadOptionsVNC
  2965  	Value Any
  2966  }
  2967  
  2968  func (s DisplayReloadOptions) MarshalJSON() ([]byte, error) {
  2969  	base, err := json.Marshal(s.DisplayReloadOptionsBase)
  2970  	if err != nil {
  2971  		return nil, err
  2972  	}
  2973  
  2974  	typestr := fmt.Sprintf("%T", s.Value)
  2975  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  2976  
  2977  	// "The branches need not cover all possible enum values"
  2978  	// This means that on Marshal, we can safely ignore empty values
  2979  	if typestr == "<nil>" {
  2980  		return []byte(base), nil
  2981  	}
  2982  
  2983  	// Runtime check for supported value types
  2984  	if typestr != "DisplayReloadOptionsVNC" {
  2985  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  2986  	}
  2987  	value, err := json.Marshal(s.Value)
  2988  	if err != nil {
  2989  		return nil, err
  2990  	}
  2991  
  2992  	// Workaround to avoid checking s.Value being empty
  2993  	if string(value) == "{}" {
  2994  		return []byte(base), nil
  2995  	}
  2996  
  2997  	// Removes the last '}' from base and the first '{' from value, in order to
  2998  	// return a single JSON object.
  2999  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  3000  	return []byte(result), nil
  3001  }
  3002  
  3003  func (s *DisplayReloadOptions) UnmarshalJSON(data []byte) error {
  3004  
  3005  	var base DisplayReloadOptionsBase
  3006  	if err := json.Unmarshal(data, &base); err != nil {
  3007  		return err
  3008  	}
  3009  	s.DisplayReloadOptionsBase = base
  3010  
  3011  	switch base.Type {
  3012  	case DisplayReloadTypeVnc:
  3013  		value := DisplayReloadOptionsVNC{}
  3014  		if err := json.Unmarshal(data, &value); err != nil {
  3015  			return err
  3016  		}
  3017  		s.Value = value
  3018  
  3019  	default:
  3020  		fmt.Println("Failed to decode DisplayReloadOptions", base.Type)
  3021  	}
  3022  
  3023  	return nil
  3024  }
  3025  
  3026  // A discriminated record of operations that can be performed with
  3027  // @transaction.
  3028  //
  3029  // Since: 1.1
  3030  type TransactionActionBase struct {
  3031  	Type TransactionActionKind `json:"type"`
  3032  }
  3033  
  3034  // A discriminated record of operations that can be performed with
  3035  // @transaction.
  3036  //
  3037  // Since: 1.1
  3038  type TransactionAction struct {
  3039  	// Base type for this struct
  3040  	TransactionActionBase
  3041  	// Value based on @type, possible types:
  3042  	// * AbortWrapper
  3043  	// * BlockDirtyBitmapAddWrapper
  3044  	// * BlockDirtyBitmapWrapper
  3045  	// * BlockDirtyBitmapWrapper
  3046  	// * BlockDirtyBitmapWrapper
  3047  	// * BlockDirtyBitmapWrapper
  3048  	// * BlockDirtyBitmapMergeWrapper
  3049  	// * BlockdevBackupWrapper
  3050  	// * BlockdevSnapshotWrapper
  3051  	// * BlockdevSnapshotInternalWrapper
  3052  	// * BlockdevSnapshotSyncWrapper
  3053  	// * DriveBackupWrapper
  3054  	Value Any
  3055  }
  3056  
  3057  func (s TransactionAction) MarshalJSON() ([]byte, error) {
  3058  	base, err := json.Marshal(s.TransactionActionBase)
  3059  	if err != nil {
  3060  		return nil, err
  3061  	}
  3062  
  3063  	typestr := fmt.Sprintf("%T", s.Value)
  3064  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  3065  
  3066  	// "The branches need not cover all possible enum values"
  3067  	// This means that on Marshal, we can safely ignore empty values
  3068  	if typestr == "<nil>" {
  3069  		return []byte(base), nil
  3070  	}
  3071  
  3072  	// Runtime check for supported value types
  3073  	if typestr != "AbortWrapper" &&
  3074  		typestr != "BlockDirtyBitmapAddWrapper" &&
  3075  		typestr != "BlockDirtyBitmapWrapper" &&
  3076  		typestr != "BlockDirtyBitmapMergeWrapper" &&
  3077  		typestr != "BlockdevBackupWrapper" &&
  3078  		typestr != "BlockdevSnapshotWrapper" &&
  3079  		typestr != "BlockdevSnapshotInternalWrapper" &&
  3080  		typestr != "BlockdevSnapshotSyncWrapper" &&
  3081  		typestr != "DriveBackupWrapper" {
  3082  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  3083  	}
  3084  	value, err := json.Marshal(s.Value)
  3085  	if err != nil {
  3086  		return nil, err
  3087  	}
  3088  
  3089  	// Workaround to avoid checking s.Value being empty
  3090  	if string(value) == "{}" {
  3091  		return []byte(base), nil
  3092  	}
  3093  
  3094  	// Removes the last '}' from base and the first '{' from value, in order to
  3095  	// return a single JSON object.
  3096  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  3097  	return []byte(result), nil
  3098  }
  3099  
  3100  func (s *TransactionAction) UnmarshalJSON(data []byte) error {
  3101  
  3102  	var base TransactionActionBase
  3103  	if err := json.Unmarshal(data, &base); err != nil {
  3104  		return err
  3105  	}
  3106  	s.TransactionActionBase = base
  3107  
  3108  	switch base.Type {
  3109  	case TransactionActionKindAbort:
  3110  		value := AbortWrapper{}
  3111  		if err := json.Unmarshal(data, &value); err != nil {
  3112  			return err
  3113  		}
  3114  		s.Value = value
  3115  	case TransactionActionKindBlockDirtyBitmapAdd:
  3116  		value := BlockDirtyBitmapAddWrapper{}
  3117  		if err := json.Unmarshal(data, &value); err != nil {
  3118  			return err
  3119  		}
  3120  		s.Value = value
  3121  	case TransactionActionKindBlockDirtyBitmapClear:
  3122  		value := BlockDirtyBitmapWrapper{}
  3123  		if err := json.Unmarshal(data, &value); err != nil {
  3124  			return err
  3125  		}
  3126  		s.Value = value
  3127  	case TransactionActionKindBlockDirtyBitmapDisable:
  3128  		value := BlockDirtyBitmapWrapper{}
  3129  		if err := json.Unmarshal(data, &value); err != nil {
  3130  			return err
  3131  		}
  3132  		s.Value = value
  3133  	case TransactionActionKindBlockDirtyBitmapEnable:
  3134  		value := BlockDirtyBitmapWrapper{}
  3135  		if err := json.Unmarshal(data, &value); err != nil {
  3136  			return err
  3137  		}
  3138  		s.Value = value
  3139  	case TransactionActionKindBlockDirtyBitmapMerge:
  3140  		value := BlockDirtyBitmapMergeWrapper{}
  3141  		if err := json.Unmarshal(data, &value); err != nil {
  3142  			return err
  3143  		}
  3144  		s.Value = value
  3145  	case TransactionActionKindBlockDirtyBitmapRemove:
  3146  		value := BlockDirtyBitmapWrapper{}
  3147  		if err := json.Unmarshal(data, &value); err != nil {
  3148  			return err
  3149  		}
  3150  		s.Value = value
  3151  	case TransactionActionKindBlockdevBackup:
  3152  		value := BlockdevBackupWrapper{}
  3153  		if err := json.Unmarshal(data, &value); err != nil {
  3154  			return err
  3155  		}
  3156  		s.Value = value
  3157  	case TransactionActionKindBlockdevSnapshot:
  3158  		value := BlockdevSnapshotWrapper{}
  3159  		if err := json.Unmarshal(data, &value); err != nil {
  3160  			return err
  3161  		}
  3162  		s.Value = value
  3163  	case TransactionActionKindBlockdevSnapshotInternalSync:
  3164  		value := BlockdevSnapshotInternalWrapper{}
  3165  		if err := json.Unmarshal(data, &value); err != nil {
  3166  			return err
  3167  		}
  3168  		s.Value = value
  3169  	case TransactionActionKindBlockdevSnapshotSync:
  3170  		value := BlockdevSnapshotSyncWrapper{}
  3171  		if err := json.Unmarshal(data, &value); err != nil {
  3172  			return err
  3173  		}
  3174  		s.Value = value
  3175  	case TransactionActionKindDriveBackup:
  3176  		value := DriveBackupWrapper{}
  3177  		if err := json.Unmarshal(data, &value); err != nil {
  3178  			return err
  3179  		}
  3180  		s.Value = value
  3181  
  3182  	default:
  3183  		fmt.Println("Failed to decode TransactionAction", base.Type)
  3184  	}
  3185  
  3186  	return nil
  3187  }
  3188  
  3189  // None: Additional members depend on the value of @meta-type.
  3190  //
  3191  // Since: 2.5
  3192  type SchemaInfoBase struct {
  3193  	Name     string         `json:"name"`               // the entity's name, inherited from @base. The SchemaInfo is always referenced by this name. Commands and events have the name defined in the QAPI schema. Unlike command and event names, type names are not part of the wire ABI. Consequently, type names are meaningless strings here, although they are still guaranteed unique regardless of @meta-type.
  3194  	MetaType SchemaMetaType `json:"meta-type"`          // the entity's meta type, inherited from @base.
  3195  	Features []string       `json:"features,omitempty"` // names of features associated with the entity, in no particular order. (since 4.1 for object types, 4.2 for commands, 5.0 for the rest)
  3196  }
  3197  
  3198  // None: Additional members depend on the value of @meta-type.
  3199  //
  3200  // Since: 2.5
  3201  type SchemaInfo struct {
  3202  	// Base type for this struct
  3203  	SchemaInfoBase
  3204  	// Value based on @meta-type, possible types:
  3205  	// * SchemaInfoBuiltin
  3206  	// * SchemaInfoEnum
  3207  	// * SchemaInfoArray
  3208  	// * SchemaInfoObject
  3209  	// * SchemaInfoAlternate
  3210  	// * SchemaInfoCommand
  3211  	// * SchemaInfoEvent
  3212  	Value Any
  3213  }
  3214  
  3215  func (s SchemaInfo) MarshalJSON() ([]byte, error) {
  3216  	base, err := json.Marshal(s.SchemaInfoBase)
  3217  	if err != nil {
  3218  		return nil, err
  3219  	}
  3220  
  3221  	typestr := fmt.Sprintf("%T", s.Value)
  3222  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  3223  
  3224  	// "The branches need not cover all possible enum values"
  3225  	// This means that on Marshal, we can safely ignore empty values
  3226  	if typestr == "<nil>" {
  3227  		return []byte(base), nil
  3228  	}
  3229  
  3230  	// Runtime check for supported value types
  3231  	if typestr != "SchemaInfoAlternate" &&
  3232  		typestr != "SchemaInfoArray" &&
  3233  		typestr != "SchemaInfoBuiltin" &&
  3234  		typestr != "SchemaInfoCommand" &&
  3235  		typestr != "SchemaInfoEnum" &&
  3236  		typestr != "SchemaInfoEvent" &&
  3237  		typestr != "SchemaInfoObject" {
  3238  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  3239  	}
  3240  	value, err := json.Marshal(s.Value)
  3241  	if err != nil {
  3242  		return nil, err
  3243  	}
  3244  
  3245  	// Workaround to avoid checking s.Value being empty
  3246  	if string(value) == "{}" {
  3247  		return []byte(base), nil
  3248  	}
  3249  
  3250  	// Removes the last '}' from base and the first '{' from value, in order to
  3251  	// return a single JSON object.
  3252  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  3253  	return []byte(result), nil
  3254  }
  3255  
  3256  func (s *SchemaInfo) UnmarshalJSON(data []byte) error {
  3257  
  3258  	var base SchemaInfoBase
  3259  	if err := json.Unmarshal(data, &base); err != nil {
  3260  		return err
  3261  	}
  3262  	s.SchemaInfoBase = base
  3263  
  3264  	switch base.MetaType {
  3265  	case SchemaMetaTypeAlternate:
  3266  		value := SchemaInfoAlternate{}
  3267  		if err := json.Unmarshal(data, &value); err != nil {
  3268  			return err
  3269  		}
  3270  		s.Value = value
  3271  	case SchemaMetaTypeArray:
  3272  		value := SchemaInfoArray{}
  3273  		if err := json.Unmarshal(data, &value); err != nil {
  3274  			return err
  3275  		}
  3276  		s.Value = value
  3277  	case SchemaMetaTypeBuiltin:
  3278  		value := SchemaInfoBuiltin{}
  3279  		if err := json.Unmarshal(data, &value); err != nil {
  3280  			return err
  3281  		}
  3282  		s.Value = value
  3283  	case SchemaMetaTypeCommand:
  3284  		value := SchemaInfoCommand{}
  3285  		if err := json.Unmarshal(data, &value); err != nil {
  3286  			return err
  3287  		}
  3288  		s.Value = value
  3289  	case SchemaMetaTypeEnum:
  3290  		value := SchemaInfoEnum{}
  3291  		if err := json.Unmarshal(data, &value); err != nil {
  3292  			return err
  3293  		}
  3294  		s.Value = value
  3295  	case SchemaMetaTypeEvent:
  3296  		value := SchemaInfoEvent{}
  3297  		if err := json.Unmarshal(data, &value); err != nil {
  3298  			return err
  3299  		}
  3300  		s.Value = value
  3301  	case SchemaMetaTypeObject:
  3302  		value := SchemaInfoObject{}
  3303  		if err := json.Unmarshal(data, &value); err != nil {
  3304  			return err
  3305  		}
  3306  		s.Value = value
  3307  
  3308  	default:
  3309  		fmt.Println("Failed to decode SchemaInfo", base.MetaType)
  3310  	}
  3311  
  3312  	return nil
  3313  }
  3314  
  3315  // Describes the options of a user creatable QOM object.
  3316  //
  3317  // Since: 6.0
  3318  type ObjectOptionsBase struct {
  3319  	QomType ObjectType `json:"qom-type"` // the class name for the object to be created
  3320  	Id      string     `json:"id"`       // the name of the new object
  3321  }
  3322  
  3323  // Describes the options of a user creatable QOM object.
  3324  //
  3325  // Since: 6.0
  3326  type ObjectOptions struct {
  3327  	// Base type for this struct
  3328  	ObjectOptionsBase
  3329  	// Value based on @qom-type, possible types:
  3330  	// * AuthZListProperties
  3331  	// * AuthZListFileProperties
  3332  	// * AuthZPAMProperties
  3333  	// * AuthZSimpleProperties
  3334  	// * CanHostSocketcanProperties
  3335  	// * ColoCompareProperties
  3336  	// * CryptodevBackendProperties
  3337  	// * CryptodevBackendProperties
  3338  	// * CryptodevVhostUserProperties
  3339  	// * DBusVMStateProperties
  3340  	// * FilterBufferProperties
  3341  	// * FilterDumpProperties
  3342  	// * FilterMirrorProperties
  3343  	// * FilterRedirectorProperties
  3344  	// * NetfilterProperties
  3345  	// * FilterRewriterProperties
  3346  	// * InputBarrierProperties
  3347  	// * InputLinuxProperties
  3348  	// * IothreadProperties
  3349  	// * MemoryBackendEpcProperties
  3350  	// * MemoryBackendFileProperties
  3351  	// * MemoryBackendMemfdProperties
  3352  	// * MemoryBackendProperties
  3353  	// * PrManagerHelperProperties
  3354  	// * QtestProperties
  3355  	// * RngProperties
  3356  	// * RngEgdProperties
  3357  	// * RngRandomProperties
  3358  	// * SecretProperties
  3359  	// * SecretKeyringProperties
  3360  	// * SevGuestProperties
  3361  	// * ThrottleGroupProperties
  3362  	// * TlsCredsAnonProperties
  3363  	// * TlsCredsPskProperties
  3364  	// * TlsCredsX509Properties
  3365  	// * TlsCredsProperties
  3366  	// * RemoteObjectProperties
  3367  	Value Any
  3368  }
  3369  
  3370  func (s ObjectOptions) MarshalJSON() ([]byte, error) {
  3371  	base, err := json.Marshal(s.ObjectOptionsBase)
  3372  	if err != nil {
  3373  		return nil, err
  3374  	}
  3375  
  3376  	typestr := fmt.Sprintf("%T", s.Value)
  3377  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  3378  
  3379  	// "The branches need not cover all possible enum values"
  3380  	// This means that on Marshal, we can safely ignore empty values
  3381  	if typestr == "<nil>" {
  3382  		return []byte(base), nil
  3383  	}
  3384  
  3385  	// Runtime check for supported value types
  3386  	if typestr != "AuthZListProperties" &&
  3387  		typestr != "AuthZListFileProperties" &&
  3388  		typestr != "AuthZPAMProperties" &&
  3389  		typestr != "AuthZSimpleProperties" &&
  3390  		typestr != "CanHostSocketcanProperties" &&
  3391  		typestr != "ColoCompareProperties" &&
  3392  		typestr != "CryptodevBackendProperties" &&
  3393  		typestr != "CryptodevVhostUserProperties" &&
  3394  		typestr != "DBusVMStateProperties" &&
  3395  		typestr != "FilterBufferProperties" &&
  3396  		typestr != "FilterDumpProperties" &&
  3397  		typestr != "FilterMirrorProperties" &&
  3398  		typestr != "FilterRedirectorProperties" &&
  3399  		typestr != "NetfilterProperties" &&
  3400  		typestr != "FilterRewriterProperties" &&
  3401  		typestr != "InputBarrierProperties" &&
  3402  		typestr != "InputLinuxProperties" &&
  3403  		typestr != "IothreadProperties" &&
  3404  		typestr != "MemoryBackendEpcProperties" &&
  3405  		typestr != "MemoryBackendFileProperties" &&
  3406  		typestr != "MemoryBackendMemfdProperties" &&
  3407  		typestr != "MemoryBackendProperties" &&
  3408  		typestr != "PrManagerHelperProperties" &&
  3409  		typestr != "QtestProperties" &&
  3410  		typestr != "RngProperties" &&
  3411  		typestr != "RngEgdProperties" &&
  3412  		typestr != "RngRandomProperties" &&
  3413  		typestr != "SecretProperties" &&
  3414  		typestr != "SecretKeyringProperties" &&
  3415  		typestr != "SevGuestProperties" &&
  3416  		typestr != "ThrottleGroupProperties" &&
  3417  		typestr != "TlsCredsProperties" &&
  3418  		typestr != "TlsCredsAnonProperties" &&
  3419  		typestr != "TlsCredsPskProperties" &&
  3420  		typestr != "TlsCredsX509Properties" &&
  3421  		typestr != "RemoteObjectProperties" {
  3422  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  3423  	}
  3424  	value, err := json.Marshal(s.Value)
  3425  	if err != nil {
  3426  		return nil, err
  3427  	}
  3428  
  3429  	// Workaround to avoid checking s.Value being empty
  3430  	if string(value) == "{}" {
  3431  		return []byte(base), nil
  3432  	}
  3433  
  3434  	// Removes the last '}' from base and the first '{' from value, in order to
  3435  	// return a single JSON object.
  3436  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  3437  	return []byte(result), nil
  3438  }
  3439  
  3440  func (s *ObjectOptions) UnmarshalJSON(data []byte) error {
  3441  
  3442  	var base ObjectOptionsBase
  3443  	if err := json.Unmarshal(data, &base); err != nil {
  3444  		return err
  3445  	}
  3446  	s.ObjectOptionsBase = base
  3447  
  3448  	switch base.QomType {
  3449  	case ObjectTypeAuthzList:
  3450  		value := AuthZListProperties{}
  3451  		if err := json.Unmarshal(data, &value); err != nil {
  3452  			return err
  3453  		}
  3454  		s.Value = value
  3455  	case ObjectTypeAuthzListfile:
  3456  		value := AuthZListFileProperties{}
  3457  		if err := json.Unmarshal(data, &value); err != nil {
  3458  			return err
  3459  		}
  3460  		s.Value = value
  3461  	case ObjectTypeAuthzPam:
  3462  		value := AuthZPAMProperties{}
  3463  		if err := json.Unmarshal(data, &value); err != nil {
  3464  			return err
  3465  		}
  3466  		s.Value = value
  3467  	case ObjectTypeAuthzSimple:
  3468  		value := AuthZSimpleProperties{}
  3469  		if err := json.Unmarshal(data, &value); err != nil {
  3470  			return err
  3471  		}
  3472  		s.Value = value
  3473  	case ObjectTypeCanHostSocketcan:
  3474  		value := CanHostSocketcanProperties{}
  3475  		if err := json.Unmarshal(data, &value); err != nil {
  3476  			return err
  3477  		}
  3478  		s.Value = value
  3479  	case ObjectTypeColoCompare:
  3480  		value := ColoCompareProperties{}
  3481  		if err := json.Unmarshal(data, &value); err != nil {
  3482  			return err
  3483  		}
  3484  		s.Value = value
  3485  	case ObjectTypeCryptodevBackend:
  3486  		value := CryptodevBackendProperties{}
  3487  		if err := json.Unmarshal(data, &value); err != nil {
  3488  			return err
  3489  		}
  3490  		s.Value = value
  3491  	case ObjectTypeCryptodevBackendBuiltin:
  3492  		value := CryptodevBackendProperties{}
  3493  		if err := json.Unmarshal(data, &value); err != nil {
  3494  			return err
  3495  		}
  3496  		s.Value = value
  3497  	case ObjectTypeCryptodevVhostUser:
  3498  		value := CryptodevVhostUserProperties{}
  3499  		if err := json.Unmarshal(data, &value); err != nil {
  3500  			return err
  3501  		}
  3502  		s.Value = value
  3503  	case ObjectTypeDbusVmstate:
  3504  		value := DBusVMStateProperties{}
  3505  		if err := json.Unmarshal(data, &value); err != nil {
  3506  			return err
  3507  		}
  3508  		s.Value = value
  3509  	case ObjectTypeFilterBuffer:
  3510  		value := FilterBufferProperties{}
  3511  		if err := json.Unmarshal(data, &value); err != nil {
  3512  			return err
  3513  		}
  3514  		s.Value = value
  3515  	case ObjectTypeFilterDump:
  3516  		value := FilterDumpProperties{}
  3517  		if err := json.Unmarshal(data, &value); err != nil {
  3518  			return err
  3519  		}
  3520  		s.Value = value
  3521  	case ObjectTypeFilterMirror:
  3522  		value := FilterMirrorProperties{}
  3523  		if err := json.Unmarshal(data, &value); err != nil {
  3524  			return err
  3525  		}
  3526  		s.Value = value
  3527  	case ObjectTypeFilterRedirector:
  3528  		value := FilterRedirectorProperties{}
  3529  		if err := json.Unmarshal(data, &value); err != nil {
  3530  			return err
  3531  		}
  3532  		s.Value = value
  3533  	case ObjectTypeFilterReplay:
  3534  		value := NetfilterProperties{}
  3535  		if err := json.Unmarshal(data, &value); err != nil {
  3536  			return err
  3537  		}
  3538  		s.Value = value
  3539  	case ObjectTypeFilterRewriter:
  3540  		value := FilterRewriterProperties{}
  3541  		if err := json.Unmarshal(data, &value); err != nil {
  3542  			return err
  3543  		}
  3544  		s.Value = value
  3545  	case ObjectTypeInputBarrier:
  3546  		value := InputBarrierProperties{}
  3547  		if err := json.Unmarshal(data, &value); err != nil {
  3548  			return err
  3549  		}
  3550  		s.Value = value
  3551  	case ObjectTypeInputLinux:
  3552  		value := InputLinuxProperties{}
  3553  		if err := json.Unmarshal(data, &value); err != nil {
  3554  			return err
  3555  		}
  3556  		s.Value = value
  3557  	case ObjectTypeIothread:
  3558  		value := IothreadProperties{}
  3559  		if err := json.Unmarshal(data, &value); err != nil {
  3560  			return err
  3561  		}
  3562  		s.Value = value
  3563  	case ObjectTypeMemoryBackendEpc:
  3564  		value := MemoryBackendEpcProperties{}
  3565  		if err := json.Unmarshal(data, &value); err != nil {
  3566  			return err
  3567  		}
  3568  		s.Value = value
  3569  	case ObjectTypeMemoryBackendFile:
  3570  		value := MemoryBackendFileProperties{}
  3571  		if err := json.Unmarshal(data, &value); err != nil {
  3572  			return err
  3573  		}
  3574  		s.Value = value
  3575  	case ObjectTypeMemoryBackendMemfd:
  3576  		value := MemoryBackendMemfdProperties{}
  3577  		if err := json.Unmarshal(data, &value); err != nil {
  3578  			return err
  3579  		}
  3580  		s.Value = value
  3581  	case ObjectTypeMemoryBackendRam:
  3582  		value := MemoryBackendProperties{}
  3583  		if err := json.Unmarshal(data, &value); err != nil {
  3584  			return err
  3585  		}
  3586  		s.Value = value
  3587  	case ObjectTypePrManagerHelper:
  3588  		value := PrManagerHelperProperties{}
  3589  		if err := json.Unmarshal(data, &value); err != nil {
  3590  			return err
  3591  		}
  3592  		s.Value = value
  3593  	case ObjectTypeQtest:
  3594  		value := QtestProperties{}
  3595  		if err := json.Unmarshal(data, &value); err != nil {
  3596  			return err
  3597  		}
  3598  		s.Value = value
  3599  	case ObjectTypeRngBuiltin:
  3600  		value := RngProperties{}
  3601  		if err := json.Unmarshal(data, &value); err != nil {
  3602  			return err
  3603  		}
  3604  		s.Value = value
  3605  	case ObjectTypeRngEgd:
  3606  		value := RngEgdProperties{}
  3607  		if err := json.Unmarshal(data, &value); err != nil {
  3608  			return err
  3609  		}
  3610  		s.Value = value
  3611  	case ObjectTypeRngRandom:
  3612  		value := RngRandomProperties{}
  3613  		if err := json.Unmarshal(data, &value); err != nil {
  3614  			return err
  3615  		}
  3616  		s.Value = value
  3617  	case ObjectTypeSecret:
  3618  		value := SecretProperties{}
  3619  		if err := json.Unmarshal(data, &value); err != nil {
  3620  			return err
  3621  		}
  3622  		s.Value = value
  3623  	case ObjectTypeSecret_Keyring:
  3624  		value := SecretKeyringProperties{}
  3625  		if err := json.Unmarshal(data, &value); err != nil {
  3626  			return err
  3627  		}
  3628  		s.Value = value
  3629  	case ObjectTypeSevGuest:
  3630  		value := SevGuestProperties{}
  3631  		if err := json.Unmarshal(data, &value); err != nil {
  3632  			return err
  3633  		}
  3634  		s.Value = value
  3635  	case ObjectTypeThrottleGroup:
  3636  		value := ThrottleGroupProperties{}
  3637  		if err := json.Unmarshal(data, &value); err != nil {
  3638  			return err
  3639  		}
  3640  		s.Value = value
  3641  	case ObjectTypeTlsCipherSuites:
  3642  		value := TlsCredsProperties{}
  3643  		if err := json.Unmarshal(data, &value); err != nil {
  3644  			return err
  3645  		}
  3646  		s.Value = value
  3647  	case ObjectTypeTlsCredsAnon:
  3648  		value := TlsCredsAnonProperties{}
  3649  		if err := json.Unmarshal(data, &value); err != nil {
  3650  			return err
  3651  		}
  3652  		s.Value = value
  3653  	case ObjectTypeTlsCredsPsk:
  3654  		value := TlsCredsPskProperties{}
  3655  		if err := json.Unmarshal(data, &value); err != nil {
  3656  			return err
  3657  		}
  3658  		s.Value = value
  3659  	case ObjectTypeTlsCredsX509:
  3660  		value := TlsCredsX509Properties{}
  3661  		if err := json.Unmarshal(data, &value); err != nil {
  3662  			return err
  3663  		}
  3664  		s.Value = value
  3665  	case ObjectTypeXRemoteObject:
  3666  		value := RemoteObjectProperties{}
  3667  		if err := json.Unmarshal(data, &value); err != nil {
  3668  			return err
  3669  		}
  3670  		s.Value = value
  3671  
  3672  	default:
  3673  		fmt.Println("Failed to decode ObjectOptions", base.QomType)
  3674  	}
  3675  
  3676  	return nil
  3677  }
  3678  
  3679  // Information about a virtual CPU
  3680  //
  3681  // Since: 2.12
  3682  type CpuInfoFastBase struct {
  3683  	CpuIndex int64                  `json:"cpu-index"`       // index of the virtual CPU
  3684  	QomPath  string                 `json:"qom-path"`        // path to the CPU object in the QOM tree
  3685  	ThreadId int64                  `json:"thread-id"`       // ID of the underlying host thread
  3686  	Props    *CpuInstanceProperties `json:"props,omitempty"` // properties describing to which node/socket/core/thread virtual CPU belongs to, provided if supported by board
  3687  	Target   SysEmuTarget           `json:"target"`          // the QEMU system emulation target, which determines which additional fields will be listed (since 3.0)
  3688  }
  3689  
  3690  // Information about a virtual CPU
  3691  //
  3692  // Since: 2.12
  3693  type CpuInfoFast struct {
  3694  	// Base type for this struct
  3695  	CpuInfoFastBase
  3696  	// Value based on @target, possible types:
  3697  	// * CpuInfoS390
  3698  	Value Any
  3699  }
  3700  
  3701  func (s CpuInfoFast) MarshalJSON() ([]byte, error) {
  3702  	base, err := json.Marshal(s.CpuInfoFastBase)
  3703  	if err != nil {
  3704  		return nil, err
  3705  	}
  3706  
  3707  	typestr := fmt.Sprintf("%T", s.Value)
  3708  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  3709  
  3710  	// "The branches need not cover all possible enum values"
  3711  	// This means that on Marshal, we can safely ignore empty values
  3712  	if typestr == "<nil>" {
  3713  		return []byte(base), nil
  3714  	}
  3715  
  3716  	// Runtime check for supported value types
  3717  	if typestr != "CpuInfoS390" {
  3718  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  3719  	}
  3720  	value, err := json.Marshal(s.Value)
  3721  	if err != nil {
  3722  		return nil, err
  3723  	}
  3724  
  3725  	// Workaround to avoid checking s.Value being empty
  3726  	if string(value) == "{}" {
  3727  		return []byte(base), nil
  3728  	}
  3729  
  3730  	// Removes the last '}' from base and the first '{' from value, in order to
  3731  	// return a single JSON object.
  3732  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  3733  	return []byte(result), nil
  3734  }
  3735  
  3736  func (s *CpuInfoFast) UnmarshalJSON(data []byte) error {
  3737  
  3738  	var base CpuInfoFastBase
  3739  	if err := json.Unmarshal(data, &base); err != nil {
  3740  		return err
  3741  	}
  3742  	s.CpuInfoFastBase = base
  3743  
  3744  	switch base.Target {
  3745  	case SysEmuTargetS390X:
  3746  		value := CpuInfoS390{}
  3747  		if err := json.Unmarshal(data, &value); err != nil {
  3748  			return err
  3749  		}
  3750  		s.Value = value
  3751  
  3752  	default:
  3753  		fmt.Println("Failed to decode CpuInfoFast", base.Target)
  3754  	}
  3755  
  3756  	return nil
  3757  }
  3758  
  3759  // A discriminated record of NUMA options. (for OptsVisitor)
  3760  //
  3761  // Since: 2.1
  3762  type NumaOptionsBase struct {
  3763  	Type NumaOptionsType `json:"type"`
  3764  }
  3765  
  3766  // A discriminated record of NUMA options. (for OptsVisitor)
  3767  //
  3768  // Since: 2.1
  3769  type NumaOptions struct {
  3770  	// Base type for this struct
  3771  	NumaOptionsBase
  3772  	// Value based on @type, possible types:
  3773  	// * NumaNodeOptions
  3774  	// * NumaDistOptions
  3775  	// * NumaCpuOptions
  3776  	// * NumaHmatLBOptions
  3777  	// * NumaHmatCacheOptions
  3778  	Value Any
  3779  }
  3780  
  3781  func (s NumaOptions) MarshalJSON() ([]byte, error) {
  3782  	base, err := json.Marshal(s.NumaOptionsBase)
  3783  	if err != nil {
  3784  		return nil, err
  3785  	}
  3786  
  3787  	typestr := fmt.Sprintf("%T", s.Value)
  3788  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  3789  
  3790  	// "The branches need not cover all possible enum values"
  3791  	// This means that on Marshal, we can safely ignore empty values
  3792  	if typestr == "<nil>" {
  3793  		return []byte(base), nil
  3794  	}
  3795  
  3796  	// Runtime check for supported value types
  3797  	if typestr != "NumaCpuOptions" &&
  3798  		typestr != "NumaDistOptions" &&
  3799  		typestr != "NumaHmatCacheOptions" &&
  3800  		typestr != "NumaHmatLBOptions" &&
  3801  		typestr != "NumaNodeOptions" {
  3802  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  3803  	}
  3804  	value, err := json.Marshal(s.Value)
  3805  	if err != nil {
  3806  		return nil, err
  3807  	}
  3808  
  3809  	// Workaround to avoid checking s.Value being empty
  3810  	if string(value) == "{}" {
  3811  		return []byte(base), nil
  3812  	}
  3813  
  3814  	// Removes the last '}' from base and the first '{' from value, in order to
  3815  	// return a single JSON object.
  3816  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  3817  	return []byte(result), nil
  3818  }
  3819  
  3820  func (s *NumaOptions) UnmarshalJSON(data []byte) error {
  3821  
  3822  	var base NumaOptionsBase
  3823  	if err := json.Unmarshal(data, &base); err != nil {
  3824  		return err
  3825  	}
  3826  	s.NumaOptionsBase = base
  3827  
  3828  	switch base.Type {
  3829  	case NumaOptionsTypeCpu:
  3830  		value := NumaCpuOptions{}
  3831  		if err := json.Unmarshal(data, &value); err != nil {
  3832  			return err
  3833  		}
  3834  		s.Value = value
  3835  	case NumaOptionsTypeDist:
  3836  		value := NumaDistOptions{}
  3837  		if err := json.Unmarshal(data, &value); err != nil {
  3838  			return err
  3839  		}
  3840  		s.Value = value
  3841  	case NumaOptionsTypeHmatCache:
  3842  		value := NumaHmatCacheOptions{}
  3843  		if err := json.Unmarshal(data, &value); err != nil {
  3844  			return err
  3845  		}
  3846  		s.Value = value
  3847  	case NumaOptionsTypeHmatLb:
  3848  		value := NumaHmatLBOptions{}
  3849  		if err := json.Unmarshal(data, &value); err != nil {
  3850  			return err
  3851  		}
  3852  		s.Value = value
  3853  	case NumaOptionsTypeNode:
  3854  		value := NumaNodeOptions{}
  3855  		if err := json.Unmarshal(data, &value); err != nil {
  3856  			return err
  3857  		}
  3858  		s.Value = value
  3859  
  3860  	default:
  3861  		fmt.Println("Failed to decode NumaOptions", base.Type)
  3862  	}
  3863  
  3864  	return nil
  3865  }
  3866  
  3867  // Union containing information about a memory device
  3868  //
  3869  // nvdimm is included since 2.12. virtio-pmem is included since 4.1.
  3870  // virtio-mem is included since 5.1. sgx-epc is included since 6.2.
  3871  //
  3872  // Since: 2.1
  3873  type MemoryDeviceInfoBase struct {
  3874  	Type MemoryDeviceInfoKind `json:"type"`
  3875  }
  3876  
  3877  // Union containing information about a memory device
  3878  //
  3879  // nvdimm is included since 2.12. virtio-pmem is included since 4.1.
  3880  // virtio-mem is included since 5.1. sgx-epc is included since 6.2.
  3881  //
  3882  // Since: 2.1
  3883  type MemoryDeviceInfo struct {
  3884  	// Base type for this struct
  3885  	MemoryDeviceInfoBase
  3886  	// Value based on @type, possible types:
  3887  	// * PCDIMMDeviceInfoWrapper
  3888  	// * PCDIMMDeviceInfoWrapper
  3889  	// * VirtioPMEMDeviceInfoWrapper
  3890  	// * VirtioMEMDeviceInfoWrapper
  3891  	// * SgxEPCDeviceInfoWrapper
  3892  	Value Any
  3893  }
  3894  
  3895  func (s MemoryDeviceInfo) MarshalJSON() ([]byte, error) {
  3896  	base, err := json.Marshal(s.MemoryDeviceInfoBase)
  3897  	if err != nil {
  3898  		return nil, err
  3899  	}
  3900  
  3901  	typestr := fmt.Sprintf("%T", s.Value)
  3902  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  3903  
  3904  	// "The branches need not cover all possible enum values"
  3905  	// This means that on Marshal, we can safely ignore empty values
  3906  	if typestr == "<nil>" {
  3907  		return []byte(base), nil
  3908  	}
  3909  
  3910  	// Runtime check for supported value types
  3911  	if typestr != "PCDIMMDeviceInfoWrapper" &&
  3912  		typestr != "SgxEPCDeviceInfoWrapper" &&
  3913  		typestr != "VirtioMEMDeviceInfoWrapper" &&
  3914  		typestr != "VirtioPMEMDeviceInfoWrapper" {
  3915  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  3916  	}
  3917  	value, err := json.Marshal(s.Value)
  3918  	if err != nil {
  3919  		return nil, err
  3920  	}
  3921  
  3922  	// Workaround to avoid checking s.Value being empty
  3923  	if string(value) == "{}" {
  3924  		return []byte(base), nil
  3925  	}
  3926  
  3927  	// Removes the last '}' from base and the first '{' from value, in order to
  3928  	// return a single JSON object.
  3929  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  3930  	return []byte(result), nil
  3931  }
  3932  
  3933  func (s *MemoryDeviceInfo) UnmarshalJSON(data []byte) error {
  3934  
  3935  	var base MemoryDeviceInfoBase
  3936  	if err := json.Unmarshal(data, &base); err != nil {
  3937  		return err
  3938  	}
  3939  	s.MemoryDeviceInfoBase = base
  3940  
  3941  	switch base.Type {
  3942  	case MemoryDeviceInfoKindDimm:
  3943  		value := PCDIMMDeviceInfoWrapper{}
  3944  		if err := json.Unmarshal(data, &value); err != nil {
  3945  			return err
  3946  		}
  3947  		s.Value = value
  3948  	case MemoryDeviceInfoKindNvdimm:
  3949  		value := PCDIMMDeviceInfoWrapper{}
  3950  		if err := json.Unmarshal(data, &value); err != nil {
  3951  			return err
  3952  		}
  3953  		s.Value = value
  3954  	case MemoryDeviceInfoKindSgxEpc:
  3955  		value := SgxEPCDeviceInfoWrapper{}
  3956  		if err := json.Unmarshal(data, &value); err != nil {
  3957  			return err
  3958  		}
  3959  		s.Value = value
  3960  	case MemoryDeviceInfoKindVirtioMem:
  3961  		value := VirtioMEMDeviceInfoWrapper{}
  3962  		if err := json.Unmarshal(data, &value); err != nil {
  3963  			return err
  3964  		}
  3965  		s.Value = value
  3966  	case MemoryDeviceInfoKindVirtioPmem:
  3967  		value := VirtioPMEMDeviceInfoWrapper{}
  3968  		if err := json.Unmarshal(data, &value); err != nil {
  3969  			return err
  3970  		}
  3971  		s.Value = value
  3972  
  3973  	default:
  3974  		fmt.Println("Failed to decode MemoryDeviceInfo", base.Type)
  3975  	}
  3976  
  3977  	return nil
  3978  }
  3979  
  3980  // A yank instance can be yanked with the @yank qmp command to recover from a
  3981  // hanging QEMU.
  3982  //
  3983  // Currently implemented yank instances:
  3984  //  - nbd block device:
  3985  //    Yanking it will shut down the connection to the nbd server without
  3986  //    attempting to reconnect.
  3987  //  - socket chardev:
  3988  //    Yanking it will shut down the connected socket.
  3989  //  - migration:
  3990  //    Yanking it will shut down all migration connections. Unlike
  3991  //    @migrate_cancel, it will not notify the migration process, so migration
  3992  //    will go into @failed state, instead of @cancelled state. @yank should be
  3993  //    used to recover from hangs.
  3994  //
  3995  // Since: 6.0
  3996  type YankInstanceBase struct {
  3997  	Type YankInstanceType `json:"type"`
  3998  }
  3999  
  4000  // A yank instance can be yanked with the @yank qmp command to recover from a
  4001  // hanging QEMU.
  4002  //
  4003  // Currently implemented yank instances:
  4004  //  - nbd block device:
  4005  //    Yanking it will shut down the connection to the nbd server without
  4006  //    attempting to reconnect.
  4007  //  - socket chardev:
  4008  //    Yanking it will shut down the connected socket.
  4009  //  - migration:
  4010  //    Yanking it will shut down all migration connections. Unlike
  4011  //    @migrate_cancel, it will not notify the migration process, so migration
  4012  //    will go into @failed state, instead of @cancelled state. @yank should be
  4013  //    used to recover from hangs.
  4014  //
  4015  // Since: 6.0
  4016  type YankInstance struct {
  4017  	// Base type for this struct
  4018  	YankInstanceBase
  4019  	// Value based on @type, possible types:
  4020  	// * YankInstanceBlockNode
  4021  	// * YankInstanceChardev
  4022  	Value Any
  4023  }
  4024  
  4025  func (s YankInstance) MarshalJSON() ([]byte, error) {
  4026  	base, err := json.Marshal(s.YankInstanceBase)
  4027  	if err != nil {
  4028  		return nil, err
  4029  	}
  4030  
  4031  	typestr := fmt.Sprintf("%T", s.Value)
  4032  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  4033  
  4034  	// "The branches need not cover all possible enum values"
  4035  	// This means that on Marshal, we can safely ignore empty values
  4036  	if typestr == "<nil>" {
  4037  		return []byte(base), nil
  4038  	}
  4039  
  4040  	// Runtime check for supported value types
  4041  	if typestr != "YankInstanceBlockNode" &&
  4042  		typestr != "YankInstanceChardev" {
  4043  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  4044  	}
  4045  	value, err := json.Marshal(s.Value)
  4046  	if err != nil {
  4047  		return nil, err
  4048  	}
  4049  
  4050  	// Workaround to avoid checking s.Value being empty
  4051  	if string(value) == "{}" {
  4052  		return []byte(base), nil
  4053  	}
  4054  
  4055  	// Removes the last '}' from base and the first '{' from value, in order to
  4056  	// return a single JSON object.
  4057  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  4058  	return []byte(result), nil
  4059  }
  4060  
  4061  func (s *YankInstance) UnmarshalJSON(data []byte) error {
  4062  
  4063  	var base YankInstanceBase
  4064  	if err := json.Unmarshal(data, &base); err != nil {
  4065  		return err
  4066  	}
  4067  	s.YankInstanceBase = base
  4068  
  4069  	switch base.Type {
  4070  	case YankInstanceTypeBlockNode:
  4071  		value := YankInstanceBlockNode{}
  4072  		if err := json.Unmarshal(data, &value); err != nil {
  4073  			return err
  4074  		}
  4075  		s.Value = value
  4076  	case YankInstanceTypeChardev:
  4077  		value := YankInstanceChardev{}
  4078  		if err := json.Unmarshal(data, &value); err != nil {
  4079  			return err
  4080  		}
  4081  		s.Value = value
  4082  
  4083  	default:
  4084  		fmt.Println("Failed to decode YankInstance", base.Type)
  4085  	}
  4086  
  4087  	return nil
  4088  }
  4089  
  4090  // Options of an audio backend.
  4091  //
  4092  // Since: 4.0
  4093  type AudiodevBase struct {
  4094  	Id          string         `json:"id"`                     // identifier of the backend
  4095  	Driver      AudiodevDriver `json:"driver"`                 // the backend driver to use
  4096  	TimerPeriod *uint32        `json:"timer-period,omitempty"` // timer period (in microseconds, 0: use lowest possible)
  4097  }
  4098  
  4099  // Options of an audio backend.
  4100  //
  4101  // Since: 4.0
  4102  type Audiodev struct {
  4103  	// Base type for this struct
  4104  	AudiodevBase
  4105  	// Value based on @driver, possible types:
  4106  	// * AudiodevGenericOptions
  4107  	// * AudiodevAlsaOptions
  4108  	// * AudiodevCoreaudioOptions
  4109  	// * AudiodevGenericOptions
  4110  	// * AudiodevDsoundOptions
  4111  	// * AudiodevJackOptions
  4112  	// * AudiodevOssOptions
  4113  	// * AudiodevPaOptions
  4114  	// * AudiodevSdlOptions
  4115  	// * AudiodevGenericOptions
  4116  	// * AudiodevWavOptions
  4117  	Value Any
  4118  }
  4119  
  4120  func (s Audiodev) MarshalJSON() ([]byte, error) {
  4121  	base, err := json.Marshal(s.AudiodevBase)
  4122  	if err != nil {
  4123  		return nil, err
  4124  	}
  4125  
  4126  	typestr := fmt.Sprintf("%T", s.Value)
  4127  	typestr = typestr[strings.LastIndex(typestr, ".")+1:]
  4128  
  4129  	// "The branches need not cover all possible enum values"
  4130  	// This means that on Marshal, we can safely ignore empty values
  4131  	if typestr == "<nil>" {
  4132  		return []byte(base), nil
  4133  	}
  4134  
  4135  	// Runtime check for supported value types
  4136  	if typestr != "AudiodevAlsaOptions" &&
  4137  		typestr != "AudiodevCoreaudioOptions" &&
  4138  		typestr != "AudiodevGenericOptions" &&
  4139  		typestr != "AudiodevDsoundOptions" &&
  4140  		typestr != "AudiodevJackOptions" &&
  4141  		typestr != "AudiodevOssOptions" &&
  4142  		typestr != "AudiodevPaOptions" &&
  4143  		typestr != "AudiodevSdlOptions" &&
  4144  		typestr != "AudiodevWavOptions" {
  4145  		return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
  4146  	}
  4147  	value, err := json.Marshal(s.Value)
  4148  	if err != nil {
  4149  		return nil, err
  4150  	}
  4151  
  4152  	// Workaround to avoid checking s.Value being empty
  4153  	if string(value) == "{}" {
  4154  		return []byte(base), nil
  4155  	}
  4156  
  4157  	// Removes the last '}' from base and the first '{' from value, in order to
  4158  	// return a single JSON object.
  4159  	result := fmt.Sprintf("%s,%s", base[:len(base)-1], value[1:])
  4160  	return []byte(result), nil
  4161  }
  4162  
  4163  func (s *Audiodev) UnmarshalJSON(data []byte) error {
  4164  
  4165  	var base AudiodevBase
  4166  	if err := json.Unmarshal(data, &base); err != nil {
  4167  		return err
  4168  	}
  4169  	s.AudiodevBase = base
  4170  
  4171  	switch base.Driver {
  4172  	case AudiodevDriverAlsa:
  4173  		value := AudiodevAlsaOptions{}
  4174  		if err := json.Unmarshal(data, &value); err != nil {
  4175  			return err
  4176  		}
  4177  		s.Value = value
  4178  	case AudiodevDriverCoreaudio:
  4179  		value := AudiodevCoreaudioOptions{}
  4180  		if err := json.Unmarshal(data, &value); err != nil {
  4181  			return err
  4182  		}
  4183  		s.Value = value
  4184  	case AudiodevDriverDbus:
  4185  		value := AudiodevGenericOptions{}
  4186  		if err := json.Unmarshal(data, &value); err != nil {
  4187  			return err
  4188  		}
  4189  		s.Value = value
  4190  	case AudiodevDriverDsound:
  4191  		value := AudiodevDsoundOptions{}
  4192  		if err := json.Unmarshal(data, &value); err != nil {
  4193  			return err
  4194  		}
  4195  		s.Value = value
  4196  	case AudiodevDriverJack:
  4197  		value := AudiodevJackOptions{}
  4198  		if err := json.Unmarshal(data, &value); err != nil {
  4199  			return err
  4200  		}
  4201  		s.Value = value
  4202  	case AudiodevDriverNone:
  4203  		value := AudiodevGenericOptions{}
  4204  		if err := json.Unmarshal(data, &value); err != nil {
  4205  			return err
  4206  		}
  4207  		s.Value = value
  4208  	case AudiodevDriverOss:
  4209  		value := AudiodevOssOptions{}
  4210  		if err := json.Unmarshal(data, &value); err != nil {
  4211  			return err
  4212  		}
  4213  		s.Value = value
  4214  	case AudiodevDriverPa:
  4215  		value := AudiodevPaOptions{}
  4216  		if err := json.Unmarshal(data, &value); err != nil {
  4217  			return err
  4218  		}
  4219  		s.Value = value
  4220  	case AudiodevDriverSdl:
  4221  		value := AudiodevSdlOptions{}
  4222  		if err := json.Unmarshal(data, &value); err != nil {
  4223  			return err
  4224  		}
  4225  		s.Value = value
  4226  	case AudiodevDriverSpice:
  4227  		value := AudiodevGenericOptions{}
  4228  		if err := json.Unmarshal(data, &value); err != nil {
  4229  			return err
  4230  		}
  4231  		s.Value = value
  4232  	case AudiodevDriverWav:
  4233  		value := AudiodevWavOptions{}
  4234  		if err := json.Unmarshal(data, &value); err != nil {
  4235  			return err
  4236  		}
  4237  		s.Value = value
  4238  
  4239  	default:
  4240  		fmt.Println("Failed to decode Audiodev", base.Driver)
  4241  	}
  4242  
  4243  	return nil
  4244  }
  4245  

View as plain text