telegram parser
This commit is contained in:
@@ -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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user