#10 Serialize array of records via protobuf

This commit is contained in:
folex 2020-04-30 12:17:04 +03:00 committed by GitHub
commit 5a8a294f84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,10 @@
syntax = "proto3";
package dht.pb;
message Records {
repeated Record records = 1;
}
// Record represents a dht record that contains a value
// for a key value pair
message Record {

View File

@ -50,6 +50,7 @@ pub use behaviour::{Kademlia, KademliaConfig, KademliaEvent, Quorum};
pub use protocol::KadConnectionType;
pub use query::QueryId;
pub use record::{store, ProviderRecord, Record};
pub use dht_proto::{Record as ProtoRecord, Records as ProtoRecords};
use std::num::NonZeroUsize;

View File

@ -539,7 +539,7 @@ fn proto_to_resp_msg(message: proto::Message) -> Result<KadResponseMsg, io::Erro
}
}
fn record_from_proto(record: proto::Record) -> Result<Record, io::Error> {
pub fn record_from_proto(record: proto::Record) -> Result<Record, io::Error> {
let key = record::Key::from(record.key);
let value = record.value;
@ -562,7 +562,7 @@ fn record_from_proto(record: proto::Record) -> Result<Record, io::Error> {
Ok(Record { key, value, publisher, expires })
}
fn record_to_proto(record: Record) -> proto::Record {
pub fn record_to_proto(record: Record) -> proto::Record {
proto::Record {
key: record.key.to_vec(),
value: record.value,

View File

@ -70,7 +70,7 @@ impl From<Multihash> for Key {
}
/// A record stored in the DHT.
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct Record {
/// Key of the record.
pub key: Key,