// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package proto

import (
	

	
)

// ConnectionID represents CONNECTION-ID attribute.
//
// The CONNECTION-ID attribute uniquely identifies a peer data
// connection.  It is a 32-bit unsigned integral value.
//
// RFC 6062 Section 6.2.1.
type ConnectionID uint32

const connectionIDSize = 4 // uint32: 4 bytes, 32 bits

// AddTo adds CONNECTION-ID to message.
func ( ConnectionID) ( *stun.Message) error {
	 := make([]byte, lifetimeSize)
	binary.BigEndian.PutUint32(, uint32())
	.Add(stun.AttrConnectionID, )

	return nil
}

// GetFrom decodes CONNECTION-ID from message.
func ( *ConnectionID) ( *stun.Message) error {
	,  := .Get(stun.AttrConnectionID)
	if  != nil {
		return 
	}
	if  = stun.CheckSize(stun.AttrConnectionID, len(), connectionIDSize);  != nil {
		return 
	}
	_ = [connectionIDSize-1] // Asserting length
	*(*uint32)() = binary.BigEndian.Uint32()

	return nil
}