summaryrefslogtreecommitdiff
path: root/sql-common
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2016-04-15 20:40:25 +0200
committerOleksandr Byelkin <sanja@mariadb.com>2016-08-31 17:17:46 +0200
commite7608a78ef45cc46f4e4d5abbda788ad54e80e71 (patch)
tree72d74018fbb72dcb417875399b2a3bd7bdbe7791 /sql-common
parent468a6ad722778768eb4ee5003dd818945b363261 (diff)
downloadmariadb-git-e7608a78ef45cc46f4e4d5abbda788ad54e80e71.tar.gz
MDEV-8931: (server part of) session state tracking
initial commit to test
Diffstat (limited to 'sql-common')
-rw-r--r--sql-common/pack.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/sql-common/pack.c b/sql-common/pack.c
index 4bb4a0b7a4e..5428feb623e 100644
--- a/sql-common/pack.c
+++ b/sql-common/pack.c
@@ -186,3 +186,25 @@ uchar *safe_net_store_length(uchar *packet, size_t packet_len, ulonglong length)
return packet+8;
}
+
+/**
+ The length of space required to store the resulting length-encoded integer
+ for the given number. This function can be used at places where one needs to
+ dynamically allocate the buffer for a given number to be stored as length-
+ encoded integer.
+
+ @param num [IN] the input number
+
+ @return length of buffer needed to store this number [1, 3, 4, 9].
+*/
+
+uint net_length_size(ulonglong num)
+{
+ if (num < (ulonglong) 251LL)
+ return 1;
+ if (num < (ulonglong) 65536LL)
+ return 3;
+ if (num < (ulonglong) 16777216LL)
+ return 4;
+ return 9;
+}