template class B, typename U> void SameFormat::Read(B& buf, U& data) { buf.Give(&data, sizeof data); } template class B, typename U> void SameFormat::ReadBlock(B& buf, U* data, unsigned int elements) { buf.Give(data, elements * sizeof(U)); } // ---------------------------------------------------- template class B> void LeastSignificantFirst::Read(B& buf, uint16_t& value) { value = buf.Get(); value |= buf.Get() << 8; } template class B> void LeastSignificantFirst::Read(B& buf, uint32_t& value) { value = buf.Get(); value |= buf.Get() << 8; value |= buf.Get() << 16; value |= buf.Get() << 24; } template class B> void LeastSignificantFirst::Read(B& buf, uint64_t& value) { value = buf.Get(); value |= buf.Get() << 8; value |= buf.Get() << 16; value |= buf.Get() << 24; value |= (uint64_t)buf.Get() << 32; value |= (uint64_t)buf.Get() << 40; value |= (uint64_t)buf.Get() << 48; value |= (uint64_t)buf.Get() << 56; } template class B> void LeastSignificantFirst::Read(B& buf, float& value) { uint32_t tmp; this->Read(buf, tmp); memcpy(&value, &tmp, sizeof(value)); } template class B> void LeastSignificantFirst::Read(B& buf, double& value) { uint64_t tmp; this->Read(buf, tmp); memcpy(&value, &tmp, sizeof(value)); } template void LeastSignificantFirst::Reverse(Integer& value) { char* p = reinterpret_cast(&value); std::reverse(p, p + sizeof(value)); } template class B, typename U> void LeastSignificantFirst::ReadBlock(B& buf, U* data, unsigned int elements) { for (unsigned int ii = 0; ii < elements; ++ii) { buf.Give(*(data + ii)); } } /* Overloads for when U is uint8_t or int8_t */ template class B> void LeastSignificantFirst::ReadBlock(B& buf, uint8_t* data, unsigned int elements) { buf.Give(data, elements); } template class B> void LeastSignificantFirst::ReadBlock(B& buf, int8_t* data, unsigned int elements) { buf.Give(data, elements); } // ---------------------------------------------------- template class B> void MostSignificantFirst::Read(B& buf, uint16_t& value) { value = buf.Get() << 8; value |= buf.Get(); } template class B> void MostSignificantFirst::Read(B& buf, uint32_t& value) { value = buf.Get() << 24; value |= buf.Get() << 16; value |= buf.Get() << 8; value |= buf.Get(); } template class B> void MostSignificantFirst::Read(B& buf, uint64_t& value) { value = (uint64_t)buf.Get() << 56; value |= (uint64_t)buf.Get() << 48; value |= (uint64_t)buf.Get() << 40; value |= (uint64_t)buf.Get() << 32; value |= buf.Get() << 24; value |= buf.Get() << 16; value |= buf.Get() << 8; value |= buf.Get(); } template class B> void MostSignificantFirst::Read(B& buf, float& value) { uint32_t tmp; this->Read(buf, tmp); memcpy(&value, &tmp, sizeof(value)); } template class B> void MostSignificantFirst::Read(B& buf, double& value) { uint64_t tmp; this->Read(buf, tmp); memcpy(&value, &tmp, sizeof(value)); } template void MostSignificantFirst::Reverse(Integer& value) { char* p = reinterpret_cast(&value); std::reverse(p, p + sizeof(value)); } template class B, typename U> void MostSignificantFirst::ReadBlock(B& buf, U* data, unsigned int elements) { for (unsigned int ii = 0; ii < elements; ++ii) { buf.Give(*(data + ii)); } } template class B> void MostSignificantFirst::ReadBlock(B& buf, uint8_t* data, unsigned int elements) { buf.Give(data, elements); } template class B> void MostSignificantFirst::ReadBlock(B& buf, int8_t* data, unsigned int elements) { buf.Give(data, elements); }