bool CTag::WriteTagToFile(CFileDataIO* file, EUtf8Str eStrEncode) const { ASSERT_VALID(this); // don't write tags of unknown types, we wouldn't be able to read them in again // and the met file would be corrupted if (IsStr() || IsInt() || IsFloat() || IsBlob() || IsInt64()) { file->WriteUInt8(m_uType); if (m_pszName) { UINT taglen = strlen(m_pszName); file->WriteUInt16((uint16)taglen); file->Write(m_pszName, taglen); } else { file->WriteUInt16(1); file->WriteUInt8(m_uName); } if (IsStr()) { file->WriteString(GetStr(), eStrEncode); } else if (IsInt()) { file->WriteUInt32((uint32)m_uVal); } else if (IsInt64(false)) { file->WriteUInt64(m_uVal); } else if (IsFloat()) { file->Write(&m_fVal, 4); } else if (IsBlob()) { // NOTE: This will break backward compatibility with met files for eMule versions prior to 0.44a file->WriteUInt32(m_nBlobSize); file->Write(m_pData, m_nBlobSize); } //TODO: Support more tag types else { TRACE("%s; Unknown tag: type=0x%02X\n", __FUNCTION__, m_uType); ASSERT(0); return false; } return true; } else { TRACE("%s; Ignored tag with unknown type=0x%02X\n", __FUNCTION__, m_uType); ASSERT(0); return false; } }
void CTag::SetInt64(uint64 uVal) { ASSERT( IsInt64(true) ); if (IsInt64(true)){ m_uVal = uVal; m_uType = TAGTYPE_UINT64; } }
LLBC_Variant &LLBC_Variant::BecomeInt64() { if (!IsInt64()) { *this = AsInt64(); } return *this; }
static void SendMessage(TCircularQueue<std::pair<FName, TArray<FOscDataElemStruct>>> & _pendingMessages, const osc::ReceivedMessage & message) { const FName address(message.AddressPattern()); TArray<FOscDataElemStruct> data; const auto argBegin = message.ArgumentsBegin(); const auto argEnd = message.ArgumentsEnd(); for(auto it = argBegin; it != argEnd; ++it) { FOscDataElemStruct elem; if(it->IsFloat()) { elem.SetFloat(it->AsFloatUnchecked()); } else if(it->IsDouble()) { elem.SetFloat(it->AsDoubleUnchecked()); } else if(it->IsInt32()) { elem.SetInt(it->AsInt32Unchecked()); } else if(it->IsInt64()) { elem.SetInt(it->AsInt64Unchecked()); } else if(it->IsBool()) { elem.SetBool(it->AsBoolUnchecked()); } else if(it->IsString()) { elem.SetString(FName(it->AsStringUnchecked())); } data.Add(elem); } // save it in pending messages _pendingMessages.Enqueue(std::make_pair(address, data)); }
bool CTag::WriteNewEd2kTag(CFileDataIO* data, EUtf8Str eStrEncode) const { ASSERT_VALID(this); // Write tag type uint8 uType; UINT uStrValLen = 0; LPCSTR pszValA = NULL; CStringA* pstrValA = NULL; if (IsInt()) { if (m_uVal <= 0xFF) uType = TAGTYPE_UINT8; else if (m_uVal <= 0xFFFF) uType = TAGTYPE_UINT16; else uType = TAGTYPE_UINT32; } else if (IsInt64(false)) { if (m_uVal <= 0xFF) uType = TAGTYPE_UINT8; else if (m_uVal <= 0xFFFF) uType = TAGTYPE_UINT16; else if (m_uVal <= 0xFFFFFFFF) uType = TAGTYPE_UINT32; else uType = TAGTYPE_UINT64; } else if (IsStr()) { if (eStrEncode == utf8strRaw) { CUnicodeToUTF8 utf8(*m_pstrVal); pstrValA = new CStringA((LPCSTR)utf8, utf8.GetLength()); } else if (eStrEncode == utf8strOptBOM) { if (NeedUTF8String(*m_pstrVal)) { CUnicodeToBOMUTF8 bomutf8(*m_pstrVal); pstrValA = new CStringA((LPCSTR)bomutf8, bomutf8.GetLength()); } else { CUnicodeToMultiByte mb(*m_pstrVal); pstrValA = new CStringA((LPCSTR)mb, mb.GetLength()); } } else { CUnicodeToMultiByte mb(*m_pstrVal); pstrValA = new CStringA((LPCSTR)mb, mb.GetLength()); } uStrValLen = pstrValA->GetLength(); pszValA = *pstrValA; if (uStrValLen >= 1 && uStrValLen <= 16) uType = (uint8)(TAGTYPE_STR1 + uStrValLen - 1); else uType = TAGTYPE_STRING; } else uType = m_uType; // Write tag name if (m_pszName) { data->WriteUInt8(uType); UINT uTagNameLen = strlen(m_pszName); data->WriteUInt16((uint16)uTagNameLen); data->Write(m_pszName, uTagNameLen); } else { ASSERT( m_uName != 0 ); data->WriteUInt8(uType | 0x80); data->WriteUInt8(m_uName); } // Write tag data if (uType == TAGTYPE_STRING) { data->WriteUInt16((uint16)uStrValLen); data->Write(pszValA, uStrValLen); } else if (uType >= TAGTYPE_STR1 && uType <= TAGTYPE_STR16) { data->Write(pszValA, uStrValLen); } else if (uType == TAGTYPE_UINT64) { data->WriteUInt64(m_uVal); } else if (uType == TAGTYPE_UINT32) { data->WriteUInt32((uint32)m_uVal); } else if (uType == TAGTYPE_UINT16) { data->WriteUInt16((uint16)m_uVal); } else if (uType == TAGTYPE_UINT8) { data->WriteUInt8((uint8)m_uVal); } else if (uType == TAGTYPE_FLOAT32) { data->Write(&m_fVal, 4); } else if (uType == TAGTYPE_HASH) { data->WriteHash16(m_pData); } else if (uType == TAGTYPE_BLOB) { data->WriteUInt32(m_nBlobSize); data->Write(m_pData, m_nBlobSize); } else { TRACE("%s; Unknown tag: type=0x%02X\n", __FUNCTION__, uType); ASSERT(0); return false; } delete pstrValA; return true; }