Changeset 85212 in vbox
- Timestamp:
- Jul 11, 2020 12:27:52 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-all/QMTranslatorImpl.cpp
r83794 r85212 28 28 29 29 /* QM File Magic Number */ 30 static const size_t MagicLength= 16;31 static const uint8_t Magic[MagicLength] =30 static const size_t g_cbMagic = 16; 31 static const uint8_t g_abMagic[g_cbMagic] = 32 32 { 33 33 0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95, … … 60 60 public: 61 61 62 QMBytesStream(const uint8_t *const dataStart, size_t cbSize) :63 m_cbSize(dataStart ? cbSize : 0),64 m_dataStart(dataStart),65 m_iter(dataStart)62 QMBytesStream(const uint8_t *const dataStart, size_t cbSize) 63 : m_cbSize(dataStart ? cbSize : 0) 64 , m_dataStart(dataStart) 65 , m_iter(dataStart) 66 66 { 67 67 setEnd(); 68 68 } 69 69 70 /* Sets end pointer70 /** Sets end pointer. 71 71 * Used in message reader to detect the end of message block */ 72 72 inline void setEnd(size_t pos = 0) … … 89 89 } 90 90 91 /* Reads string in UTF16 and converts it into a UTF8 string */91 /** Reads string in UTF16 and converts it into a UTF8 string */ 92 92 inline com::Utf8Str readUtf16String() 93 93 { … … 109 109 } 110 110 111 /* Reads string in one-byte encoding111 /** Reads string in one-byte encoding. 112 112 * The string is assumed to be in ISO-8859-1 encoding */ 113 113 inline com::Utf8Str readString() … … 120 120 } 121 121 122 /* Checks the magic number 123 * Should be called when in the beginning of the data */ 122 /** Checks the magic number. 123 * Should be called when in the beginning of the data 124 * @throws exception on mismatch */ 124 125 inline void checkMagic() 125 126 { 126 checkSize(MagicLength); 127 if (memcmp(&(*m_iter), Magic, MagicLength)) throw QMException("Wrong magic number"); 128 m_iter += MagicLength; 129 } 130 131 /* Has we reached the end pointer? */ 132 inline bool hasFinished() { return m_iter == m_end; } 133 134 /* Returns current stream position */ 135 inline size_t tellPos() { return m_iter - m_dataStart; } 136 137 /* Moves current pointer to a desired position */ 138 inline void seek(int pos) { m_iter += pos; } 139 140 /* Checks whether stream has enough data to read size bytes */ 141 inline void checkSize(int size) 142 { 143 if (m_end - m_iter < size) throw QMException("Incorrect item size"); 127 checkSize(g_cbMagic); 128 if (RT_LIKELY(memcmp(&(*m_iter), g_abMagic, g_cbMagic) == 0)) 129 m_iter += g_cbMagic; 130 else 131 throw QMException("Wrong magic number"); 132 } 133 134 /** Has we reached the end pointer? */ 135 inline bool hasFinished() 136 { 137 return m_iter == m_end; 138 } 139 140 /** Returns current stream position */ 141 inline size_t tellPos() 142 { 143 return (size_t)(m_iter - m_dataStart); 144 } 145 146 /** Moves current pointer to a desired position */ 147 inline void seek(uint32_t offSkip) 148 { 149 size_t cbLeft = (size_t)(m_end - m_iter); 150 if (cbLeft <= offSkip) 151 m_iter += offSkip; 152 else 153 m_iter = m_end; /** @todo r=bird: Or throw exception via checkSize? */ 154 } 155 156 /** Checks whether stream has enough data to read size bytes */ 157 inline void checkSize(size_t size) 158 { 159 if (RT_LIKELY((size_t)(m_end - m_iter) >= size)) 160 return; 161 throw QMException("Incorrect item size"); 144 162 } 145 163 };
Note:
See TracChangeset
for help on using the changeset viewer.