From: CryptoManiac Date: Fri, 28 Aug 2015 22:26:12 +0000 (+0300) Subject: VarInt: new GetEncodedSize() method X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=0c95b16ee0998f78aa504cb5a03a850cb7bb8241 VarInt: new GetEncodedSize() method --- diff --git a/Novacoin/VarInt.cs b/Novacoin/VarInt.cs index d376cae..e78d107 100644 --- a/Novacoin/VarInt.cs +++ b/Novacoin/VarInt.cs @@ -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; + } + } + /// /// Decodes integer value from compact representation ///