| 135 | } |
| 136 | |
| 137 | func IdOperation(op Operation, base *OpBase) entity.Id { |
| 138 | if base.id == "" { |
| 139 | // something went really wrong |
| 140 | panic("op's id not set") |
| 141 | } |
| 142 | if base.id == entity.UnsetId { |
| 143 | // This means we are trying to get the op's Id *before* it has been stored, for instance when |
| 144 | // adding multiple ops in one go in an OperationPack. |
| 145 | // As the Id is computed based on the actual bytes written on the disk, we are going to predict |
| 146 | // those and then get the Id. This is safe as it will be the exact same code writing on disk later. |
| 147 | |
| 148 | data, err := json.Marshal(op) |
| 149 | if err != nil { |
| 150 | panic(err) |
| 151 | } |
| 152 | |
| 153 | base.id = entity.DeriveId(data) |
| 154 | } |
| 155 | return base.id |
| 156 | } |
| 157 | |
| 158 | func (base *OpBase) Type() OperationType { |
| 159 | return base.OperationType |