mrDarker
6 天以前 829fe6c6bc33d53fda9c31fd45a37e1df87befff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "stdafx.h"
#include "CSVData.h"
#include "ToolUnits.h"
 
 
namespace SERVO {
    CSVData::CSVData()
    {
 
    }
 
    CSVData::~CSVData()
    {
 
    }
 
    std::string& CSVData::getTime()
    {
        return m_strTime;
    }
 
    std::vector<uint8_t>& CSVData::getSVRawData()
    {
        return m_svRawData;
    }
 
    int CSVData::serialize(char* pszBuffer, int nBufferSize)
    {
        if (nBufferSize < 133 * 2) return -1;
 
        int index = 0;
        CToolUnits::convertString(&pszBuffer[index], 8 * 2, m_strTime);
        index += 8 * 2;
 
        memcpy(&pszBuffer[index], m_svRawData.data(), 125 * 2);
        index += 125 * 2;
 
        return 133 * 2;
    }
 
    int CSVData::unserialize(const char* pszBuffer, int nBufferSize)
    {
        if (pszBuffer == nullptr) return -1;
        if (nBufferSize < 133 * 2) return -1;
 
        int index = 0;
        CToolUnits::convertString(&pszBuffer[index], 8 * 2, m_strTime);
        index += 8 * 2;
 
        m_svRawData.clear();
        if (nBufferSize < index + 125 * 2) return -1;
        m_svRawData.insert(
            m_svRawData.end(),
            (const uint8_t*)&pszBuffer[index],
            (const uint8_t*)&pszBuffer[index + 125 * 2]);
        index += 125 * 2;
 
        return 133 * 2;
    }
}