vmware / govmomi

Go library for the VMware vSphere API
Apache License 2.0
2.26k stars 896 forks source link

fix: xml marshal byte array fields as vCenter does #3476

Closed dougm closed 1 week ago

dougm commented 1 week ago

Go's encoding/xml package and vCenter marshal '[]byte' differently: Go encodes the entire array in a single xml element, for example:

  <foo>
    <bar>hello</bar>
  </foo>

vCenter encodes each byte of the array in its own xml element, example with same data as above:

  <foo>
    <bar>104</bar>
    <bar>101</bar>
    <bar>108</bar>
    <bar>108</bar>
    <bar>111</bar>
  </foo>

This behavior is hardwired, see the xml/encoding source for the handful of []byte special cases along the lines of:

  if reflect.Slice && slice element type == reflect.Uint8

While govmomi maintains a fork of Go's xml/encoding package, we prefer to further diverge. Proposed solution is to use a 'ByteSlice' type that implements xml marshaling as vCenter does, but otherwise behaves just as []byte does.

Commits that follow enhance vcsim and govc support around various []byte fields.

Fixes #1977 Fixes #3469