Skip to content

Commit

Permalink
Merge pull request #174 from xmidt-org/denopink/feat/qos-normifier
Browse files Browse the repository at this point in the history
feat: add qos normifier
  • Loading branch information
schmidtw committed Apr 18, 2024
2 parents 4690632 + 71b9bd7 commit c6b4db4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions normify.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ func SetSessionID(sessionID string) NormifierOption {
})
}

// ClampQualityOfService clamps a wrp message's qos value between 0 and 99.
func ClampQualityOfService() NormifierOption {
return optionFunc(func(m *Message) error {
if m.QualityOfService < 0 {
m.QualityOfService = 0
} else if m.QualityOfService > 99 {
m.QualityOfService = 99
}

return nil
})
}

// EnsureMetadataString ensures that the message has the given string metadata.
// This will always set the metadata.
func EnsureMetadataString(key, value string) NormifierOption {
Expand Down
18 changes: 18 additions & 0 deletions normify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ func TestNormifier(t *testing.T) {
want: Message{
SessionID: "session",
},
}, {
description: "ClampQualityOfService(), QualityOfService < 0",
opt: ClampQualityOfService(),
msg: Message{
QualityOfService: -1,
},
want: Message{
QualityOfService: 0,
},
}, {
description: "ClampQualityOfService(), QualityOfService > 99",
opt: ClampQualityOfService(),
msg: Message{
QualityOfService: 100,
},
want: Message{
QualityOfService: 99,
},
}, {
description: "EnsureMetadataString(key, value) add to empty",
opt: EnsureMetadataString("key", "value"),
Expand Down

0 comments on commit c6b4db4

Please sign in to comment.