config_json.go 709 B

123456789101112131415161718192021222324252627
  1. // +build json
  2. package kcp
  3. import (
  4. "encoding/json"
  5. )
  6. func (this *Config) UnmarshalJSON(data []byte) error {
  7. type JSONConfig struct {
  8. Mode string `json:"Mode"`
  9. Mtu int `json:"MaximumTransmissionUnit"`
  10. Sndwnd int `json:"SendingWindowSize"`
  11. Rcvwnd int `json:"ReceivingWindowSize"`
  12. Fec int `json:"ForwardErrorCorrectionGroupSize"`
  13. Acknodelay bool `json:"AcknowledgeNoDelay"`
  14. Dscp int `json:"Dscp"`
  15. ReadTimeout int `json:"ReadTimeout"`
  16. WriteTimeout int `json:"WriteTimeout"`
  17. }
  18. jsonConfig := effectiveConfig
  19. if err := json.Unmarshal(data, &jsonConfig); err != nil {
  20. return err
  21. }
  22. *this = jsonConfig
  23. return nil
  24. }