-
Notifications
You must be signed in to change notification settings - Fork 79
/
param.go
46 lines (41 loc) · 1.3 KB
/
param.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package sctp
import (
"errors"
"fmt"
)
type param interface {
marshal() ([]byte, error)
length() int
}
// ErrParamTypeUnhandled is returned if unknown parameter type is specified.
var ErrParamTypeUnhandled = errors.New("unhandled ParamType")
func buildParam(t paramType, rawParam []byte) (param, error) {
switch t {
case forwardTSNSupp:
return (¶mForwardTSNSupported{}).unmarshal(rawParam)
case supportedExt:
return (¶mSupportedExtensions{}).unmarshal(rawParam)
case ecnCapable:
return (¶mECNCapable{}).unmarshal(rawParam)
case random:
return (¶mRandom{}).unmarshal(rawParam)
case reqHMACAlgo:
return (¶mRequestedHMACAlgorithm{}).unmarshal(rawParam)
case chunkList:
return (¶mChunkList{}).unmarshal(rawParam)
case stateCookie:
return (¶mStateCookie{}).unmarshal(rawParam)
case heartbeatInfo:
return (¶mHeartbeatInfo{}).unmarshal(rawParam)
case outSSNResetReq:
return (¶mOutgoingResetRequest{}).unmarshal(rawParam)
case reconfigResp:
return (¶mReconfigResponse{}).unmarshal(rawParam)
case zeroChecksumAcceptable:
return (¶mZeroChecksumAcceptable{}).unmarshal(rawParam)
default:
return nil, fmt.Errorf("%w: %v", ErrParamTypeUnhandled, t)
}
}