| 1287 | } |
| 1288 | |
| 1289 | static bool GetDataTableWriteDataDB(lua_State *L, vector<std::shared_ptr<std::vector<uint8_t>>> &ret) { |
| 1290 | //取写数据库的key value |
| 1291 | if (!lua_istable(L, -1)) { |
| 1292 | LogPrint(BCLog::LUAVM, "GetDataTableWriteDataDB is not table\n"); |
| 1293 | return false; |
| 1294 | } |
| 1295 | uint16_t len = 0; |
| 1296 | vector<uint8_t> vBuf; |
| 1297 | //取key |
| 1298 | string key = ""; |
| 1299 | if (!(getStringInTable(L, (char *)"key", key))) { |
| 1300 | LogPrint(BCLog::LUAVM, "key get fail\n"); |
| 1301 | return false; |
| 1302 | } else { |
| 1303 | // LogPrint(BCLog::LUAVM, "key:%s\n", key); |
| 1304 | } |
| 1305 | vBuf.clear(); |
| 1306 | for (size_t i = 0; i < key.size(); i++) { |
| 1307 | vBuf.insert(vBuf.end(), key.at(i)); |
| 1308 | } |
| 1309 | ret.insert(ret.end(), std::make_shared<vector<uint8_t>>(vBuf.begin(), vBuf.end())); |
| 1310 | |
| 1311 | //取value的长度 |
| 1312 | double doubleValue = 0; |
| 1313 | if (!(getNumberInTable(L, (char *)"length", doubleValue))) { |
| 1314 | LogPrint(BCLog::LUAVM, "length get fail\n"); |
| 1315 | return false; |
| 1316 | } else { |
| 1317 | len = (uint16_t)doubleValue; |
| 1318 | // LogPrint(BCLog::LUAVM, "len =%d\n", len); |
| 1319 | } |
| 1320 | if ((len > 0) && (len <= LUA_C_BUFFER_SIZE)) { |
| 1321 | if (!getArrayInTable(L, (char *)"value", len, vBuf)) { |
| 1322 | LogPrint(BCLog::LUAVM, "value is not table\n"); |
| 1323 | return false; |
| 1324 | } else { |
| 1325 | // LogPrint(BCLog::LUAVM, "value:%s\n", HexStr(vBuf).c_str()); |
| 1326 | ret.insert(ret.end(), std::make_shared<vector<uint8_t>>(vBuf.begin(), vBuf.end())); |
| 1327 | } |
| 1328 | return true; |
| 1329 | } else { |
| 1330 | LogPrint(BCLog::LUAVM, "len overflow\n"); |
| 1331 | return false; |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | /** |
| 1336 | *bool WriteDataDB(const void* const key,const uint8_t keylen,const void * const value,const uint16_t valuelen,const uint32_t time) |
no test coverage detected