//CFTTSerialize - [2020-04-13 11:57:46]
#ifndef _CFTTSERIALIZE_H_
#define _CFTTSERIALIZE_H_

#include "CFTTFile.h"

/*
002680D8 CFTTSerialize::CFTTSerialize(CFTTFile *,int,int,bool,bool)
00268140 CFTTSerialize::~CFTTSerialize()
00268158 CFTTSerialize::Finish(bool)
002681C2 CFTTSerialize::SerializeTime_t(long *,int)

001CC740 CFTTSerialize::SerializeArray<(EFTTSerializeSize)1,bool,44>(bool (&)[44],int)
001CC75E CFTTSerialize::SerializeArray<(EFTTSerializeSize)1,bool,68>(bool (&)[68],int)
001CC77C CFTTSerialize::SerializeArray<(EFTTSerializeSize)1,bool,69>(bool (&)[69],int)
001CC79A CFTTSerialize::SerializeArray<(EFTTSerializeSize)1,bool,81>(bool (&)[81],int)
001CC7B8 CFTTSerialize::SerializeArray<(EFTTSerializeSize)1,bool,82>(bool (&)[82],int)
001CC7D6 CFTTSerialize::SerializeArray<(EFTTSerializeSize)1,bool,87>(bool (&)[87],int)
001CC7F4 CFTTSerialize::SerializeArray<(EFTTSerializeSize)1,bool,16>(bool (&)[16],int)
001CC812 CFTTSerialize::SerializeArray<(EFTTSerializeSize)4,int,3>(int (&)[3],int)
001CC830 CFTTSerialize::SerializeArray<(EFTTSerializeSize)4,int,5>(int (&)[5],int)
001CCB3A CFTTSerialize::SerializeArray<(EFTTSerializeSize)2,wchar_t,128>(wchar_t (&)[128],int)
001CCB5A CFTTSerialize::SerializeArray<(EFTTSerializeSize)4,int,8>(int (&)[8],int)
001CCB78 CFTTSerialize::SerializeArray<(EFTTSerializeSize)1,char,64>(char (&)[64],int)
001CCB96 CFTTSerialize::SerializeArray<(EFTTSerializeSize)1,char,128>(char (&)[128],int)
001CF3EA CFTTSerialize::SerializeArray<(EFTTSerializeSize)2,wchar_t,64>(wchar_t (&)[64],int)
001E16C8 CFTTSerialize::SerializeArray<(EFTTSerializeSize)2,ushort,38>(ushort (&)[38],int)
001E16E6 CFTTSerialize::SerializeArray<(EFTTSerializeSize)2,ushort,75>(ushort (&)[75],int)
001E1704 CFTTSerialize::SerializeArray<(EFTTSerializeSize)2,ushort,10>(ushort (&)[10],int)
001E1722 CFTTSerialize::SerializeArray<(EFTTSerializeSize)2,wchar_t,17>(wchar_t (&)[17],int)
001E756E CFTTSerialize::SerializeArray<(EFTTSerializeSize)2,ushort,16>(ushort (&)[16],int)
001E758C CFTTSerialize::SerializeArray<(EFTTSerializeSize)2,ushort,39>(ushort (&)[39],int)
0026FF88 CFTTSerialize::SerializeArray<(EFTTSerializeSize)4,uint,8>(uint (&)[8],int)

0011B978 CFTTSerialize::SerializeInternal<ushort>(ushort *,int)
0011BA06 CFTTSerialize::SerializeInternal<uchar>(uchar *,int)
0011BA9A CFTTSerialize::SerializeInternal<signed char>(signed char *,int)
001CEDD0 CFTTSerialize::SerializeInternal<bool>(bool *,int)
001CEE64 CFTTSerialize::SerializeInternal<uint>(uint *,int)
001CEEF6 CFTTSerialize::SerializeInternal<int>(int *,int)
001CEF88 CFTTSerialize::SerializeInternal<float>(float *,int)
001CF01A CFTTSerialize::SerializeInternal<EUserType>(EUserType *,int)
001CF0AC CFTTSerialize::SerializeInternal<EUserABTest>(EUserABTest *,int)
001CF13E CFTTSerialize::SerializeInternal<wchar_t>(wchar_t *,int)
001CF1CC CFTTSerialize::SerializeInternal<char>(char *,int)
001E83C4 CFTTSerialize::SerializeInternal<uint64_t>(uint64_t *,int)
001E845A CFTTSerialize::SerializeInternal<ESyncState>(ESyncState *,int)
001EA3C8 CFTTSerialize::SerializeInternal<short>(short *,int)
001EC6D8 CFTTSerialize::SerializeInternal<EStageOperation>(EStageOperation *,int)
001EC76A CFTTSerialize::SerializeInternal<ELeague>(ELeague *,int)
001EC7FC CFTTSerialize::SerializeInternal<ECharModelType>(ECharModelType *,int)
002681F6 CFTTSerialize::SerializeInternal<long long>(long long *,int)


0x28


调用方法
uchar dd[10];
CFTTSerialize pp(nullptr, 10, 10, false, false);
pp.SerializeArray<EFTTSerializeSize::size_char, uchar, 10>(dd, 8);
*/

enum EFTTSerializeSize {
  size_char = 1,
  size_wchar = 2,
  size_int = 4,
  size_float = 4,
  size_longlong = 8
};

//template <EFTTSerializeSize d, class T, int len>
class CFTTSerialize {
public:
  CFTTSerialize(CFTTFile *pFile, int a3, int a4, bool isWrite, bool isAutoDelFile);  //002680D8
  ~CFTTSerialize();                                                                  //00268140
  int Finish(bool);                                                                  //00268158
  void SerializeTime_t(long *, int);                                                 //002681C2

  template <EFTTSerializeSize d, typename T, int dCount>
  void SerializeArray(T (&a2)[dCount], int a3) {
    for (int i = 0; i != dCount; i++) {
      SerializeInternal<T>(a2 + i, a3);
    }
  };

  template <typename T>
  void SerializeInternal(T *pDat, int len) {
    //LOGI("CFTTSerialize::SerializeInternal entry");
    uint64 dcount = 0;
    if (bIsWrite_1C) {
      //0011BA10
      dcount = pFile_0->Write(pDat, sizeof(T));
    } else {
      //loc_11BA1A
      if (field_18 < len)
        return;
      dcount = pFile_0->Read(pDat, sizeof(T));
    }
    //0011BA32
    //001EA3F0
    bErr_1E |= (dcount != sizeof(T));  //设置错误码

    T dr1_tmp = *pDat;  //0011BA4C
    int64 d1_64 = (int64)dr1_tmp;
    i64_8 = (i64_8 >> 5) ^ (i64_8 << 7) ^ d1_64;

    uint dr3;
    uchar *pr4_uchar = reinterpret_cast<uchar *>(pDat);
    for (int dr6 = 0; dr6 != sizeof(T) * 8; dr6 += 8) {  //loc_11BA00 ushort 2
      //loc_11B9D4
      uchar cr0 = *pr4_uchar;

      if constexpr (sizeof(T) == 1) {
        field_10 ^= cr0;
      } else if (sizeof(T) == 2) {
        cr0 = cr0 << dr6;
        field_10 ^= cr0;
      } else if (sizeof(T) >= 4) {
        dr3 = dr6 & 24;
        cr0 = cr0 << dr3;
        field_10 ^= cr0;
      }

      cr0 = *pr4_uchar;  //0011B9E0   LDRB.W R0, [R4],#1
      pr4_uchar++;
      short_14 = (cr0 + short_14) % 0xFFF1;
      short_16 = (short_14 + short_16) % 0xFFF1;
    }
  };

  CFTTFile *pFile_0;
  int field_4;
  int64 i64_8;
  uint32_t field_10;
  uint16_t short_14;
  uint16_t short_16;
  int field_18;
  bool bIsWrite_1C;
  uint8 byte_1D;
  uint8 bErr_1E;  //byte_1E;
  uint8 byte_1F;
  bool isAutoDelFile_20;  //是否在解构时自动删除 pFile_0
  int field_24;
};

#endif  //_CFTTSERIALIZE_H_