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

package extension

import 

const (
	renegotiationInfoHeaderSize = 5
)

// RenegotiationInfo allows a Client/Server to
// communicate their renegotation support
//
// https://tools.ietf.org/html/rfc5746
type RenegotiationInfo struct {
	RenegotiatedConnection uint8
}

// TypeValue returns the extension TypeValue.
func ( RenegotiationInfo) () TypeValue {
	return RenegotiationInfoTypeValue
}

// Marshal encodes the extension.
func ( *RenegotiationInfo) () ([]byte, error) {
	 := make([]byte, renegotiationInfoHeaderSize)

	binary.BigEndian.PutUint16(, uint16(.TypeValue()))
	binary.BigEndian.PutUint16([2:], uint16(1)) // length
	[4] = .RenegotiatedConnection

	return , nil
}

// Unmarshal populates the extension from encoded data.
func ( *RenegotiationInfo) ( []byte) error {
	if len() < renegotiationInfoHeaderSize {
		return errBufferTooSmall
	} else if TypeValue(binary.BigEndian.Uint16()) != .TypeValue() {
		return errInvalidExtensionType
	}

	.RenegotiatedConnection = [4]

	return nil
}