-
Notifications
You must be signed in to change notification settings - Fork 13
/
sccp.go
95 lines (87 loc) · 1.74 KB
/
sccp.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2019-2024 go-sccp authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
/*
Package sccp provides encoding/decoding feature of Signalling Connection Control Part used in SS7/SIGTRAN protocol stack.
This is still an experimental project, and currently in its very early stage of development. Any part of implementations
(including exported APIs) may be changed before released as v1.0.0.
*/
package sccp
import (
"encoding"
"fmt"
)
// MsgType is type of SCCP message.
type MsgType uint8
// Message Type definitions.
const (
_ MsgType = iota
MsgTypeCR
MsgTypeCC
MsgTypeCREF
MsgTypeRLSD
MsgTypeRLC
MsgTypeDT1
MsgTypeDT2
MsgTypeAK
MsgTypeUDT
MsgTypeUDTS
MsgTypeED
MsgTypeEA
MsgTypeRSR
MsgTypeRSC
MsgTypeERR
MsgTypeIT
MsgTypeXUDT
MsgTypeXUDTS
MsgTypeLUDT
MsgTypeLUDTS
)
// Message is an interface that defines SCCP messages.
type Message interface {
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
MarshalTo([]byte) error
MarshalLen() int
MessageType() MsgType
MessageTypeName() string
fmt.Stringer
}
// ParseMessage decodes the byte sequence into Message by Message Type.
// Currently this only supports UDT type of message only.
func ParseMessage(b []byte) (Message, error) {
var m Message
switch MsgType(b[0]) {
/* TODO: implement!
case CR:
case CC:
case CREF:
case RLSD:
case RLC:
case DT1:
case DT2:
case AK:
*/
case MsgTypeUDT:
m = &UDT{}
/* TODO: implement!
case UDTS:
case ED:
case EA:
case RSR:
case RSC:
case ERR:
case IT:
case XUDT:
case XUDTS:
case LUDT:
case LUDTS:
*/
default:
return nil, UnsupportedTypeError(b[0])
}
if err := m.UnmarshalBinary(b); err != nil {
return nil, err
}
return m, nil
}