Encode encodes the temp index value.
(buf []byte)
| 1401 | |
| 1402 | // Encode encodes the temp index value. |
| 1403 | func (v *TempIndexValueElem) Encode(buf []byte) []byte { |
| 1404 | if v.Delete { |
| 1405 | if v.Distinct { |
| 1406 | handle := v.Handle |
| 1407 | var hEncoded []byte |
| 1408 | var hLen uint16 |
| 1409 | if handle.IsInt() { |
| 1410 | hEncoded = codec.EncodeUint(hEncoded, uint64(handle.IntValue())) |
| 1411 | hLen = 8 |
| 1412 | } else { |
| 1413 | hEncoded = handle.Encoded() |
| 1414 | hLen = uint16(len(hEncoded)) |
| 1415 | } |
| 1416 | // flag + handle length + handle + [partition id] + temp key version |
| 1417 | if buf == nil { |
| 1418 | l := hLen + 4 |
| 1419 | if v.Global { |
| 1420 | l += 9 |
| 1421 | } |
| 1422 | buf = make([]byte, 0, l) |
| 1423 | } |
| 1424 | buf = append(buf, byte(TempIndexValueFlagDeleted)) |
| 1425 | buf = append(buf, byte(hLen>>8), byte(hLen)) |
| 1426 | buf = append(buf, hEncoded...) |
| 1427 | if v.Global { |
| 1428 | buf = append(buf, TempIndexKeyTypePartitionIDFlag) |
| 1429 | buf = append(buf, codec.EncodeInt(nil, v.Handle.(kv.PartitionHandle).PartitionID)...) |
| 1430 | } |
| 1431 | buf = append(buf, v.KeyVer) |
| 1432 | return buf |
| 1433 | } |
| 1434 | // flag + temp key version |
| 1435 | if buf == nil { |
| 1436 | buf = make([]byte, 0, 2) |
| 1437 | } |
| 1438 | buf = append(buf, byte(TempIndexValueFlagNonDistinctDeleted)) |
| 1439 | buf = append(buf, v.KeyVer) |
| 1440 | return buf |
| 1441 | } |
| 1442 | if v.Distinct { |
| 1443 | // flag + value length + value + temp key version |
| 1444 | if buf == nil { |
| 1445 | buf = make([]byte, 0, len(v.Value)+4) |
| 1446 | } |
| 1447 | buf = append(buf, byte(TempIndexValueFlagNormal)) |
| 1448 | vLen := uint16(len(v.Value)) |
| 1449 | buf = append(buf, byte(vLen>>8), byte(vLen)) |
| 1450 | buf = append(buf, v.Value...) |
| 1451 | buf = append(buf, v.KeyVer) |
| 1452 | return buf |
| 1453 | } |
| 1454 | // flag + value + temp key version |
| 1455 | if buf == nil { |
| 1456 | buf = make([]byte, 0, len(v.Value)+2) |
| 1457 | } |
| 1458 | buf = append(buf, byte(TempIndexValueFlagNonDistinctNormal)) |
| 1459 | buf = append(buf, v.Value...) |
| 1460 | buf = append(buf, v.KeyVer) |