Import varintDecode from BFGMiner

This commit is contained in:
Huang Le 2014-08-15 15:37:46 +08:00 committed by Luke Dashjr
parent a1dbe722fa
commit 74e674632e
2 changed files with 27 additions and 0 deletions

View File

@ -1,2 +1,3 @@
Luke Dashjr <luke_libblkmaker@dashjr.org>
Andy Alness <andy.alness@gmail.com>
Huang Le <4tarhl@gmail.com>

View File

@ -47,6 +47,32 @@ bool _blkmk_dblsha256(void *hash, const void *data, size_t datasz) {
#define dblsha256 _blkmk_dblsha256
static
size_t varintDecode(const uint8_t *p, size_t size, uint64_t *n)
{
if (size > 8 && p[0] == 0xff)
{
*n = upk_u64le(p, 1);
return 9;
}
if (size > 4 && p[0] == 0xfe)
{
*n = upk_u32le(p, 1);
return 5;
}
if (size > 2 && p[0] == 0xfd)
{
*n = upk_u16le(p, 1);
return 3;
}
if (size > 0 && p[0] <= 0xfc)
{
*n = p[0];
return 1;
}
return 0;
}
static
char varintEncode(unsigned char *out, uint64_t n) {
if (n < 0xfd)