func (d *Decoder) decodeFixedArray(v reflect.Value, ignoreOpaque bool) (int, error) {
	if !ignoreOpaque && v.Type().Elem().Kind() == reflect.Uint8 {
		data, n, err := d.DecodeFixedOpaque(int32(v.Len()))
		if err != nil {
			return n, err
		}
		reflect.Copy(v, reflect.ValueOf(data))
		return n, nil
	}
	var n int
	for i := 0; i < v.Len(); i++ {
		n2, err := d.decode(v.Index(i))
		n += n2
		if err != nil {
			return n, err
		}
	}
	return n, nil
}
decodeFixedArray treats the next bytes as a series of XDR encoded elements
of the same type as the array represented by the reflection value and decodes
each element into the passed array.  The ignoreOpaque flag controls whether
or not uint8 (byte) elements should be decoded individually or as a fixed
sequence of opaque data.  It returns the  the number of bytes actually read.

An UnmarshalError is returned if any issues are encountered while decoding
the array elements.

Reference:
RFC Section 4.12 - Fixed-Length Array
Individually XDR encoded array elements
package xdr
import (
	"fmt"
	"io"
	"math"
	"reflect"
	"time"
)
var (
	errMaxSlice = "data exceeds max slice limit"
	errIODecode = "%s while decoding %d bytes"
)
func Unmarshal(r io.Reader, v interface{}) (int, error) {
	d := Decoder{r: r}
	return d.Decode(v)
}
func UnmarshalLimited(r io.Reader, v interface{}, maxSize uint) (int, error) {
	d := Decoder{r: r, maxReadSize: maxSize}
	return d.Decode(v)
}
type Decoder struct {
	r io.Reader
	maxReadSize uint
}
func (d *Decoder) DecodeInt() (int32, int, error) {
	var buf [4]byte
	n, err := io.ReadFull(d.r, buf[:])
	if err != nil {
		msg := fmt.Sprintf(errIODecode, err.Error(), 4)
		err := unmarshalError("DecodeInt", ErrIO, msg, buf[:n], err)
		return 0, n, err
	}
	rv := int32(buf[3]) | int32(buf[2])<<8 |
		int32(buf[1])<<16 | int32(buf[0])<<24
	return rv, n, nil
}
func (d *Decoder) DecodeUint() (uint32, int, error) {
	var buf [4]byte
	n, err := io.ReadFull(d.r, buf[:])
	if err != nil {
		msg := fmt.Sprintf(errIODecode, err.Error(), 4)
		err := unmarshalError("DecodeUint", ErrIO, msg, buf[:n], err)
		return 0, n, err
	}
	rv := uint32(buf[3]) | uint32(buf[2])<<8 |
		uint32(buf[1])<<16 | uint32(buf[0])<<24
	return rv, n, nil
}
func (d *Decoder) DecodeEnum(validEnums map[int32]bool) (int32, int, error) {
	val, n, err := d.DecodeInt()
	if err != nil {
		return 0, n, err
	}
	if !validEnums[val] {
		err := unmarshalError("DecodeEnum", ErrBadEnumValue,
			"invalid enum", val, nil)
		return 0, n, err
	}
	return val, n, nil
}
func (d *Decoder) DecodeBool() (bool, int, error) {
	val, n, err := d.DecodeInt()
	if err != nil {
		return false, n, err
	}
	switch val {
	case 0:
		return false, n, nil
	case 1:
		return true, n, nil
	}
	err = unmarshalError("DecodeBool", ErrBadEnumValue, "bool not 0 or 1",
		val, nil)
	return false, n, err
}
func (d *Decoder) DecodeHyper() (int64, int, error) {
	var buf [8]byte
	n, err := io.ReadFull(d.r, buf[:])
	if err != nil {
		msg := fmt.Sprintf(errIODecode, err.Error(), 8)
		err := unmarshalError("DecodeHyper", ErrIO, msg, buf[:n], err)
		return 0, n, err
	}
	rv := int64(buf[7]) | int64(buf[6])<<8 |
		int64(buf[5])<<16 | int64(buf[4])<<24 |
		int64(buf[3])<<32 | int64(buf[2])<<40 |
		int64(buf[1])<<48 | int64(buf[0])<<56
	return rv, n, err
}
func (d *Decoder) DecodeUhyper() (uint64, int, error) {
	var buf [8]byte
	n, err := io.ReadFull(d.r, buf[:])
	if err != nil {
		msg := fmt.Sprintf(errIODecode, err.Error(), 8)
		err := unmarshalError("DecodeUhyper", ErrIO, msg, buf[:n], err)
		return 0, n, err
	}
	rv := uint64(buf[7]) | uint64(buf[6])<<8 |
		uint64(buf[5])<<16 | uint64(buf[4])<<24 |
		uint64(buf[3])<<32 | uint64(buf[2])<<40 |
		uint64(buf[1])<<48 | uint64(buf[0])<<56
	return rv, n, nil
}
func (d *Decoder) DecodeFloat() (float32, int, error) {
	var buf [4]byte
	n, err := io.ReadFull(d.r, buf[:])
	if err != nil {
		msg := fmt.Sprintf(errIODecode, err.Error(), 4)
		err := unmarshalError("DecodeFloat", ErrIO, msg, buf[:n], err)
		return 0, n, err
	}
	val := uint32(buf[3]) | uint32(buf[2])<<8 |
		uint32(buf[1])<<16 | uint32(buf[0])<<24
	return math.Float32frombits(val), n, nil
}
func (d *Decoder) DecodeDouble() (float64, int, error) {
	var buf [8]byte
	n, err := io.ReadFull(d.r, buf[:])
	if err != nil {
		msg := fmt.Sprintf(errIODecode, err.Error(), 8)
		err := unmarshalError("DecodeDouble", ErrIO, msg, buf[:n], err)
		return 0, n, err
	}
	val := uint64(buf[7]) | uint64(buf[6])<<8 |
		uint64(buf[5])<<16 | uint64(buf[4])<<24 |
		uint64(buf[3])<<32 | uint64(buf[2])<<40 |
		uint64(buf[1])<<48 | uint64(buf[0])<<56
	return math.Float64frombits(val), n, nil
}
func (d *Decoder) DecodeFixedOpaque(size int32) ([]byte, int, error) {
	if size == 0 {
		return nil, 0, nil
	}
	pad := (4 - (size % 4)) % 4
	paddedSize := size + pad
	if uint(paddedSize) > uint(math.MaxInt32) {
		err := unmarshalError("DecodeFixedOpaque", ErrOverflow,
			errMaxSlice, paddedSize, nil)
		return nil, 0, err
	}
	buf := make([]byte, paddedSize)
	n, err := io.ReadFull(d.r, buf)
	if err != nil {
		msg := fmt.Sprintf(errIODecode, err.Error(), paddedSize)
		err := unmarshalError("DecodeFixedOpaque", ErrIO, msg, buf[:n],
			err)
		return nil, n, err
	}
	return buf[0:size], n, nil
}
func (d *Decoder) DecodeOpaque() ([]byte, int, error) {
	dataLen, n, err := d.DecodeUint()
	if err != nil {
		return nil, n, err
	}
	if uint(dataLen) > uint(math.MaxInt32) ||
		(d.maxReadSize != 0 && uint(dataLen) > d.maxReadSize) {
		err := unmarshalError("DecodeOpaque", ErrOverflow, errMaxSlice,
			dataLen, nil)
		return nil, n, err
	}
	rv, n2, err := d.DecodeFixedOpaque(int32(dataLen))
	n += n2
	if err != nil {
		return nil, n, err
	}
	return rv, n, nil
}
func (d *Decoder) DecodeString() (string, int, error) {
	dataLen, n, err := d.DecodeUint()
	if err != nil {
		return "", n, err
	}
	if uint(dataLen) > uint(math.MaxInt32) ||
		(d.maxReadSize != 0 && uint(dataLen) > d.maxReadSize) {
		err = unmarshalError("DecodeString", ErrOverflow, errMaxSlice,
			dataLen, nil)
		return "", n, err
	}
	opaque, n2, err := d.DecodeFixedOpaque(int32(dataLen))
	n += n2
	if err != nil {
		return "", n, err
	}
	return string(opaque), n, nil
}