using System;
using System.Collections.Generic;
-using System.Linq;
+using System.IO;
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
///
return prefix;
}
}
+
+ public static ulong ReadVarInt(ref BinaryReader reader)
+ {
+ byte prefix = reader.ReadByte();
+
+ switch (prefix)
+ {
+ case 0xfd: // ushort
+ return reader.ReadUInt16();
+ case 0xfe: // uint
+ return reader.ReadUInt32();
+ case 0xff: // ulong
+ return reader.ReadUInt64();
+ default:
+ return prefix;
+ }
+ }
+
}
}