1
0
mirror of https://github.com/xmrig/xmrig.git synced 2025-12-26 06:00:00 -05:00

Update Coin, BlobReader and WalletAddress.

This commit is contained in:
XMRig
2021-08-17 08:17:21 +07:00
parent 9eac9dd30a
commit d1033abbe5
8 changed files with 369 additions and 165 deletions

View File

@@ -1,8 +1,8 @@
/* XMRig
* Copyright 2012-2013 The Cryptonote developers
* Copyright 2014-2021 The Monero Project
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2012-2013 The Cryptonote developers
* Copyright (c) 2014-2021 The Monero Project
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,58 +23,71 @@
#include <cstdint>
#include <cstring>
namespace xmrig {
class CBlobReader
class BlobReader
{
public:
inline CBlobReader(const void* data, size_t size)
: m_data(reinterpret_cast<const uint8_t*>(data))
, m_size(size)
, m_index(0)
inline BlobReader(const uint8_t *data, size_t size) :
m_size(size),
m_data(data)
{}
inline bool operator()(uint8_t& data) { return getByte(data); }
inline bool operator()(uint64_t& data) { return getVarint(data); }
inline bool operator()(uint64_t &data) { return getVarint(data); }
inline bool operator()(uint8_t &data) { return getByte(data); }
inline size_t index() const { return m_index; }
inline size_t remaining() const { return m_size - m_index; }
inline bool skip(size_t n)
{
if (m_index + n > m_size) {
return false;
}
m_index += n;
return true;
}
template<size_t N>
inline bool operator()(uint8_t(&data)[N])
{
for (size_t i = 0; i < N; ++i) {
if (!getByte(data[i])) {
return false;
}
if (m_index + N > m_size) {
return false;
}
memcpy(data, m_data + m_index, N);
m_index += N;
return true;
}
template<typename T>
inline void readItems(T& data, size_t count)
inline void readItems(T &data, size_t count)
{
data.resize(count);
for (size_t i = 0; i < count; ++i)
for (size_t i = 0; i < count; ++i) {
operator()(data[i]);
}
}
inline size_t index() const { return m_index; }
inline void skip(size_t N) { m_index += N; }
private:
inline bool getByte(uint8_t& data)
inline bool getByte(uint8_t &data)
{
if (m_index >= m_size) {
return false;
}
data = m_data[m_index++];
return true;
}
inline bool getVarint(uint64_t& data)
inline bool getVarint(uint64_t &data)
{
uint64_t result = 0;
uint8_t t;
@@ -89,12 +102,13 @@ private:
} while (t & 0x80);
data = result;
return true;
}
const uint8_t* m_data;
size_t m_size;
size_t m_index;
const size_t m_size;
const uint8_t *m_data;
size_t m_index = 0;
};