Exemplo n.º 1
0
// Optimize reads by short-circuiting what is unnecessary.
// Invalid returns are conflated with skipped, but are store only.
bool stealth_record::from_data(reader& source, size_t start_height,
    const binary& filter)
{
    height_ = source.read_4_bytes_little_endian();

    if (height_ < start_height)
    {
        reset();
        source.skip(serialized_size(false) - sizeof(uint32_t));
        return false;
    }

    prefix_ = source.read_4_bytes_little_endian();

    if (!filter.is_prefix_of(prefix_))
    {
        reset();
        source.skip(serialized_size(false) - 2 * sizeof(uint32_t));
        return false;
    }

    unsigned_ephemeral_ = source.read_hash();
    public_key_hash_ = source.read_short_hash();
    transaction_hash_ = source.read_hash();

    if (!source)
        reset();

    return source;
}
Exemplo n.º 2
0
    /// Copy this message into a buffer.
    virtual char * serialize_to( char * p, size_t max_size ) {
      Grappa::impl::MessageBase::serialize_to( p, max_size );
      // copy deserialization function pointer
      auto fp = &deserialize_and_call;
      if( serialized_size() > max_size ) {
        return p;
      } else {
        // // turn into 2D pointer
        //auto gfp = make_global( fp, destination_ );
        // // write to buffer
        //*(reinterpret_cast< intptr_t* >(p)) = reinterpret_cast< intptr_t >( gfp );
        //*(reinterpret_cast< intptr_t* >(p)) = reinterpret_cast< intptr_t >( fp );
        //intptr_t gfp = reinterpret_cast< intptr_t >( fp ) << 16;
        //gfp |= destination_; // TODO: watch out for sign extension
        //*(reinterpret_cast< intptr_t* >(p)) = gfp;
        // p += sizeof( fp );

        FPAddr gfp = { destination_, reinterpret_cast< intptr_t >( fp ) };
        *(reinterpret_cast< FPAddr* >(p)) = gfp;
        static_assert( sizeof(gfp) == 8, "gfp wrong size?" );
        p += sizeof( gfp );

        
        // copy contents
        std::memcpy( p, &storage_, sizeof(storage_) );
        
        DVLOG(5) << __PRETTY_FUNCTION__ << " serialized message of size " << sizeof(fp) + sizeof(storage_) << " to " << gfp.dest << " with deserializer " << fp;
        
        // return pointer following message
        return p + sizeof( T );
      }
    }
size_t AuthorizationSet::SerializedSizeOfElements() const {
    size_t size = 0;
    for (size_t i = 0; i < elems_size_; ++i) {
        size += serialized_size(elems_[i]);
    }
    return size;
}
Exemplo n.º 4
0
data_chunk alert_payload::to_data() const
{
    data_chunk data;
    boost::iostreams::stream<byte_sink<data_chunk>> ostream(data);
    to_data(ostream);
    ostream.flush();
    BITCOIN_ASSERT(data.size() == serialized_size());
    return data;
}
Exemplo n.º 5
0
data_chunk nonce_::to_data() const
{
    data_chunk data;
    data_sink ostream(data);
    to_data(ostream);
    ostream.flush();
    BITCOIN_ASSERT(data.size() == serialized_size());
    return data;
}
Exemplo n.º 6
0
data_chunk block::to_data(bool with_transaction_count) const
{
    data_chunk data;
    data_sink ostream(data);
    to_data(ostream, with_transaction_count);
    ostream.flush();
    BITCOIN_ASSERT(data.size() == serialized_size(with_transaction_count));
    return data;
}
Exemplo n.º 7
0
data_chunk alert::to_data(uint32_t version) const
{
    data_chunk data;
    const auto size = serialized_size(version);
    data.reserve(size);
    data_sink ostream(data);
    to_data(version, ostream);
    ostream.flush();
    BITCOIN_ASSERT(data.size() == size);
    return data;
}
Exemplo n.º 8
0
data_chunk point::to_data(bool wire) const
{
    data_chunk data;
    const auto size = serialized_size(wire);
    data.reserve(size);
    data_sink ostream(data);
    to_data(ostream, wire);
    ostream.flush();
    BITCOIN_ASSERT(data.size() == size);
    return data;
}
Exemplo n.º 9
0
    void serialize (vertex_id v_id, std::vector<byte> & serialized) const
        {
            size_type s = serialized_size ();
#ifdef VERBOSE
            std::cerr << "Serializing bytes = " << s << '\n';
            std::cerr << "<< sizeof (length) = " << sizeof (s)
                      << " sizeof(vid) = " << sizeof (v_id) << '\n';
#endif
            serialized.reserve (serialized.size () + s);
            serialized.resize (serialized.size () + s);
            byte *end_of_serialized = &serialized.back () - s + 1;
            dias::serialize (s, &end_of_serialized);
            dias::serialize (v_id, &end_of_serialized);
            dias::serialize_vect_as_float (coords, &end_of_serialized);
            voronoi_mbr.serialize_as_float (&end_of_serialized);
            BOOST_FOREACH (vertex_id v, neighbours)
            {
                dias::serialize (v, &end_of_serialized);
            }
Exemplo n.º 10
0
void message_header::unmarshall(binary_reader& reader)
{
    reader.read((char*)this, serialized_size());
}
Exemplo n.º 11
0
void message_header::marshall(binary_writer& writer)
{
    writer.write((const char*)this, serialized_size());
}