buildStateEncodeFunc builds the encode() method for each API state object. encode() will call gapil_encode_type() with the state type before encoding the proto message with gapil_encode_object.
()
| 195 | // encode() will call gapil_encode_type() with the state type before encoding |
| 196 | // the proto message with gapil_encode_object. |
| 197 | func (e *encoder) buildStateEncodeFunc() { |
| 198 | for _, api := range e.APIs { |
| 199 | mgState := &mangling.Class{ |
| 200 | Parent: e.Root, |
| 201 | Name: cases.Title(api.Name()) + "State", |
| 202 | } |
| 203 | |
| 204 | stateTy := e.T.Globals.Field(api.Name()).Type |
| 205 | statePtr := e.T.Pointer(stateTy) |
| 206 | |
| 207 | mgEncode := e.mgEncode(mgState) |
| 208 | e.C.Build(e.M.Function( |
| 209 | e.T.VoidPtr, |
| 210 | e.Mangler(mgEncode), |
| 211 | statePtr, e.T.CtxPtr, e.T.Bool), func(s *compiler.S) { |
| 212 | |
| 213 | this, isGroup := s.Parameter(0), s.Parameter(2) |
| 214 | |
| 215 | e.debug(s, "encoding "+api.Name()+" state: this: %p, ctx: %p", this, s.Ctx) |
| 216 | |
| 217 | typeID := s.Call(e.entities.state[api].encodeType, s.Ctx) |
| 218 | |
| 219 | buf, delBuf := e.newBuf(s) |
| 220 | |
| 221 | for i, g := range encodeableGlobals(api) { |
| 222 | e.debug(s, "encoding "+api.Name()+" global '"+g.Name()+"'") |
| 223 | ptr := this.Index(0, g.Name()) |
| 224 | e.encodeField(s, ptr, buf, serialization.StateStart+serialization.ProtoFieldID(i), g.Type) |
| 225 | } |
| 226 | |
| 227 | bufOffset := buf.Index(0, compiler.BufSize).Load() |
| 228 | bufData := buf.Index(0, compiler.BufData).Load() |
| 229 | out := s.Call(e.callbacks.encodeObject, s.Ctx, isGroup.Cast(e.T.Uint8), typeID, bufOffset, bufData) |
| 230 | |
| 231 | delBuf() |
| 232 | |
| 233 | s.Return(out) |
| 234 | }) |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // buildCommandEncodeFuncs builds the encode() method for the each API command |
| 239 | // and the API command call (if they don't return void). |
no test coverage detected