memory_settings.go 978 B

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