-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfasthl7.go
53 lines (42 loc) · 868 Bytes
/
fasthl7.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package fasthl7
import (
"bytes"
"errors"
)
const (
SegmentSeparator = '\r'
)
type Message []Segment
type Segment []Field
func (s Segment) Name() string {
return string(s[0][0][0][0])
}
type Field []Repetition
type Repetition []Component
type Component []Subcomponent
type Subcomponent []byte
type Delimiters struct {
Field byte
Component byte
Repeat byte
Escape byte
Subcomponent byte
}
func GetDelimiters(msg []byte) (*Delimiters, error) {
if len(msg) < 8 {
return nil, errors.New("error: msg too short")
}
if !bytes.HasPrefix(msg, []byte("MSH")) {
return nil, errors.New("error: missing header")
}
return &Delimiters{
Field: msg[3],
Component: msg[4],
Repeat: msg[5],
Escape: msg[6],
Subcomponent: msg[7],
}, nil
}
func ParseMessage(b []byte) (Message, error) {
return nil, nil
}