func (txn *Txn) populate(actionIndices capn.UInt16List, actions msgs.Action_List) { localActions := make([]localAction, actionIndices.Len()) txn.localActions = localActions var action *localAction actionIndicesIdx := 0 actionIndex := -1 if actionIndicesIdx < actionIndices.Len() { actionIndex = int(actionIndices.At(actionIndicesIdx)) action = &localActions[actionIndicesIdx] } for idx, l := 0, actions.Len(); idx < l; idx++ { actionCap := actions.At(idx) if idx == actionIndex { action.Txn = txn action.vUUId = common.MakeVarUUId(actionCap.VarId()) } switch actionCap.Which() { case msgs.ACTION_READ: if idx == actionIndex { readCap := actionCap.Read() readVsn := common.MakeTxnId(readCap.Version()) action.readVsn = readVsn } case msgs.ACTION_WRITE: if idx == actionIndex { action.writeTxnActions = &actions action.writeAction = &actionCap txn.writes = append(txn.writes, action.vUUId) } else { txn.writes = append(txn.writes, common.MakeVarUUId(actionCap.VarId())) } case msgs.ACTION_READWRITE: if idx == actionIndex { readWriteCap := actionCap.Readwrite() readVsn := common.MakeTxnId(readWriteCap.Version()) action.readVsn = readVsn action.writeTxnActions = &actions action.writeAction = &actionCap txn.writes = append(txn.writes, action.vUUId) } else { txn.writes = append(txn.writes, common.MakeVarUUId(actionCap.VarId())) } case msgs.ACTION_CREATE: if idx == actionIndex { createCap := actionCap.Create() positions := common.Positions(createCap.Positions()) action.writeTxnActions = &actions action.writeAction = &actionCap action.createPositions = &positions txn.writes = append(txn.writes, action.vUUId) } else { txn.writes = append(txn.writes, common.MakeVarUUId(actionCap.VarId())) } case msgs.ACTION_ROLL: if idx == actionIndex { rollCap := actionCap.Roll() readVsn := common.MakeTxnId(rollCap.Version()) action.readVsn = readVsn action.writeTxnActions = &actions action.writeAction = &actionCap action.roll = true txn.writes = append(txn.writes, action.vUUId) } else { txn.writes = append(txn.writes, common.MakeVarUUId(actionCap.VarId())) } default: panic(fmt.Sprintf("Unexpected action type: %v", actionCap.Which())) } if idx == actionIndex { actionIndicesIdx++ if actionIndicesIdx < actionIndices.Len() { actionIndex = int(actionIndices.At(actionIndicesIdx)) action = &localActions[actionIndicesIdx] } } } if actionIndicesIdx != actionIndices.Len() { panic(fmt.Sprintf("Expected to find %v local actions, but only found %v", actionIndices.Len(), actionIndicesIdx)) } }