buildCommandCallEncodeFuncs builds the encode() method for the each API command call (for commands that don't return void). encode() will call gapil_encode_type() with the state type before encoding the proto message with gapil_encode_object.
()
| 292 | // encode() will call gapil_encode_type() with the state type before encoding |
| 293 | // the proto message with gapil_encode_object. |
| 294 | func (e *encoder) buildCommandCallEncodeFuncs() { |
| 295 | for _, api := range e.APIs { |
| 296 | for _, cmd := range api.Functions { |
| 297 | if cmd.Return.Type == semantic.VoidType { |
| 298 | continue |
| 299 | } |
| 300 | mgCmd := &mangling.Namespace{Name: "cmd", Parent: e.Root} |
| 301 | mgClass := &mangling.Class{Name: cmd.Name() + "Call", Parent: mgCmd} |
| 302 | mgEncode := e.mgEncode(mgClass) |
| 303 | |
| 304 | fields := []codegen.Field{{Name: "result", Type: e.T.Target(cmd.Return.Type)}} |
| 305 | thisTy := e.T.Pointer(e.T.Struct(cmd.Name()+"_call", fields...)) |
| 306 | |
| 307 | e.C.Build(e.M.Function( |
| 308 | e.T.VoidPtr, |
| 309 | e.Mangler(mgEncode), |
| 310 | thisTy, e.T.CtxPtr, e.T.Bool), func(s *compiler.S) { |
| 311 | |
| 312 | this, isGroup := s.Parameter(0), s.Parameter(2) |
| 313 | |
| 314 | e.debug(s, "encoding command call: '"+cmd.Name()+"' this: %p, ctx: %p", this, s.Ctx) |
| 315 | |
| 316 | typeID := s.Call(e.entities.funcCalls[cmd].encodeType, s.Ctx) |
| 317 | |
| 318 | buf, delBuf := e.newBuf(s) |
| 319 | |
| 320 | resultPtr := this.Index(0, "result") |
| 321 | e.encodeField(s, resultPtr, buf, serialization.CmdResult, cmd.Return.Type) |
| 322 | |
| 323 | bufOffset := buf.Index(0, compiler.BufSize).Load() |
| 324 | bufData := buf.Index(0, compiler.BufData).Load() |
| 325 | out := s.Call(e.callbacks.encodeObject, s.Ctx, isGroup.Cast(e.T.Uint8), typeID, bufOffset, bufData) |
| 326 | |
| 327 | delBuf() |
| 328 | |
| 329 | s.Return(out) |
| 330 | }) |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | // newBuf creates and returns a pointer to a new buffer stored on the stack |
| 336 | // along with a function that will release the buffer's data. |
no test coverage detected