VarInt: new GetEncodedSize() method
authorCryptoManiac <balthazar@yandex.ru>
Fri, 28 Aug 2015 22:26:12 +0000 (01:26 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Fri, 28 Aug 2015 22:26:12 +0000 (01:26 +0300)
Novacoin/VarInt.cs

index d376cae..e78d107 100644 (file)
@@ -82,6 +82,26 @@ namespace Novacoin
             return EncodeVarInt((ulong)n);
         }
 
+        public static int GetEncodedSize(long n)
+        {
+            if (n <= 0xfc)
+            {
+                return 1;
+            }
+            else if (n <= ushort.MaxValue)
+            {
+                return 3;
+            }
+            else if (n <= uint.MaxValue)
+            {
+                return 5;
+            }
+            else
+            {
+                return 9;
+            }
+        }
+
         /// <summary>
         /// Decodes integer value from compact representation
         ///