From fa2e8fa1122c3f2400ab8f178bd9285a9ed50019 Mon Sep 17 00:00:00 2001 From: Eitam Date: Tue, 22 Feb 2022 19:11:30 +0200 Subject: [PATCH] Added covert to string interface if needed --- replication/row_event.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/replication/row_event.go b/replication/row_event.go index 1729aefb7..a6ffd7611 100644 --- a/replication/row_event.go +++ b/replication/row_event.go @@ -1141,6 +1141,10 @@ func (e *RowsEvent) decodeValue(data []byte, tp byte, meta uint16) (v interface{ v, err = littleDecodeBit(data, nbits, n) case MYSQL_TYPE_BLOB: v, n, err = decodeBlob(data, meta) + newValue, ok := convertToString(v) + if ok { + v = newValue + } case MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VAR_STRING: length = int(meta) @@ -1152,6 +1156,10 @@ func (e *RowsEvent) decodeValue(data []byte, tp byte, meta uint16) (v interface{ length = int(FixedLengthInt(data[0:meta])) n = length + int(meta) v, err = e.decodeJsonBinary(data[meta:n]) + newValue, ok := convertToString(v) + if ok { + v = newValue + } case MYSQL_TYPE_GEOMETRY: // MySQL saves Geometry as Blob in binlog // Seem that the binary format is SRID (4 bytes) + WKB, outer can use @@ -1167,6 +1175,20 @@ func (e *RowsEvent) decodeValue(data []byte, tp byte, meta uint16) (v interface{ return v, n, err } +// convertToString receive an interface and convert it to string if match the desired type +func convertToString(s interface{}) (string, bool) { + if s == nil { + return "", false + } + switch v := s.(type) { + case []uint8: + str := string(v) + return str, true + default: + return "", false + } +} + func decodeString(data []byte, length int) (v string, n int) { if length < 256 { length = int(data[0])