forked from jjeffery/stomp
/
frame.go
55 lines (49 loc) · 1.42 KB
/
frame.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
54
55
package stomp
// A Frame represents a STOMP frame. A frame consists of a command
// followed by a collection of header elements, and then an optional
// body.
//
// Users of this package will not normally need to make use of the Frame
// type directly. It is a lower level type useful for implementing
// STOMP protocol handlers.
type Frame struct {
Command string
*Header
Body []byte
}
// NewFrame creates a new STOMP frame with the specified command and headers.
// The headers should contain an even number of entries. Each even index is
// the header name, and the odd indexes are the assocated header values.
func NewFrame(command string, headers ...string) *Frame {
f := &Frame{Command: command, Header: &Header{}}
for index := 0; index < len(headers); index += 2 {
f.Add(headers[index], headers[index+1])
}
return f
}
// Clone creates a deep copy of the frame and its header. The cloned
// frame shares the body with the original frame.
func (f *Frame) Clone() *Frame {
return &Frame{Command: f.Command, Header: f.Header.Clone(), Body: f.Body}
}
func (f *Frame) verifyConnect(version Version, isStomp bool) error {
switch version {
case V10:
if isStomp {
}
case V11:
case V12:
}
return nil
}
func (f *Frame) verifyMandatory(keys ...string) error {
for _, key := range keys {
if _, ok := f.Header.index(key); !ok {
return &Error{
Message: "missing header: " + key,
Frame: f,
}
}
}
return nil
}