I am working with equipments that can occasionally send slightly invalid messages, containing empty AVPs (the length is valid, but the "data" is empty).
This change aims to address this issue by adding an optional parameter in dictionaries to set whether the parsing of incoming messages should be strict or not (it is strict by default).
TODO
[ ] There is a missing change needed for this PR to work with #146: the latter introduces a new function called dict.NewParserFromLibrary and it needs to be modified to set p.Strict = true just like dict.NewParser does.
Example usage
dictionary, err := dict.NewParserFromLibrary(
library.Base,
library.CreditControl,
library.TgppRoRf,
)
if err != nil {
panic(err)
}
dictionary.Strict = false // Does not return an error when one or more incoming AVPs are invalid or empty
// declare stateMachine
if err := diam.ListenAndServeNetwork("tcp", "127.0.0.1", stateMachine, dictionary); err != nil {
panic(err)
}
How to get the parsing error?
When Parser.Strict is set to false, the parsing error is accessible like so:
func myHandler(conn diam.Conn, msg *diam.Message) {
if msg.DecodeErr != nil {
// some custom logic, like logging the error
}
}
Example error (shows the AVP stack, down the actual error, and it contains all the invalid AVPs, not just the first one):
Failed to decode one or more AVPs: {Service-Information(873): Grouped{SMS-Information(2000): Grouped{Recipient-SCCP-Address(2010): Not enough data to make an Address from byte[0] = []}}}
I am working with equipments that can occasionally send slightly invalid messages, containing empty AVPs (the length is valid, but the "data" is empty).
This change aims to address this issue by adding an optional parameter in dictionaries to set whether the parsing of incoming messages should be strict or not (it is strict by default).
TODO
dict.NewParserFromLibrary
and it needs to be modified to setp.Strict = true
just likedict.NewParser
does.Example usage
How to get the parsing error?
When
Parser.Strict
is set tofalse
, the parsing error is accessible like so:Example error (shows the AVP stack, down the actual error, and it contains all the invalid AVPs, not just the first one):
Failed to decode one or more AVPs: {Service-Information(873): Grouped{SMS-Information(2000): Grouped{Recipient-SCCP-Address(2010): Not enough data to make an Address from byte[0] = []}}}