telegram parser

This commit is contained in:
zhiqiang feng
2020-12-31 14:31:06 +08:00
parent f885002440
commit 3813cab9ab
+26
View File
@@ -0,0 +1,26 @@
package parser
import "strings"
type Telegram struct {
Text string
Complete bool
Parsed bool
Fields []string
Sequence uint16
}
const Start = "ZCZC"
const End = "NNN"
//Parse
func Parse(text string) (*Telegram, error) {
var telegram = &Telegram{Text: text}
telegram.Complete = isStartAndEnd(text)
return telegram, nil
}
func isStartAndEnd(s string) bool {
text := strings.TrimSpace(s)
return strings.HasPrefix(text, Start) && strings.HasSuffix(text, End)
}