func (m *MLDv2MulticastListenerQueryMessage) serializeSourceAddressesTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
	numberOfSourceAddresses := len(m.SourceAddresses)
	if numberOfSourceAddresses > math.MaxUint16 {
		return fmt.Errorf(
			"there are more than %d source addresses, but 65535 is the maximum number of supported addresses",
			numberOfSourceAddresses)
	}
	if opts.FixLengths {
		m.NumberOfSources = uint16(numberOfSourceAddresses)
	}
	lastSAIdx := numberOfSourceAddresses - 1
	for k := range m.SourceAddresses {
		i := lastSAIdx - k  
		buf, err := b.PrependBytes(16)
		if err != nil {
			return err
		}
		sa16 := m.SourceAddresses[i].To16()
		if sa16 == nil {
			return fmt.Errorf("invalid source address [%d] '%s'", i, m.SourceAddresses[i])
		}
		copy(buf[0:16], sa16)
	}
	return nil
}
writes each source address to the buffer preserving the order
package layers
import (
	"encoding/binary"
	"errors"
	"fmt"
	"math"
	"net"
	"time"
	"github.com/google/gopacket"
)
const (
	mldv2STrue uint8 = 0x8
	mldv2SMask uint8 = 0x8
	mldv2QRVMask uint8 = 0x7
)
type MLDv2MulticastListenerQueryMessage struct {
	BaseLayer
	MaximumResponseCode uint16
	MulticastAddress net.IP
	SuppressRoutersideProcessing bool
	QueriersRobustnessVariable uint8
	QueriersQueryIntervalCode uint8
	NumberOfSources uint16
	SourceAddresses []net.IP
}
func (m *MLDv2MulticastListenerQueryMessage) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
	if len(data) < 24 {
		df.SetTruncated()
		return errors.New("ICMP layer less than 24 bytes for Multicast Listener Query Message V2")
	}
	m.MaximumResponseCode = binary.BigEndian.Uint16(data[0:2])
	m.MulticastAddress = data[4:20]
	m.SuppressRoutersideProcessing = (data[20] & mldv2SMask) == mldv2STrue
	m.QueriersRobustnessVariable = data[20] & mldv2QRVMask
	m.QueriersQueryIntervalCode = data[21]
	m.NumberOfSources = binary.BigEndian.Uint16(data[22:24])
	var end int
	for i := uint16(0); i < m.NumberOfSources; i++ {
		begin := 24 + (int(i) * 16)
		end = begin + 16
		if end > len(data) {
			df.SetTruncated()
			return fmt.Errorf("ICMP layer less than %d bytes for Multicast Listener Query Message V2", end)
		}
		m.SourceAddresses = append(m.SourceAddresses, data[begin:end])
	}
	return nil
}
func (*MLDv2MulticastListenerQueryMessage) NextLayerType() gopacket.LayerType {
	return gopacket.LayerTypeZero
}
func (m *MLDv2MulticastListenerQueryMessage) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
	if err := m.serializeSourceAddressesTo(b, opts); err != nil {
		return err
	}
	buf, err := b.PrependBytes(24)
	if err != nil {
		return err
	}
	binary.BigEndian.PutUint16(buf[0:2], m.MaximumResponseCode)
	copy(buf[2:4], []byte{0x00, 0x00})  
	ma16 := m.MulticastAddress.To16()
	if ma16 == nil {
		return fmt.Errorf("invalid MulticastAddress '%s'", m.MulticastAddress)
	}
	copy(buf[4:20], ma16)
	byte20 := m.QueriersRobustnessVariable & mldv2QRVMask
	if m.SuppressRoutersideProcessing {
		byte20 |= mldv2STrue
	} else {
		byte20 &= ^mldv2STrue  
	}
	byte20 &= 0x0F  
	buf[20] = byte20
	binary.BigEndian.PutUint16(buf[22:24], m.NumberOfSources)
	buf[21] = m.QueriersQueryIntervalCode
	return nil
}