...
1 package main
2
3 import (
4 "log"
5 "strings"
6 )
7
8
9
10
11
12 type Protocol struct {
13 Parent *Protocol
14 Name string
15 ExtXName string
16 ExtName string
17 MajorVersion string
18 MinorVersion string
19
20 Imports []*Protocol
21 Types []Type
22 Requests []*Request
23 }
24
25 type Protocols []*Protocol
26
27 func (ps Protocols) Len() int { return len(ps) }
28 func (ps Protocols) Swap(i, j int) { ps[i], ps[j] = ps[j], ps[i] }
29 func (ps Protocols) Less(i, j int) bool { return ps[i].ExtName < ps[j].ExtName }
30
31
32
33
34
35 func (p *Protocol) Initialize() {
36 for _, typ := range p.Types {
37 typ.Initialize(p)
38 }
39 for _, req := range p.Requests {
40 req.Initialize(p)
41 }
42 }
43
44
45
46 func (p *Protocol) PkgName() string {
47 return strings.Replace(p.Name, "_", "", -1)
48 }
49
50
51
52
53 func (p *Protocol) ProtocolFind(name string) *Protocol {
54 if p.Name == name {
55 return p
56 }
57 for _, imp := range p.Imports {
58 if imp.Name == name {
59 return imp
60 }
61 }
62 log.Panicf("Could not find protocol with name '%s'.", name)
63 panic("unreachable")
64 }
65
66
67
68 func (p *Protocol) isExt() bool {
69 return strings.ToLower(p.Name) != "xproto"
70 }
71
View as plain text