Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Additional Supported-Features #133

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 59 additions & 7 deletions ie/cp-function-features.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@

package ie

import "io"

// NewCPFunctionFeatures creates a new CPFunctionFeatures IE.
func NewCPFunctionFeatures(features uint8) *IE {
return newUint8ValIE(CPFunctionFeatures, features)
func NewCPFunctionFeatures(features ...uint8) *IE {
return New(CPFunctionFeatures, features)
}

// CPFunctionFeatures returns CPFunctionFeatures in uint8 if the type of IE matches.
func (i *IE) CPFunctionFeatures() (uint8, error) {
// CPFunctionFeatures returns CPFunctionFeatures in []byte if the type of IE matches.
func (i *IE) CPFunctionFeatures() ([]byte, error) {
if i.Type != CPFunctionFeatures {
return 0, &InvalidTypeError{Type: i.Type}
return nil, &InvalidTypeError{Type: i.Type}
}

return i.ValueAsUint8()
if len(i.Payload) < 1 {
return nil, io.ErrUnexpectedEOF
}
return i.Payload, nil
}

// HasLOAD reports whether an IE has LOAD bit.
Expand All @@ -41,3 +45,51 @@ func (i *IE) HasOVRL() bool {

return has2ndBit(i.Payload[0])
}

// HasARDR reports whether an IE has ARDR bit.
func (i *IE) HasARDR() bool {
if i.Type != CPFunctionFeatures {
return false
}
if len(i.Payload) < 1 {
return false
}

return has7thBit(i.Payload[0])
}

// HasUIAUR reports whether an IE has UIAUR bit.
func (i *IE) HasUIAUR() bool {
if i.Type != CPFunctionFeatures {
return false
}
if len(i.Payload) < 1 {
return false
}

return has8thBit(i.Payload[0])
}

// HasPSUCC reports whether an IE has PSUCC bit.
func (i *IE) HasPSUCC() bool {
if i.Type != CPFunctionFeatures {
return false
}
if len(i.Payload) < 2 {
return false
}

return has1stBit(i.Payload[1])
}

// HasRPGUR reports whether an IE has RPGUR bit.
func (i *IE) HasRPGUR() bool {
if i.Type != CPFunctionFeatures {
return false
}
if len(i.Payload) < 2 {
return false
}

return has2ndBit(i.Payload[1])
}
10 changes: 10 additions & 0 deletions ie/ie_byte_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ func TestByteArrayIEs(t *testing.T) {
),
decoded: []byte{0x04, 0x02},
decoderFunc: func(i *ie.IE) ([]byte, error) { return i.ApplyAction() },
}, {
description: "CPFunctionFeatures",
structured: ie.NewCPFunctionFeatures(0x3f),
decoded: []byte{0x3f},
decoderFunc: func(i *ie.IE) ([]byte, error) { return i.CPFunctionFeatures() },
}, {
description: "CPFunctionFeatures/2bytes",
structured: ie.NewCPFunctionFeatures(0x3f, 0x01),
decoded: []byte{0x3f, 0x01},
decoderFunc: func(i *ie.IE) ([]byte, error) { return i.CPFunctionFeatures() },
},
}

Expand Down
5 changes: 0 additions & 5 deletions ie/ie_uint8_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,6 @@ func TestUint8IEs(t *testing.T) {
structured: ie.NewCause(ie.CauseRequestAccepted),
decoded: ie.CauseRequestAccepted,
decoderFunc: func(i *ie.IE) (uint8, error) { return i.Cause() },
}, {
description: "CPFunctionFeatures",
structured: ie.NewCPFunctionFeatures(0x3f),
decoded: 0x3f,
decoderFunc: func(i *ie.IE) (uint8, error) { return i.CPFunctionFeatures() },
}, {
description: "CreateBridgeInfoForTSC",
structured: ie.NewCreateBridgeInfoForTSC(1),
Expand Down
Loading