fxos/lib/binary.cpp

72 lines
2.2 KiB
C++

//---------------------------------------------------------------------------//
// 1100101 |_ mov #0, r4 __ //
// 11 |_ <0xb380 %5c4> / _|_ _____ ___ //
// 0110 |_ 3.50 -> 3.60 | _\ \ / _ (_-< //
// |_ base# + offset |_| /_\_\___/__/ //
//---------------------------------------------------------------------------//
#include <fxos/binary.h>
using namespace FxOS;
//=== Binary ===//
BSON Binary::serialize() const
{
BSONField *fields = (BSONField *)malloc(m_objects.size() * sizeof *fields);
int i = 0;
for(auto const &[address, obj]: m_objects) {
char str[32];
sprintf(str, "%08x", address);
// TODO: Serialize BinaryObjects
// new(&fields[i]) BSONField(str, obj->serialize());
new(&fields[i]) BSONField(str, BSON::mkNull());
i++;
}
return BSON::mkDocument({
{"*", BSON::mkString("Binary")},
{"vspace", m_vspace.serialize()},
{"objects", BSON::mkDocumentFromFieldArray(fields, m_objects.size())},
});
}
void Binary::deserialize(BSON const &b)
{
assert(b.isDocument() && b["*"].getString() == "Binary");
m_vspace.deserialize(b["vspace"]);
BSONField const *fields = b["objects"].getDocumentFields();
int N = b["objects"].size();
for(int i = 0; i < N; i++) {
uint32_t address = std::stoul(fields[i].getName(), nullptr, 16);
// TODO: Deserialize BinaryObject from fields[i].value()
}
}
//=== BinaryObject ===//
bool BinaryObject::intersects(BinaryObject const &other) const
{
uint32_t inter_start = std::max(m_address, other.address());
uint32_t inter_end
= std::min(m_address + m_size, other.address() + other.size());
return inter_start < inter_end;
}
bool BinaryObject::contains(BinaryObject const &other) const
{
return m_address <= other.address()
&& m_address + m_size >= other.address() + other.size();
}
//=== Variable ===//
Variable::Variable(Binary &binary, u32 address, std::string const &name):
BinaryObject(binary, BinaryObject::Variable, address, 4)
{
setName(name);
// m_type = IntegerType(4, false);
}