| 1 | package mainscip-go gomod github.com/valinurovam/garagemq . `github.com/valinurovam/garagemq/protocol`/ |
| 2 | |
| 3 | import "text/templatescip-go gomod github.com/golang/go/src go1.12 `text/template`/" |
| 4 | |
| 5 | func getConstantsTemplatescip-go gomod github.com/valinurovam/garagemq . `github.com/valinurovam/garagemq/protocol`/getConstantsTemplate().() *templatescip-go gomod github.com/golang/go/src go1.12 `text/template`/.Templatescip-go gomod github.com/golang/go/src go1.12 `text/template`/Template# { |
| 6 | const constTemplate = ` |
| 7 | // Package amqp for read, write, parse amqp frames |
| 8 | // Autogenerated code. Do not edit. |
| 9 | package amqp |
| 10 | {{range .}} |
| 11 | {{.Doc}} |
| 12 | const {{.GoName}} = {{.Value}} |
| 13 | {{end}} |
| 14 | |
| 15 | // ConstantsNameMap map for mapping error codes into error messages |
| 16 | var ConstantsNameMap = map[uint16]string{ |
| 17 | {{range .}} |
| 18 | {{if eq .IgnoreOnMap false}} |
| 19 | {{.Value}}: "{{.GoStr}}",{{end}} |
| 20 | {{end}} |
| 21 | } |
| 22 | ` |
| 23 | return templatescip-go gomod github.com/golang/go/src go1.12 `text/template`/.Mustscip-go gomod github.com/golang/go/src go1.12 `text/template`/Must().(templatescip-go gomod github.com/golang/go/src go1.12 `text/template`/.Newscip-go gomod github.com/golang/go/src go1.12 `text/template`/New().("constTemplate").Parsescip-go gomod github.com/golang/go/src go1.12 `text/template`/Template#Parse().(constTemplate)) |
| 24 | } |
| 25 | |
| 26 | func getMethodsTemplatescip-go gomod github.com/valinurovam/garagemq . `github.com/valinurovam/garagemq/protocol`/getMethodsTemplate().() *templatescip-go gomod github.com/golang/go/src go1.12 `text/template`/.Templatescip-go gomod github.com/golang/go/src go1.12 `text/template`/Template# { |
| 27 | const methodsTemplate = ` |
| 28 | // Package amqp for read, write, parse amqp frames |
| 29 | // Autogenerated code. Do not edit. |
| 30 | package amqp |
| 31 | |
| 32 | import ( |
| 33 | "io" |
| 34 | "fmt" |
| 35 | "time" |
| 36 | ) |
| 37 | |
| 38 | // Method represents base method interface |
| 39 | type Method interface { |
| 40 | Name() string |
| 41 | FrameType() byte |
| 42 | ClassIdentifier() uint16 |
| 43 | MethodIdentifier() uint16 |
| 44 | Read(reader io.Reader, protoVersion string) (err error) |
| 45 | Write(writer io.Writer, protoVersion string) (err error) |
| 46 | Sync() bool |
| 47 | } |
| 48 | {{range .}} |
| 49 | {{$classId := .ID}} |
| 50 | // {{.GoName}} methods |
| 51 | |
| 52 | {{ if .Fields }} |
| 53 | // {{.GoName}}PropertyList represents properties for {{.GoName}} method |
| 54 | type {{.GoName}}PropertyList struct { |
| 55 | {{range .Fields}}{{.GoName}} {{if ne .GoType "*Table"}}*{{end}}{{.GoType}} |
| 56 | {{end}} |
| 57 | } |
| 58 | // {{.GoName}}PropertyList reads properties from io reader |
| 59 | func (pList *{{.GoName}}PropertyList) Read(reader io.Reader, propertyFlags uint16, protoVersion string) (err error) { |
| 60 | {{range .Fields}} |
| 61 | if propertyFlags&(1<<{{.HeaderIndex}}) != 0 { |
| 62 | value, err := Read{{.ReaderFunc}}(reader{{if eq .ReaderFunc "Table"}}, protoVersion{{end}}) |
| 63 | if err != nil { |
| 64 | return err |
| 65 | } |
| 66 | pList.{{.GoName}} = {{if ne .GoType "*Table"}}&{{end}}value |
| 67 | } |
| 68 | {{end}} |
| 69 | return |
| 70 | } |
| 71 | // {{.GoName}}PropertyList wiretes properties into io writer |
| 72 | func (pList *{{.GoName}}PropertyList) Write(writer io.Writer, protoVersion string) (propertyFlags uint16, err error) { |
| 73 | {{range .Fields}} |
| 74 | if pList.{{.GoName}} != nil { |
| 75 | propertyFlags |= 1 << {{.HeaderIndex}} |
| 76 | if err = Write{{.ReaderFunc}}(writer, {{if ne .GoType "*Table"}}*{{end}}pList.{{.GoName}}{{if eq .ReaderFunc "Table"}}, protoVersion{{end}}); err != nil { |
| 77 | return |
| 78 | } |
| 79 | } |
| 80 | {{end}} |
| 81 | return |
| 82 | } |
| 83 | {{end}} |
| 84 | {{range .Methods}} |
| 85 | {{.Doc}} |
| 86 | type {{.GoName}} struct { |
| 87 | {{range .Fields}}{{.GoName}} {{.GoType}} |
| 88 | {{end}} |
| 89 | } |
| 90 | // Name returns method name as string, usefully for logging |
| 91 | func (method *{{.GoName}}) Name() string { |
| 92 | return "{{.GoName}}" |
| 93 | } |
| 94 | |
| 95 | // FrameType returns method frame type |
| 96 | func (method *{{.GoName}}) FrameType() byte { |
| 97 | return 1 |
| 98 | } |
| 99 | |
| 100 | // ClassIdentifier returns method classID |
| 101 | func (method *{{.GoName}}) ClassIdentifier() uint16 { |
| 102 | return {{$classId}} |
| 103 | } |
| 104 | |
| 105 | // MethodIdentifier returns method methodID |
| 106 | func (method *{{.GoName}}) MethodIdentifier() uint16 { |
| 107 | return {{.ID}} |
| 108 | } |
| 109 | |
| 110 | // Sync is method should me sent synchronous |
| 111 | func (method *{{.GoName}}) Sync() bool { |
| 112 | return {{if eq .Synchronous 1}}true{{else}}false{{end}} |
| 113 | } |
| 114 | |
| 115 | // Read method from io reader |
| 116 | func (method *{{.GoName}}) Read(reader io.Reader, protoVersion string) (err error) { |
| 117 | {{range .Fields}} |
| 118 | {{if .IsBit }} |
| 119 | {{if eq .BitOrder 0}} |
| 120 | bits, err := ReadOctet(reader) |
| 121 | if err != nil { |
| 122 | return err |
| 123 | } |
| 124 | {{end}} |
| 125 | method.{{.GoName}} = bits&(1<<{{.BitOrder}}) != 0 |
| 126 | {{else}} |
| 127 | method.{{.GoName}}, err = Read{{.ReaderFunc}}(reader{{if eq .ReaderFunc "Table"}}, protoVersion{{end}}) |
| 128 | if err != nil { |
| 129 | return err |
| 130 | } |
| 131 | {{end}} |
| 132 | |
| 133 | {{end}} |
| 134 | return |
| 135 | } |
| 136 | |
| 137 | // Write method from io reader |
| 138 | func (method *{{.GoName}}) Write(writer io.Writer, protoVersion string) (err error) { |
| 139 | {{$bitFieldsStarted := false}} |
| 140 | {{range .Fields}} |
| 141 | {{if .IsBit }} |
| 142 | {{$bitFieldsStarted := true}} |
| 143 | {{if eq .BitOrder 0}} |
| 144 | var bits byte |
| 145 | {{end}} |
| 146 | if method.{{.GoName}} { |
| 147 | bits |= 1 << {{.BitOrder}} |
| 148 | } |
| 149 | {{if .LastBit}} |
| 150 | if err = WriteOctet(writer, bits); err != nil { |
| 151 | return err |
| 152 | } |
| 153 | {{end}} |
| 154 | {{else}} |
| 155 | if err = Write{{.ReaderFunc}}(writer, method.{{.GoName}}{{if eq .ReaderFunc "Table"}}, protoVersion{{end}}); err != nil { |
| 156 | return err |
| 157 | } |
| 158 | {{end}} |
| 159 | {{end}} |
| 160 | return |
| 161 | } |
| 162 | {{end}} |
| 163 | {{end}} |
| 164 | |
| 165 | /* |
| 166 | ReadMethod reads method from frame's payload |
| 167 | |
| 168 | Method frames carry the high-level protocol commands (which we call "methods"). |
| 169 | One method frame carries one command. The method frame payload has this format: |
| 170 | |
| 171 | 0 2 4 |
| 172 | +----------+-----------+-------------- - - |
| 173 | | class-id | method-id | arguments... |
| 174 | +----------+-----------+-------------- - - |
| 175 | short short ... |
| 176 | |
| 177 | */ |
| 178 | func ReadMethod(reader io.Reader, protoVersion string) (Method, error) { |
| 179 | classID, err := ReadShort(reader) |
| 180 | if err != nil { |
| 181 | return nil, err |
| 182 | } |
| 183 | |
| 184 | methodID, err := ReadShort(reader) |
| 185 | if err != nil { |
| 186 | return nil, err |
| 187 | } |
| 188 | switch classID { |
| 189 | {{range .}} |
| 190 | case {{.ID}}: |
| 191 | switch methodID { |
| 192 | {{range .Methods}} |
| 193 | case {{.ID}}: |
| 194 | var method = &{{.GoName}}{} |
| 195 | if err := method.Read(reader, protoVersion); err != nil { |
| 196 | return nil, err |
| 197 | } |
| 198 | return method, nil{{end}} |
| 199 | }{{end}} |
| 200 | } |
| 201 | |
| 202 | return nil, fmt.Errorf("unknown classID and methodID: [%d. %d]", classID, methodID) |
| 203 | } |
| 204 | |
| 205 | // WriteMethod writes method into frame's payload |
| 206 | func WriteMethod(writer io.Writer, method Method, protoVersion string) (err error) { |
| 207 | if err = WriteShort(writer, method.ClassIdentifier()); err != nil { |
| 208 | return err |
| 209 | } |
| 210 | if err = WriteShort(writer, method.MethodIdentifier()); err != nil { |
| 211 | return err |
| 212 | } |
| 213 | |
| 214 | if err = method.Write(writer, protoVersion); err != nil { |
| 215 | return err |
| 216 | } |
| 217 | |
| 218 | return |
| 219 | } |
| 220 | ` |
| 221 | return templatescip-go gomod github.com/golang/go/src go1.12 `text/template`/.Mustscip-go gomod github.com/golang/go/src go1.12 `text/template`/Must().(templatescip-go gomod github.com/golang/go/src go1.12 `text/template`/.Newscip-go gomod github.com/golang/go/src go1.12 `text/template`/New().("methodsTemplate").Parsescip-go gomod github.com/golang/go/src go1.12 `text/template`/Template#Parse().(methodsTemplate)) |
| 222 | } |