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

Allow prefix with no talker ID #101

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions sentence.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ func Parse(raw string) (Sentence, error) {
// Custom parser allow overriding of existing parsers
if parser, ok := customParsers[s.Type]; ok {
return parser(s)
} else if parser, ok := customParsers[s.Talker+s.Type]; ok {
s.Type = s.Talker + s.Type
s.Talker = ""
return parser(s)
}

if strings.HasPrefix(s.Raw, SentenceStart) {
Expand Down
15 changes: 15 additions & 0 deletions sentence_customparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ var customparsetests = []struct {
StringValue: "two",
},
},
{
name: "zzz sentence without a talker ID",
raw: "$ZZZ,30,two,*19",
msg: TestZZZ{
BaseSentence: BaseSentence{
Talker: "",
Type: "ZZZ",
Fields: []string{"30", "two", ""},
Checksum: "19",
Raw: "$ZZZ,30,two,*19",
},
NumberValue: 30,
StringValue: "two",
},
},
{
name: "zzz sentence type",
raw: "$INVALID,123,123,*7D",
Expand Down