@@ -139,12 +139,16 @@ public void encodeKeyV2(Buf buf, String data) {
139139 buf .ensureRemainder (1 );
140140 buf .write (NOTNULL );
141141
142- int size = internalEncodeKeyV2 (buf , data );
142+ byte [] decimalBin = s2bin (data );
143+ int size = internalEncodeKey (buf , decimalBin );
144+
143145 buf .ensureRemainder (4 );
144146 buf .reverseWriteInt (size );
145147 }
146148 } else {
147- int size = internalEncodeKeyV2 (buf , data );
149+ byte [] decimalBin = s2bin (data );
150+ int size = internalEncodeKey (buf , decimalBin );
151+
148152 buf .ensureRemainder (4 );
149153 buf .reverseWriteInt (size );
150154 }
@@ -161,6 +165,11 @@ private int internalEncodeKeyV2(Buf buf, String data) {
161165 return len ;
162166 }
163167
168+ private byte [] s2bin (String data ) {
169+ MyDecimal myDecimal = new MyDecimal (data , (int )this .precision , (int )this .scale );
170+ return myDecimal .toBin ();
171+ }
172+
164173 private int internalEncodeKey (Buf buf , byte [] data ) {
165174 int groupNum = data .length / 8 ;
166175 int size = (groupNum + 1 ) * 9 ;
@@ -213,14 +222,24 @@ public void encodeKeyForUpdateV2(Buf buf, String data) {
213222 buf .reverseWriteInt0 ();
214223 } else {
215224 buf .write (NOTNULL );
216- buf .reverseWriteInt (internalEncodeKeyV2 (buf , data ));
225+
226+ byte [] decimalBin = s2bin (data );
227+ int size = internalEncodeKey (buf , decimalBin );
228+
229+ buf .ensureRemainder (4 );
230+ buf .reverseWriteInt (size );
217231 }
218232 } else {
219233 if (data == null ) {
220234 throw new RuntimeException ("Data is not allow as null." );
221235 }
222236 buf .write (NOTNULL );
223- buf .reverseWriteInt (internalEncodeKeyV2 (buf , data ));
237+
238+ byte [] decimalBin = s2bin (data );
239+ int size = internalEncodeKey (buf , decimalBin );
240+
241+ buf .ensureRemainder (4 );
242+ buf .reverseWriteInt (size );
224243 }
225244 }
226245
@@ -273,7 +292,8 @@ public String decodeKeyV2(Buf buf) {
273292 }
274293 }
275294
276- return internalReadDecimal (buf );
295+ byte [] decBin = internalReadKeyPrefixBytes (buf );
296+ return new MyDecimal (decBin , (int )this .precision , (int )this .scale ).decimalToString ();
277297 }
278298
279299 //This interface is both used by v1 and v2. We use same way to decode key prefix.
@@ -282,15 +302,12 @@ public String decodeKeyV2(Buf buf) {
282302 public String decodeKeyPrefix (Buf buf ) {
283303 if (allowNull ) {
284304 if (buf .read () == NULL ) {
285- buf .reverseSkipInt ();
286305 return null ;
287306 }
288307 }
289308
290- //Forward skip codec version field.
291- //buf.reverseSkipInt();
292-
293- return internalReadDecimal (buf );
309+ byte [] decBin = internalReadKeyPrefixBytes (buf );
310+ return new MyDecimal (decBin , (int )this .precision , (int )this .scale ).decimalToString ();
294311 }
295312
296313 private byte [] internalReadKeyPrefixBytes (Buf buf ) {
@@ -379,14 +396,12 @@ public void encodeKeyPrefix(Buf buf, String data) {
379396 buf .ensureRemainder (1 );
380397 buf .write (NOTNULL );
381398
382- int size = internalEncodeKeyV2 (buf , data );
383- buf .ensureRemainder (4 );
384- buf .reverseWriteInt (size );
399+ byte [] decimalBin = s2bin (data );
400+ internalEncodeKey (buf , decimalBin );
385401 }
386402 } else {
387- int size = internalEncodeKeyV2 (buf , data );
388- buf .ensureRemainder (4 );
389- buf .reverseWriteInt (size );
403+ byte [] decimalBin = s2bin (data );
404+ internalEncodeKey (buf , decimalBin );
390405 }
391406 }
392407
0 commit comments