Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Commit 68377dd

Browse files
committed
chore: Removes IE header from each ie
1 parent c7aeec0 commit 68377dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+344
-819
lines changed

ie/apply_action.go

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ import (
66
)
77

88
type ApplyAction struct {
9-
Header Header
10-
DFRT bool
11-
IPMD bool
12-
IPMA bool
13-
DUPL bool
14-
NOCP bool
15-
BUFF bool
16-
FORW bool
17-
DROP bool
18-
DDPN bool
19-
BDPN bool
20-
EDRT bool
9+
DFRT bool
10+
IPMD bool
11+
IPMA bool
12+
DUPL bool
13+
NOCP bool
14+
BUFF bool
15+
FORW bool
16+
DROP bool
17+
DDPN bool
18+
BDPN bool
19+
EDRT bool
2120
}
2221

2322
type ApplyActionFlag int
@@ -62,11 +61,6 @@ func NewApplyAction(flag ApplyActionFlag, extraFlags []ApplyActionExtraFlag) (Ap
6261
var bdpn bool
6362
var edrt bool
6463

65-
ieHeader := Header{
66-
Type: IEType(ApplyActionIEType),
67-
Length: 2,
68-
}
69-
7064
if (contains(extraFlags, NOCP) || contains(extraFlags, BDPN) || contains(extraFlags, DDPN)) && flag != BUFF {
7165
return ApplyAction{}, fmt.Errorf("the NOCP flag, BDPN and DDPN flag may only be set if the BUFF flag is set")
7266
}
@@ -124,27 +118,23 @@ func NewApplyAction(flag ApplyActionFlag, extraFlags []ApplyActionExtraFlag) (Ap
124118
}
125119

126120
return ApplyAction{
127-
Header: ieHeader,
128-
DFRT: dfrt,
129-
IPMD: ipmd,
130-
IPMA: ipma,
131-
DUPL: dupl,
132-
NOCP: nocp,
133-
BUFF: buff,
134-
FORW: forw,
135-
DROP: drop,
136-
DDPN: ddpn,
137-
BDPN: bdpn,
138-
EDRT: edrt,
121+
DFRT: dfrt,
122+
IPMD: ipmd,
123+
IPMA: ipma,
124+
DUPL: dupl,
125+
NOCP: nocp,
126+
BUFF: buff,
127+
FORW: forw,
128+
DROP: drop,
129+
DDPN: ddpn,
130+
BDPN: bdpn,
131+
EDRT: edrt,
139132
}, nil
140133
}
141134

142135
func (applyaction ApplyAction) Serialize() []byte {
143136
buf := new(bytes.Buffer)
144137

145-
// Octets 1 to 4: Header
146-
buf.Write(applyaction.Header.Serialize())
147-
148138
// Octet 5: DFRT (bit 8), IPMD (bit 7), IPMA (bit 6), DUPL (bit 5), NOCP (bit 4), BUFF (bit 3), FORW (bit 2), DROP (bit 1)
149139
var byte5 byte
150140
if applyaction.DFRT {
@@ -189,13 +179,8 @@ func (applyaction ApplyAction) Serialize() []byte {
189179
return buf.Bytes()
190180
}
191181

192-
func (applyaction ApplyAction) IsZeroValue() bool {
193-
return applyaction.Header.Length == 0
194-
}
195-
196-
func (applyaction ApplyAction) SetHeader(header Header) InformationElement {
197-
applyaction.Header = header
198-
return applyaction
182+
func (applyAction ApplyAction) GetType() IEType {
183+
return ApplyActionIEType
199184
}
200185

201186
func DeserializeApplyAction(ieValue []byte) (ApplyAction, error) {

ie/apply_action_test.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ func TestGivenCorrectValuesWhenNewApplyActionThenFieldsSetCorrectly(t *testing.T
1414
t.Fatalf("Error creating ApplyAction: %v", err)
1515
}
1616

17-
if applyAction.Header.Type != 44 {
18-
t.Errorf("Expected IEType 44, got %d", applyAction.Header.Type)
19-
}
20-
21-
if applyAction.Header.Length != 2 {
22-
t.Errorf("Expected Length 2, got %d", applyAction.Header.Length)
23-
}
24-
2517
if applyAction.FORW != true {
2618
t.Errorf("Expected FORW %v, got %v", flag, applyAction.FORW)
2719
}
@@ -114,7 +106,7 @@ func TestGivenApplyActionSerializedWhenDeserializeThenFieldsSetCorrectly(t *test
114106

115107
serialized := applyAction.Serialize()
116108

117-
deserialized, err := ie.DeserializeApplyAction(serialized[4:])
109+
deserialized, err := ie.DeserializeApplyAction(serialized)
118110

119111
if err != nil {
120112
t.Fatalf("Error deserializing ApplyAction: %v", err)

ie/cause.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
)
77

88
type Cause struct {
9-
Header Header
10-
Value CauseValue
9+
Value CauseValue
1110
}
1211

1312
type CauseValue uint8
@@ -38,36 +37,22 @@ func NewCause(value CauseValue) (Cause, error) {
3837
return Cause{}, fmt.Errorf("invalid value for Cause: %d", value)
3938
}
4039

41-
header := Header{
42-
Type: CauseIEType,
43-
Length: 1,
44-
}
45-
4640
return Cause{
47-
Header: header,
48-
Value: value,
41+
Value: value,
4942
}, nil
5043
}
5144

5245
func (cause Cause) Serialize() []byte {
5346
buf := new(bytes.Buffer)
5447

55-
// Octets 1 to 4: Header
56-
buf.Write(cause.Header.Serialize())
57-
5848
// Octet 5: Value (1 byte)
5949
buf.WriteByte(uint8(cause.Value))
6050

6151
return buf.Bytes()
6252
}
6353

64-
func (cause Cause) IsZeroValue() bool {
65-
return cause.Value == 0
66-
}
67-
68-
func (cause Cause) SetHeader(ieHeader Header) InformationElement {
69-
cause.Header = ieHeader
70-
return cause
54+
func (cause Cause) GetType() IEType {
55+
return CauseIEType
7156
}
7257

7358
func DeserializeCause(ieValue []byte) (Cause, error) {

ie/create_far.go

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,13 @@ import (
77
)
88

99
type CreateFAR struct {
10-
Header Header
1110
FARID FARID
1211
ApplyAction ApplyAction
1312
}
1413

1514
func NewCreateFAR(farid FARID, applyaction ApplyAction) (CreateFAR, error) {
16-
ieHeader := Header{
17-
Type: IEType(CreateFARIEType),
18-
Length: farid.Header.Length + applyaction.Header.Length + 8,
19-
}
2015

2116
return CreateFAR{
22-
Header: ieHeader,
2317
FARID: farid,
2418
ApplyAction: applyaction,
2519
}, nil
@@ -28,28 +22,32 @@ func NewCreateFAR(farid FARID, applyaction ApplyAction) (CreateFAR, error) {
2822
func (createfar CreateFAR) Serialize() []byte {
2923
buf := new(bytes.Buffer)
3024

31-
// Octets 1 to 4: Header
32-
buf.Write(createfar.Header.Serialize())
33-
3425
// Octets 5 to n: FAR ID
3526
serializedFARID := createfar.FARID.Serialize()
27+
farIDLength := uint16(len(serializedFARID))
28+
farIDHeader := Header{
29+
Type: createfar.FARID.GetType(),
30+
Length: farIDLength,
31+
}
32+
buf.Write(farIDHeader.Serialize())
3633
buf.Write(serializedFARID)
3734

3835
// Octets n+1 to m: Apply Action
3936
serializedApplyAction := createfar.ApplyAction.Serialize()
37+
applyActionLength := uint16(len(serializedApplyAction))
38+
applyActionHeader := Header{
39+
Type: createfar.ApplyAction.GetType(),
40+
Length: applyActionLength,
41+
}
42+
buf.Write(applyActionHeader.Serialize())
4043
buf.Write(serializedApplyAction)
4144

4245
return buf.Bytes()
4346

4447
}
4548

46-
func (createfar CreateFAR) IsZeroValue() bool {
47-
return createfar.Header.Length == 0
48-
}
49-
50-
func (createfar CreateFAR) SetHeader(header Header) InformationElement {
51-
createfar.Header = header
52-
return createfar
49+
func (createfar CreateFAR) GetType() IEType {
50+
return CreateFARIEType
5351
}
5452

5553
func DeserializeCreateFAR(value []byte) (CreateFAR, error) {
@@ -65,7 +63,7 @@ func DeserializeCreateFAR(value []byte) (CreateFAR, error) {
6563
if buffer.Len() < 2 {
6664
return CreateFAR{}, fmt.Errorf("not enough data for FARID type")
6765
}
68-
faridIEType := binary.BigEndian.Uint16(buffer.Next(2))
66+
buffer.Next(2)
6967

7068
if buffer.Len() < 2 {
7169
return CreateFAR{}, fmt.Errorf("not enough data for FARID length")
@@ -74,26 +72,18 @@ func DeserializeCreateFAR(value []byte) (CreateFAR, error) {
7472
faridIELength := binary.BigEndian.Uint16(buffer.Next(2))
7573
faridIEValue := buffer.Next(int(faridIELength))
7674

77-
faridIEHEader := Header{
78-
Type: IEType(faridIEType),
79-
Length: faridIELength,
80-
}
81-
82-
tempFarid, err := DeserializeFARID(faridIEValue)
75+
farid, err := DeserializeFARID(faridIEValue)
8376
if err != nil {
8477
return CreateFAR{}, fmt.Errorf("failed to deserialize FARID: %v", err)
8578
}
86-
farid, ok := tempFarid.SetHeader(faridIEHEader).(FARID)
87-
if !ok {
88-
return CreateFAR{}, fmt.Errorf("type assertion to FarID failed")
89-
}
9079

9180
createfar.FARID = farid
9281

9382
if buffer.Len() < 2 {
9483
return CreateFAR{}, fmt.Errorf("not enough data for ApplyAction type")
9584
}
96-
applyactionIEType := binary.BigEndian.Uint16(buffer.Next(2))
85+
86+
buffer.Next(2)
9787

9888
if buffer.Len() < 2 {
9989
return CreateFAR{}, fmt.Errorf("not enough data for ApplyAction length")
@@ -105,21 +95,11 @@ func DeserializeCreateFAR(value []byte) (CreateFAR, error) {
10595
}
10696
applyactionIEValue := buffer.Next(int(applyactionIELength))
10797

108-
applyActionHeader := Header{
109-
Type: IEType(applyactionIEType),
110-
Length: applyactionIELength,
111-
}
112-
113-
tempApplyaction, err := DeserializeApplyAction(applyactionIEValue)
98+
applyaction, err := DeserializeApplyAction(applyactionIEValue)
11499
if err != nil {
115100
return CreateFAR{}, fmt.Errorf("failed to deserialize ApplyAction: %v", err)
116101
}
117102

118-
applyaction, ok := tempApplyaction.SetHeader(applyActionHeader).(ApplyAction)
119-
if !ok {
120-
return CreateFAR{}, fmt.Errorf("type assertion to ApplyAction failed")
121-
}
122-
123103
createfar.ApplyAction = applyaction
124104
return createfar, nil
125105
}

ie/create_far_test.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,10 @@ func TestGivenCorrectValuesWhenNewFarThenFieldsSetCorrectly(t *testing.T) {
7474
t.Errorf("Expected BDPN false, got %v", createFar.ApplyAction.BDPN)
7575
}
7676

77-
if createFar.ApplyAction.Header.Length != 2 {
78-
t.Errorf("Expected Length 2, got %d", createFar.ApplyAction.Header.Length)
79-
}
80-
81-
if createFar.ApplyAction.Header.Type != 44 {
82-
t.Errorf("Expected IEType 44, got %d", createFar.ApplyAction.Header.Type)
83-
}
84-
8577
}
8678

8779
func TestGivenSerializedWhenDeserializeCreateFarThenFieldsSetCorrectly(t *testing.T) {
8880
farId, err := ie.NewFarID(1)
89-
9081
if err != nil {
9182
t.Fatalf("Error creating FARID: %v", err)
9283
}
@@ -105,7 +96,7 @@ func TestGivenSerializedWhenDeserializeCreateFarThenFieldsSetCorrectly(t *testin
10596

10697
serialized := createFar.Serialize()
10798

108-
deserialized, err := ie.DeserializeCreateFAR(serialized[4:])
99+
deserialized, err := ie.DeserializeCreateFAR(serialized)
109100

110101
if err != nil {
111102
t.Fatalf("Error deserializing CreateFAR: %v", err)

0 commit comments

Comments
 (0)