1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.tikv.common.apiversion;
19
20 import com.google.protobuf.ByteString;
21 import org.tikv.common.util.Pair;
22 import org.tikv.kvproto.Metapb;
23
24 public class RequestKeyV1TxnCodec extends RequestKeyV1Codec implements RequestKeyCodec {
25 public RequestKeyV1TxnCodec() {}
26
27 @Override
28 public ByteString encodePdQuery(ByteString key) {
29 return CodecUtils.encode(key);
30 }
31
32 @Override
33 public Pair<ByteString, ByteString> encodePdQueryRange(ByteString start, ByteString end) {
34 if (!start.isEmpty()) {
35 start = CodecUtils.encode(start);
36 }
37
38 if (!end.isEmpty()) {
39 end = CodecUtils.encode(end);
40 }
41
42 return Pair.create(start, end);
43 }
44
45 @Override
46 public Metapb.Region decodeRegion(Metapb.Region region) {
47 Metapb.Region.Builder builder = Metapb.Region.newBuilder().mergeFrom(region);
48 ByteString start = region.getStartKey();
49 ByteString end = region.getEndKey();
50
51 if (!start.isEmpty()) {
52 start = CodecUtils.decode(start);
53 }
54
55 if (!end.isEmpty()) {
56 end = CodecUtils.decode(end);
57 }
58
59 return builder.setStartKey(start).setEndKey(end).build();
60 }
61 }