encodeFixedArray writes the XDR encoded representation of each element in the passed array represented by the reflection value to the encapsulated writer and returns the number of bytes written. The ignoreOpaque flag controls whether or not uint8 (byte) elements should be encoded individually or as
(v reflect.Value, ignoreOpaque bool)
| 370 | // RFC Section 4.12 - Fixed-Length Array |
| 371 | // Individually XDR encoded array elements |
| 372 | func (enc *Encoder) encodeFixedArray(v reflect.Value, ignoreOpaque bool) (int, error) { |
| 373 | // Treat [#]byte (byte is alias for uint8) as opaque data unless ignored. |
| 374 | if !ignoreOpaque && v.Type().Elem().Kind() == reflect.Uint8 { |
| 375 | // Create a slice of the underlying array for better efficiency |
| 376 | // when possible. Can't create a slice of an unaddressable |
| 377 | // value. |
| 378 | if v.CanAddr() { |
| 379 | return enc.EncodeFixedOpaque(v.Slice(0, v.Len()).Bytes()) |
| 380 | } |
| 381 | |
| 382 | // When the underlying array isn't addressable fall back to |
| 383 | // copying the array into a new slice. This is rather ugly, but |
| 384 | // the inability to create a constant slice from an |
| 385 | // unaddressable array is a limitation of Go. |
| 386 | slice := make([]byte, v.Len(), v.Len()) |
| 387 | reflect.Copy(reflect.ValueOf(slice), v) |
| 388 | return enc.EncodeFixedOpaque(slice) |
| 389 | } |
| 390 | |
| 391 | // Encode each array element. |
| 392 | var n int |
| 393 | for i := 0; i < v.Len(); i++ { |
| 394 | n2, err := enc.encode(v.Index(i)) |
| 395 | n += n2 |
| 396 | if err != nil { |
| 397 | return n, err |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | return n, nil |
| 402 | } |
| 403 | |
| 404 | // encodeArray writes an XDR encoded integer representing the number of |
| 405 | // elements in the passed slice represented by the reflection value followed by |
no test coverage detected