github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/option/udp_over_tcp.go (about)

     1  package option
     2  
     3  import (
     4  	"github.com/inazumav/sing-box/common/json"
     5  	"github.com/sagernet/sing/common/uot"
     6  )
     7  
     8  type _UDPOverTCPOptions struct {
     9  	Enabled bool  `json:"enabled,omitempty"`
    10  	Version uint8 `json:"version,omitempty"`
    11  }
    12  
    13  type UDPOverTCPOptions _UDPOverTCPOptions
    14  
    15  func (o UDPOverTCPOptions) MarshalJSON() ([]byte, error) {
    16  	switch o.Version {
    17  	case 0, uot.Version:
    18  		return json.Marshal(o.Enabled)
    19  	default:
    20  		return json.Marshal(_UDPOverTCPOptions(o))
    21  	}
    22  }
    23  
    24  func (o *UDPOverTCPOptions) UnmarshalJSON(bytes []byte) error {
    25  	err := json.Unmarshal(bytes, &o.Enabled)
    26  	if err == nil {
    27  		return nil
    28  	}
    29  	return json.Unmarshal(bytes, (*_UDPOverTCPOptions)(o))
    30  }