Skip to content

Commit 83965e5

Browse files
authored
Merge pull request #599 from lance6716/fix-magic-9
use constant and add comment for magic number 9
2 parents d1b06d1 + 855f74a commit 83965e5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

replication/row_event.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,7 @@ func decodeString(data []byte, length int) (v string, n int) {
11721172
return
11731173
}
11741174

1175+
// ref: https://github.com/mysql/mysql-server/blob/a9b0c712de3509d8d08d3ba385d41a4df6348775/strings/decimal.c#L137
11751176
const digitsPerInteger int = 9
11761177

11771178
var compressedBytes = []int{0, 1, 1, 2, 2, 3, 3, 4, 4, 4}
@@ -1192,7 +1193,7 @@ func decodeDecimalDecompressValue(compIndx int, data []byte, mask uint8) (size i
11921193
return
11931194
}
11941195

1195-
var zeros = [9]byte{48, 48, 48, 48, 48, 48, 48, 48, 48}
1196+
var zeros = [digitsPerInteger]byte{48, 48, 48, 48, 48, 48, 48, 48, 48}
11961197

11971198
func decodeDecimal(data []byte, precision int, decimals int, useDecimal bool) (interface{}, int, error) {
11981199
//see python mysql replication and https://github.com/jeremycole/mysql_binlog
@@ -1244,7 +1245,7 @@ func decodeDecimal(data []byte, precision int, decimals int, useDecimal bool) (i
12441245
}
12451246
} else {
12461247
toWrite := strconv.FormatUint(uint64(value), 10)
1247-
res.Write(zeros[:9-len(toWrite)])
1248+
res.Write(zeros[:digitsPerInteger-len(toWrite)])
12481249
res.WriteString(toWrite)
12491250
}
12501251
}
@@ -1260,7 +1261,7 @@ func decodeDecimal(data []byte, precision int, decimals int, useDecimal bool) (i
12601261
value = binary.BigEndian.Uint32(data[pos:]) ^ mask
12611262
pos += 4
12621263
toWrite := strconv.FormatUint(uint64(value), 10)
1263-
res.Write(zeros[:9-len(toWrite)])
1264+
res.Write(zeros[:digitsPerInteger-len(toWrite)])
12641265
res.WriteString(toWrite)
12651266
}
12661267

0 commit comments

Comments
 (0)