From 2f12207dbed0cbf35751f8f1b11cbf5c930370e5 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Fri, 30 Nov 2018 11:17:59 +0100 Subject: [PATCH] Add ReadDecimal helper --- binlog/event_rows.go | 4 +--- buffer/buffer.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/binlog/event_rows.go b/binlog/event_rows.go index d69f9c3..91c5f8a 100644 --- a/binlog/event_rows.go +++ b/binlog/event_rows.go @@ -174,9 +174,7 @@ func (e *RowsEvent) decodeValue(buf *buffer.Buffer, ct mysql.ColumnType, meta ui case mysql.ColumnTypeNewDecimal: precision := int(meta >> 8) decimals := int(meta & 0xFF) - dec, n := mysql.DecodeDecimal(buf.Cur(), precision, decimals) - buf.Skip(n) - return dec + return buf.ReadDecimal(precision, decimals) // Date and Time case mysql.ColumnTypeYear: diff --git a/buffer/buffer.go b/buffer/buffer.go index dd1676b..a92af6d 100644 --- a/buffer/buffer.go +++ b/buffer/buffer.go @@ -170,3 +170,15 @@ func (b *Buffer) WriteStringLenEnc(s string) { func (b *Buffer) WriteStringEOF(s string) { b.pos += copy(b.data[b.pos:], s) } + +// +// Special types +// + +// ReadDecimal decodes a decimal value from the buffer anf then advances cursor +// accordingly. +func (b *Buffer) ReadDecimal(precision, decimals int) mysql.Decimal { + dec, n := mysql.DecodeDecimal(b.Cur(), precision, decimals) + b.Skip(n) + return dec +}