int operator()() { js::mValue v; string s = asString(contents("../../tests/trietest.json")); js::read_string(s, v); bool passed = true; for (auto& i: v.get_obj()) { js::mObject& o = i.second.get_obj(); cnote << i.first; vector<pair<string, string>> ss; for (auto& i: o["in"].get_obj()) ss.push_back(make_pair(i.first, i.second.get_str())); for (unsigned j = 0; j < fac((unsigned)ss.size()); ++j) { next_permutation(ss.begin(), ss.end()); BasicMap m; GenericTrieDB<BasicMap> t(&m); t.init(); for (auto const& k: ss) t.insert(k.first, k.second); if (!o["root"].is_null() && o["root"].get_str() != asHex(t.root().asArray())) { cwarn << "Test failed on permutation " << j; cwarn << "Test says:" << o["root"].get_str(); cwarn << "Impl says:" << asHex(t.root().asArray()); passed = false; } } } return passed ? 0 : 1; }
bool Gsp1101::sendCabData(UserCab const& userCab, unsigned char permFlag) { std::auto_ptr<MidiBuffer> midiBuffer = userCab.createOutMidiBuffer(permFlag == 0x02); // F0 00 00 10 00 5F 01 (procedure 73) 00 30 01 (cab index) (permanence flag) (checksum) F7 unsigned char cabEnd[]= { 0xf0, 0x00, 0x00, 0x10, 0x00, 0x5f, 0x01, 0x73, 0x00, 0x30, 0x01, 0x00, 0x00, 0x00, 0xf7 }; cabEnd[sizeof(cabEnd) - 4] = static_cast<unsigned char>(userCab.getSlot() - 1); cabEnd[sizeof(cabEnd) - 3] = permFlag; unsigned char checksum = 0x00; for (size_t i = 0; i < sizeof(cabEnd) - 3; ++i) { checksum ^= cabEnd[i + 1]; } cabEnd[sizeof(cabEnd) - 2] = checksum; MidiMessage midiMessage (cabEnd, sizeof(cabEnd)); midiBuffer->addEvent (midiMessage, midiBuffer->getNumEvents() + 1); if (openMidi()) { //Logger::outputDebugString("midiBuffer size = " + String(midiBuffer->getNumEvents())); MidiBuffer::Iterator i (*midiBuffer); const uint8* data; int len, time, count = midiBuffer->getNumEvents(); bool rcvOK = false; while (i.getNextEvent (data, len, time) && deviceReady_M) { lastMidiInput_M.setSize(0); midiOutput_M->sendMessageNow(MidiMessage(data, len)); unsigned char const testOK[] = { 0x00, 0x00, 0x10, 0x00, 0x5f, 0x01, 0x7e, 0x00, 0x7a, 0x4a, }; unsigned char const testOKcabEnd[] = { 0x00, 0x00, 0x10, 0x00, 0x5f, 0x01, 0x7e, 0x00, 0x73, 0x43, }; if (--count > 0) { Logger::outputDebugString("\nMidiMessage to send:" + asHex(data, 16, true) + " ..."); rcvOK = waitForMidiInput(testOK); } else { Logger::outputDebugString("\nMidiMessage to send:" + asHex(data, sizeof(cabEnd), true)); rcvOK = waitForMidiInput(testOKcabEnd); } if (!rcvOK) { break; } } deviceReady_M = true; return rcvOK; } else { AlertWindow::showMessageBox (AlertWindow::WarningIcon, "Warning", "MIDI Device Not Found"); return false; } }
virtual void debugPrintBody(std::string const& _indent) const { assert(m_value.size()); std::cerr << _indent; if (m_ext.size()) std::cerr << asHex(m_ext, 1) << ": "; else std::cerr << "@: "; std::cerr << m_value << std::endl; }
void Interrupter::setGameShark(const std::string &codes) { std::string code; gsCodes.clear(); for (std::size_t pos = 0; pos < codes.length() && (code = codes.substr(pos, codes.find(';', pos) - pos), true); pos += code.length() + 1) { if (code.length() >= 8) { GsCode gs; gs.type = asHex(code[0]) << 4 | asHex(code[1]); gs.value = (asHex(code[2]) << 4 | asHex(code[3])) & 0xFF; gs.address = (asHex(code[4]) << 4 | asHex(code[5]) | asHex(code[6]) << 12 | asHex(code[7]) << 8) & 0xFFFF; gsCodes.push_back(gs); } } }
std::ostream& operator<<(std::ostream& _out, BlockChain const& _bc) { string cmp = toBigEndianString(_bc.m_lastBlockHash); auto it = _bc.m_detailsDB->NewIterator(_bc.m_readOptions); for (it->SeekToFirst(); it->Valid(); it->Next()) if (it->key().ToString() != "best") { BlockDetails d(RLP(it->value().ToString())); _out << asHex(it->key().ToString()) << ": " << d.number << " @ " << d.parent << (cmp == it->key().ToString() ? " BEST" : "") << std::endl; } delete it; return _out; }
static void testLastFlipCounts(int sq, u64 mover) { mover &= ~mask(sq); const u64 enemy = ~(mover | mask(sq)); int expected = lastFlipCount(sq, mover); u64 flip = flips(sq, mover, enemy); u64 actual = bitCount(flip); if (actual!=expected) { std::cout << "lastFlipCount error\n"; std::cout << "lastFlipCount : " << expected << "\n"; std::cout << "flips : (" << bitCount(flip) << ")\n"; printBitBoard(flip); std::cout << "\nboard : (* to move)\n"; printBoard(mover, enemy); std::cout << "\n"; std::cout << "enemy : " << asHex(enemy) << "\n"; std::cout << "square : " << squareText(sq) << " (" << sq << ")" << std::endl; } assertHexEquals(expected, actual); }
void Gsp1101::handleIncomingMidiMessage(MidiInput *source, MidiMessage const& message) { MemoryBlock mb (message.getRawData(), message.getRawDataSize()); Logger::outputDebugString("\nMidiInput = " + asHex(mb)); juce::uint8 const* msgBuff = message.getSysExData(); if (!msgBuff) { lastMidiInput_M.setSize(0); return; } lastMidiInput_M = MemoryBlock(message.getSysExData(), message.getSysExDataSize()); // A sysx ACK is: // F0 00 00 10 XX XX XX 7E 00 (procedure) (checksum) F7 if (msgBuff[6] == 0x7e) {} // A sysx NACK is: // F0 00 00 10 XX XX XX 7F 00 (procedure) (err code) (checksum) F7 else if (msgBuff[6] == 0x7f) { deviceReady_M = false; // NACK error codes: #define SYSX_INVALID_CHECKSUM 7 #define MERR_OVERRUN 10 #define MIDI_PROC_FAILED 12 switch (msgBuff[9]) { case SYSX_INVALID_CHECKSUM: case MERR_OVERRUN: case MIDI_PROC_FAILED: default: break; } //Logger::outputDebugString("MidiInput error = " + String(msgBuff[9])); } else {} }
String asHex(void const* msg, size_t size, bool newline) { MemoryBlock mb(msg, size); return asHex(mb, newline); }
void hash256rlp(HexMap const& _s, HexMap::const_iterator _begin, HexMap::const_iterator _end, unsigned _preLen, RLPStream& _rlp) { #if ENABLE_DEBUG_PRINT static std::string s_indent; if (_preLen) s_indent += " "; #endif if (_begin == _end) _rlp << ""; // NULL else if (std::next(_begin) == _end) { // only one left - terminate with the pair. _rlp.appendList(2) << hexPrefixEncode(_begin->first, true, _preLen) << _begin->second; #if ENABLE_DEBUG_PRINT if (g_hashDebug) std::cerr << s_indent << asHex(bytesConstRef(_begin->first.data() + _preLen, _begin->first.size() - _preLen), 1) << ": " << _begin->second << " = " << sha3(_rlp.out()) << std::endl; #endif } else { // find the number of common prefix nibbles shared // i.e. the minimum number of nibbles shared at the beginning between the first hex string and each successive. uint sharedPre = (uint)-1; uint c = 0; for (auto i = std::next(_begin); i != _end && sharedPre; ++i, ++c) { uint x = std::min(sharedPre, std::min((uint)_begin->first.size(), (uint)i->first.size())); uint shared = _preLen; for (; shared < x && _begin->first[shared] == i->first[shared]; ++shared) {} sharedPre = std::min(shared, sharedPre); } if (sharedPre > _preLen) { // if they all have the same next nibble, we also want a pair. #if ENABLE_DEBUG_PRINT if (g_hashDebug) std::cerr << s_indent << asHex(bytesConstRef(_begin->first.data() + _preLen, sharedPre), 1) << ": " << std::endl; #endif _rlp.appendList(2) << hexPrefixEncode(_begin->first, false, _preLen, (int)sharedPre); hash256aux(_s, _begin, _end, (unsigned)sharedPre, _rlp); #if ENABLE_DEBUG_PRINT if (g_hashDebug) std::cerr << s_indent << "= " << hex << sha3(_rlp.out()) << dec << std::endl; #endif } else { // otherwise enumerate all 16+1 entries. _rlp.appendList(17); auto b = _begin; if (_preLen == b->first.size()) { #if ENABLE_DEBUG_PRINT if (g_hashDebug) std::cerr << s_indent << "@: " << b->second << std::endl; #endif ++b; } for (auto i = 0; i < 16; ++i) { auto n = b; for (; n != _end && n->first[_preLen] == i; ++n) {} if (b == n) _rlp << ""; else { #if ENABLE_DEBUG_PRINT if (g_hashDebug) std::cerr << s_indent << std::hex << i << ": " << std::dec << std::endl; #endif hash256aux(_s, b, n, _preLen + 1, _rlp); } b = n; } if (_preLen == _begin->first.size()) _rlp << _begin->second; else _rlp << ""; #if ENABLE_DEBUG_PRINT if (g_hashDebug) std::cerr << s_indent << "= " << hex << sha3(_rlp.out()) << dec << std::endl; #endif } } #if ENABLE_DEBUG_PRINT if (_preLen) s_indent.resize(s_indent.size() - 2); #endif }
virtual void debugPrintBody(std::string const& _indent) const { std::cerr << _indent << asHex(m_ext, 1) << ": "; m_next->debugPrint(_indent + " "); }