param.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package sctp
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. type param interface {
  7. marshal() ([]byte, error)
  8. length() int
  9. }
  10. // ErrParamTypeUnhandled is returned if unknown parameter type is specified.
  11. var ErrParamTypeUnhandled = errors.New("unhandled ParamType")
  12. func buildParam(t paramType, rawParam []byte) (param, error) {
  13. switch t {
  14. case forwardTSNSupp:
  15. return (&paramForwardTSNSupported{}).unmarshal(rawParam)
  16. case supportedExt:
  17. return (&paramSupportedExtensions{}).unmarshal(rawParam)
  18. case ecnCapable:
  19. return (&paramECNCapable{}).unmarshal(rawParam)
  20. case random:
  21. return (&paramRandom{}).unmarshal(rawParam)
  22. case reqHMACAlgo:
  23. return (&paramRequestedHMACAlgorithm{}).unmarshal(rawParam)
  24. case chunkList:
  25. return (&paramChunkList{}).unmarshal(rawParam)
  26. case stateCookie:
  27. return (&paramStateCookie{}).unmarshal(rawParam)
  28. case heartbeatInfo:
  29. return (&paramHeartbeatInfo{}).unmarshal(rawParam)
  30. case outSSNResetReq:
  31. return (&paramOutgoingResetRequest{}).unmarshal(rawParam)
  32. case reconfigResp:
  33. return (&paramReconfigResponse{}).unmarshal(rawParam)
  34. default:
  35. return nil, fmt.Errorf("%w: %v", ErrParamTypeUnhandled, t)
  36. }
  37. }