Example #1
0
/*static*/ mutation_ptr mutation::read_from_log_file(binary_reader& reader, dsn_message_t from)
{
    mutation_ptr mu(new mutation());
    unmarshall(reader, mu->data.header, DSF_THRIFT_BINARY);
    int size;
    unmarshall(reader, size, DSF_THRIFT_BINARY);
    mu->data.updates.resize(size);
    std::vector<int> lengths(size, 0);
    for (int i = 0; i < size; ++i)
    {
        unmarshall(reader, mu->data.updates[i].code, DSF_THRIFT_BINARY);
        unmarshall(reader, lengths[i], DSF_THRIFT_BINARY);
    }
    for (int i = 0; i < size; ++i)
    {
        int len = lengths[i];
        std::shared_ptr<char> holder(new char[len], [](char* ptr){ delete []ptr; });
        reader.read(holder.get(), len);
        mu->data.updates[i].data.assign(holder, 0, len);
    }

    mu->client_requests.resize(mu->data.updates.size());

    if (nullptr != from)
    {
        mu->_prepare_request = from;
        dsn_msg_add_ref(from); // released on dctor
    }

    snprintf_p(mu->_name, sizeof(mu->_name),
        "%" PRId32 ".%" PRId32 ".%" PRId64 ".%" PRId64,
        mu->data.header.pid.get_app_id(),
        mu->data.header.pid.get_partition_index(),
        mu->data.header.ballot,
        mu->data.header.decree);

    return mu;
}
Example #2
0
void message_header::unmarshall(binary_reader& reader)
{
    reader.read((char*)this, serialized_size());
}
Example #3
0
void message_header::unmarshall(binary_reader& reader)
{
    reader.read((char*)this, MSG_HDR_SERIALIZED_SIZE);
}