memory_settings.go 1021 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package internet
  2. // MemoryStreamConfig is a parsed form of StreamConfig. This is used to reduce the number of Protobuf parsings.
  3. type MemoryStreamConfig struct {
  4. ProtocolName string
  5. ProtocolSettings interface{}
  6. SecurityType string
  7. SecuritySettings interface{}
  8. SocketSettings *SocketConfig
  9. DownloadSettings *MemoryStreamConfig
  10. }
  11. // ToMemoryStreamConfig converts a StreamConfig to MemoryStreamConfig. It returns a default non-nil MemoryStreamConfig for nil input.
  12. func ToMemoryStreamConfig(s *StreamConfig) (*MemoryStreamConfig, error) {
  13. ets, err := s.GetEffectiveTransportSettings()
  14. if err != nil {
  15. return nil, err
  16. }
  17. mss := &MemoryStreamConfig{
  18. ProtocolName: s.GetEffectiveProtocol(),
  19. ProtocolSettings: ets,
  20. }
  21. if s != nil {
  22. mss.SocketSettings = s.SocketSettings
  23. }
  24. if s != nil && s.HasSecuritySettings() {
  25. ess, err := s.GetEffectiveSecuritySettings()
  26. if err != nil {
  27. return nil, err
  28. }
  29. mss.SecurityType = s.SecurityType
  30. mss.SecuritySettings = ess
  31. }
  32. return mss, nil
  33. }