mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 716295 part 3 - Add serialization into a buffer instead of an ostream. r=nfroyd
This commit is contained in:
parent
c4303b4973
commit
a08ff58250
@ -176,6 +176,20 @@ private:
|
||||
throw std::runtime_error("Unsupported ELF data encoding");
|
||||
}
|
||||
|
||||
template <typename R>
|
||||
void serialize(const char *buf, size_t len, char ei_data)
|
||||
{
|
||||
assert(len >= sizeof(R));
|
||||
if (ei_data == ELFDATA2LSB) {
|
||||
T::template swap<little_endian>(*this, *(R *)buf);
|
||||
return;
|
||||
} else if (ei_data == ELFDATA2MSB) {
|
||||
T::template swap<big_endian>(*this, *(R *)buf);
|
||||
return;
|
||||
}
|
||||
throw std::runtime_error("Unsupported ELF data encoding");
|
||||
}
|
||||
|
||||
public:
|
||||
serializable(const char *buf, size_t len, char ei_class, char ei_data)
|
||||
{
|
||||
@ -209,30 +223,30 @@ public:
|
||||
{
|
||||
if (ei_class == ELFCLASS32) {
|
||||
typename T::Type32 e;
|
||||
if (ei_data == ELFDATA2LSB) {
|
||||
T::template swap<little_endian>(*this, e);
|
||||
file.write((char *)&e, sizeof(e));
|
||||
return;
|
||||
} else if (ei_data == ELFDATA2MSB) {
|
||||
T::template swap<big_endian>(*this, e);
|
||||
file.write((char *)&e, sizeof(e));
|
||||
return;
|
||||
}
|
||||
serialize<typename T::Type32>((char *)&e, sizeof(e), ei_data);
|
||||
file.write((char *)&e, sizeof(e));
|
||||
return;
|
||||
} else if (ei_class == ELFCLASS64) {
|
||||
typename T::Type64 e;
|
||||
if (ei_data == ELFDATA2LSB) {
|
||||
T::template swap<little_endian>(*this, e);
|
||||
file.write((char *)&e, sizeof(e));
|
||||
return;
|
||||
} else if (ei_data == ELFDATA2MSB) {
|
||||
T::template swap<big_endian>(*this, e);
|
||||
file.write((char *)&e, sizeof(e));
|
||||
return;
|
||||
}
|
||||
serialize<typename T::Type64>((char *)&e, sizeof(e), ei_data);
|
||||
file.write((char *)&e, sizeof(e));
|
||||
return;
|
||||
}
|
||||
throw std::runtime_error("Unsupported ELF class or data encoding");
|
||||
}
|
||||
|
||||
void serialize(char *buf, size_t len, char ei_class, char ei_data)
|
||||
{
|
||||
if (ei_class == ELFCLASS32) {
|
||||
serialize<typename T::Type32>(buf, len, ei_data);
|
||||
return;
|
||||
} else if (ei_class == ELFCLASS64) {
|
||||
serialize<typename T::Type64>(buf, len, ei_data);
|
||||
return;
|
||||
}
|
||||
throw std::runtime_error("Unsupported ELF class");
|
||||
}
|
||||
|
||||
static inline unsigned int size(char ei_class)
|
||||
{
|
||||
if (ei_class == ELFCLASS32)
|
||||
|
Loading…
Reference in New Issue
Block a user