Changeset 4949 in CLRX


Ignore:
Timestamp:
Sep 5, 2019, 5:26:14 PM (2 months ago)
Author:
matszpk
Message:

CLRadeonExtender: ROCmBin: Rename MsgPackStaticArrayWriter? to MsgPackArrayWriter?. Make MsgPackMapWriter? with static size.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • CLRadeonExtender/trunk/amdbin/ROCmMetadataMP.cpp

    r4948 r4949  
    10621062class CLRX_INTERNAL MsgPackMapWriter;
    10631063
    1064 class CLRX_INTERNAL MsgPackStaticArrayWriter
     1064class CLRX_INTERNAL MsgPackArrayWriter
    10651065{
    10661066private:
     
    10691069    size_t count;
    10701070public:
    1071     MsgPackStaticArrayWriter(size_t elemsNum, std::vector<cxbyte>& output);
     1071    MsgPackArrayWriter(size_t elemsNum, std::vector<cxbyte>& output);
    10721072   
    10731073    void putBool(bool b);
    10741074    void putString(const char* str);
    10751075    void putUInt(uint64_t v);
    1076     MsgPackStaticArrayWriter putStaticArray(size_t aelemsNum);
    1077     MsgPackMapWriter putMap();
     1076    MsgPackArrayWriter putArray(size_t aelemsNum);
     1077    MsgPackMapWriter putMap(size_t melemsNum);
    10781078    void flush();
    10791079};
     
    10841084    std::vector<cxbyte>& output;
    10851085    size_t elemsNum;
     1086    size_t count;
    10861087    bool inKey;
    1087     std::vector<cxbyte> temp;
    10881088public:
    1089     MsgPackMapWriter(std::vector<cxbyte>& output);
     1089    MsgPackMapWriter(size_t elemsNum, std::vector<cxbyte>& output);
    10901090    void putKeyString(const char* str);
    10911091    void putValueBool(bool b);
    10921092    void putValueString(const char* str);
    10931093    void putValueUInt(uint64_t v);
    1094     MsgPackStaticArrayWriter putValueStaticArray(size_t aelemsNum);
    1095     MsgPackMapWriter putValueMap();
     1094    MsgPackArrayWriter putValueArray(size_t aelemsNum);
     1095    MsgPackMapWriter putValueMap(size_t melemsNum);
    10961096    std::vector<cxbyte>& putValueElement();
    10971097    void flush();
    10981098};
    10991099
    1100 MsgPackStaticArrayWriter::MsgPackStaticArrayWriter(size_t _elemsNum,
     1100MsgPackArrayWriter::MsgPackArrayWriter(size_t _elemsNum,
    11011101            std::vector<cxbyte>& _output) : output(_output), elemsNum(_elemsNum), count(0)
    11021102{
     
    11221122}
    11231123
    1124 void MsgPackStaticArrayWriter::putBool(bool b)
     1124void MsgPackArrayWriter::putBool(bool b)
    11251125{
    11261126    if (count == elemsNum)
     
    11301130}
    11311131
    1132 void MsgPackStaticArrayWriter::putString(const char* str)
     1132void MsgPackArrayWriter::putString(const char* str)
    11331133{
    11341134    if (count == elemsNum)
     
    11381138}
    11391139
    1140 void MsgPackStaticArrayWriter::putUInt(uint64_t v)
     1140void MsgPackArrayWriter::putUInt(uint64_t v)
    11411141{
    11421142    if (count == elemsNum)
     
    11461146}
    11471147
    1148 MsgPackStaticArrayWriter MsgPackStaticArrayWriter::putStaticArray(size_t aelemsNum)
     1148MsgPackArrayWriter MsgPackArrayWriter::putArray(size_t aelemsNum)
    11491149{
    11501150    if (count == elemsNum)
    11511151        throw BinException("MsgPack: Too many array elements");
    11521152    count++;
    1153     return MsgPackStaticArrayWriter(aelemsNum, output);
    1154 }
    1155 
    1156 MsgPackMapWriter::MsgPackMapWriter(std::vector<cxbyte>& _output)
    1157         : output(_output), elemsNum(0), inKey(true)
    1158 { }
     1153    return MsgPackArrayWriter(aelemsNum, output);
     1154}
     1155
     1156MsgPackMapWriter MsgPackArrayWriter::putMap(size_t melemsNum)
     1157{
     1158    if (count == elemsNum)
     1159        throw BinException("MsgPack: Too many array elements");
     1160    count++;
     1161    return MsgPackMapWriter(melemsNum, output);
     1162}
     1163
     1164MsgPackMapWriter::MsgPackMapWriter(size_t _elemsNum, std::vector<cxbyte>& _output)
     1165        : output(_output), elemsNum(_elemsNum), count(0), inKey(true)
     1166{
     1167    if (elemsNum < 16)
     1168        output.push_back(0x80 + elemsNum);
     1169    else if (elemsNum < 0x10000U)
     1170    {
     1171        cxbyte d[3];
     1172        d[0] = 0xde;
     1173        d[1] = elemsNum>>8;
     1174        d[2] = elemsNum&0xff;
     1175        output.insert(output.end(), d, d+3);
     1176    }
     1177    else
     1178    {
     1179        cxbyte d[5];
     1180        d[0] = 0xdf;
     1181        uint32_t v2 = elemsNum;
     1182        for (cxuint i=5; i >= 0; i--, v2>>=8)
     1183            d[i] = v2&0xff;
     1184        output.insert(output.end(), d, d+3);
     1185    }
     1186}
    11591187
    11601188void MsgPackMapWriter::putKeyString(const char* str)
     
    11631191        throw BinException("MsgPack: Not in key value");
    11641192    inKey = false;
    1165     elemsNum++;
    1166     msgPackWriteString(str, temp);
     1193    if (count == elemsNum)
     1194        throw BinException("MsgPack: Too many map elements");
     1195    count++;
     1196    msgPackWriteString(str, output);
    11671197}
    11681198
     
    11721202        throw BinException("MsgPack: Not in value value");
    11731203    inKey = true;
    1174     msgPackWriteBool(b, temp);
     1204    msgPackWriteBool(b, output);
    11751205}
    11761206
     
    11801210        throw BinException("MsgPack: Not in value value");
    11811211    inKey = true;
    1182     msgPackWriteString(str, temp);
     1212    msgPackWriteString(str, output);
    11831213}
    11841214
     
    11881218        throw BinException("MsgPack: Not in value value");
    11891219    inKey = true;
    1190     msgPackWriteUInt(v, temp);
    1191 }
    1192 
    1193 MsgPackStaticArrayWriter MsgPackMapWriter::putValueStaticArray(size_t aelemsNum)
     1220    msgPackWriteUInt(v, output);
     1221}
     1222
     1223MsgPackArrayWriter MsgPackMapWriter::putValueArray(size_t aelemsNum)
    11941224{
    11951225    if (inKey)
    11961226        throw BinException("MsgPack: Not in value value");
    11971227    inKey = true;
    1198     return MsgPackStaticArrayWriter(aelemsNum, temp);
     1228    return MsgPackArrayWriter(aelemsNum, output);
    11991229}
    12001230
     
    12041234        throw BinException("MsgPack: Not in value value");
    12051235    inKey = true;
    1206     return temp;
    1207 }
    1208 
    1209 MsgPackMapWriter MsgPackMapWriter::putValueMap()
     1236    return output;
     1237}
     1238
     1239MsgPackMapWriter MsgPackMapWriter::putValueMap(size_t  melemsNum)
    12101240{
    12111241    if (inKey)
    12121242        throw BinException("MsgPack: Not in value value");
    12131243    inKey = true;
    1214     return MsgPackMapWriter(temp);
     1244    return MsgPackMapWriter(melemsNum, output);
    12151245}
    12161246
Note: See TracChangeset for help on using the changeset viewer.