// Copyright 2016 Mikio Hara. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build darwin dragonfly freebsd linux netbsd openbsd solaris

package tcpopt

import (
	
	
	
)

// Marshal implements the Marshal method of Option interface.
func ( NoDelay) () ([]byte, error) {
	 := boolint32(bool())
	return (*[4]byte)(unsafe.Pointer(&))[:], nil
}

// Marshal implements the Marshal method of Option interface.
func ( MSS) () ([]byte, error) {
	 := int32()
	return (*[4]byte)(unsafe.Pointer(&))[:], nil
}

// Marshal implements the Marshal method of Option interface.
func ( SendBuffer) () ([]byte, error) {
	 := int32()
	return (*[4]byte)(unsafe.Pointer(&))[:], nil
}

// Marshal implements the Marshal method of Option interface.
func ( ReceiveBuffer) () ([]byte, error) {
	 := int32()
	return (*[4]byte)(unsafe.Pointer(&))[:], nil
}

// Marshal implements the Marshal method of Option interface.
func ( KeepAlive) () ([]byte, error) {
	 := boolint32(bool())
	return (*[4]byte)(unsafe.Pointer(&))[:], nil
}

// Marshal implements the Marshal method of Option interface.
func ( KeepAliveIdleInterval) () ([]byte, error) {
	 += KeepAliveIdleInterval(options[soKeepidle].uot - time.Nanosecond)
	 := int32(time.Duration() / options[soKeepidle].uot)
	return (*[4]byte)(unsafe.Pointer(&))[:], nil
}

// Marshal implements the Marshal method of Option interface.
func ( KeepAliveProbeInterval) () ([]byte, error) {
	 += KeepAliveProbeInterval(options[soKeepintvl].uot - time.Nanosecond)
	 := int32(time.Duration() / options[soKeepintvl].uot)
	return (*[4]byte)(unsafe.Pointer(&))[:], nil
}

// Marshal implements the Marshal method of Option interface.
func ( KeepAliveProbeCount) () ([]byte, error) {
	 := int32()
	return (*[4]byte)(unsafe.Pointer(&))[:], nil
}

// Marshal implements the Marshal method of Option interface.
func ( Cork) () ([]byte, error) {
	 := boolint32(bool())
	return (*[4]byte)(unsafe.Pointer(&))[:], nil
}

// Marshal implements the Marshal method of Option interface.
func ( NotSentLowWMK) () ([]byte, error) {
	 := int32()
	return (*[4]byte)(unsafe.Pointer(&))[:], nil
}

// Marshal implements the Marshal method of Option interface.
func ( Error) () ([]byte, error) {
	 := int32()
	return (*[4]byte)(unsafe.Pointer(&))[:], nil
}

// Marshal implements the Marshal method of Option interface.
func ( ECN) () ([]byte, error) {
	 := boolint32(bool())
	return (*[4]byte)(unsafe.Pointer(&))[:], nil
}

func parseNoDelay( []byte) (Option, error) {
	if len() < 4 {
		return nil, errors.New("short buffer")
	}
	return NoDelay(uint32bool(nativeEndian.Uint32())), nil
}

func parseMSS( []byte) (Option, error) {
	if len() < 4 {
		return nil, errors.New("short buffer")
	}
	return MSS(nativeEndian.Uint32()), nil
}

func parseSendBuffer( []byte) (Option, error) {
	if len() < 4 {
		return nil, errors.New("short buffer")
	}
	return SendBuffer(nativeEndian.Uint32()), nil
}

func parseReceiveBuffer( []byte) (Option, error) {
	if len() < 4 {
		return nil, errors.New("short buffer")
	}
	return ReceiveBuffer(nativeEndian.Uint32()), nil
}

func parseKeepAlive( []byte) (Option, error) {
	if len() < 4 {
		return nil, errors.New("short buffer")
	}
	return KeepAlive(uint32bool(nativeEndian.Uint32())), nil
}

func parseKeepAliveIdleInterval( []byte) (Option, error) {
	if len() < 4 {
		return nil, errors.New("short buffer")
	}
	 := time.Duration(nativeEndian.Uint32()) * options[soKeepidle].uot
	return KeepAliveIdleInterval(), nil
}

func parseKeepAliveProbeInterval( []byte) (Option, error) {
	if len() < 4 {
		return nil, errors.New("short buffer")
	}
	 := time.Duration(nativeEndian.Uint32()) * options[soKeepintvl].uot
	return KeepAliveProbeInterval(), nil
}

func parseKeepAliveProbeCount( []byte) (Option, error) {
	if len() < 4 {
		return nil, errors.New("short buffer")
	}
	return KeepAliveProbeCount(nativeEndian.Uint32()), nil
}

func parseCork( []byte) (Option, error) {
	if len() < 4 {
		return nil, errors.New("short buffer")
	}
	return Cork(uint32bool(nativeEndian.Uint32())), nil
}

func parseNotSentLowWMK( []byte) (Option, error) {
	if len() < 4 {
		return nil, errors.New("short buffer")
	}
	return NotSentLowWMK(nativeEndian.Uint32()), nil
}

func parseError( []byte) (Option, error) {
	if len() < 4 {
		return nil, errors.New("short buffer")
	}
	return Error(nativeEndian.Uint32()), nil
}

func parseECN( []byte) (Option, error) {
	if len() < 4 {
		return nil, errors.New("short buffer")
	}
	return ECN(uint32bool(nativeEndian.Uint32())), nil
}