udp_over_tcp.go 683 B

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