-
Notifications
You must be signed in to change notification settings - Fork 0
/
hdr.go
45 lines (38 loc) · 822 Bytes
/
hdr.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
package main
import (
"sync"
"github.com/betawaffle/kafka-gen-go/codegen"
"github.com/betawaffle/kafka-gen-go/schema"
)
type hdrGenerator struct {
mu sync.Mutex
req *schema.MessageData
res *schema.MessageData
}
func (g *hdrGenerator) addMessage(m *schema.MessageData) bool {
g.mu.Lock()
defer g.mu.Unlock()
var ok bool
switch m.Name {
case "RequestHeader":
if g.req != nil {
panic("request header conflict")
}
g.req, ok = m, g.res != nil
case "ResponseHeader":
if g.res != nil {
panic("response header conflict")
}
g.res, ok = m, g.req != nil
default:
panic("BUG: unexpected header name: " + m.Name)
}
return ok
}
func (g *hdrGenerator) getFileName() string {
return "headers_gen.go"
}
func (g *hdrGenerator) run(w *codegen.File) {
genMessage(w, g.req)
genMessage(w, g.res)
}