Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1365 from holochain/improved-signal-serialization
Browse files Browse the repository at this point in the history
Improved signal serialization
  • Loading branch information
Connoropolous authored May 2, 2019
2 parents 8f98c1b + 8f04d1c commit cbd91ef
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 31 deletions.
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ serde = { version = "=1.0.89", features = ["rc"] }
serde_derive = "=1.0.89"
chrono = "=0.4.6"
serde_json = { version = "=1.0.39", features = ["preserve_order"] }
snowflake = "=1.3.0"
snowflake = { version = "=1.3.0", features = ["serde_support"] }
bitflags = "=1.0.4"
wasmi = "=0.4.4"
failure = "=0.1.5"
Expand Down
13 changes: 7 additions & 6 deletions core/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use std::{
/// The standard approach is to drop the ActionWrapper into the key of a state history HashMap and
/// use the convenience unwrap_to! macro to extract the action data in a reducer.
/// All reducer functions must accept an ActionWrapper so all dispatchers take an ActionWrapper.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize)]
pub struct ActionWrapper {
action: Action,
id: snowflake::ProcessUniqueId,
Expand Down Expand Up @@ -88,7 +88,8 @@ impl Hash for ActionWrapper {
}

/// All Actions for the Holochain Instance Store, according to Redux pattern.
#[derive(Clone, PartialEq, Debug)]
#[derive(Clone, PartialEq, Debug, Serialize)]
#[serde(tag = "action_type", content = "data")]
pub enum Action {
// ----------------
// Agent actions:
Expand Down Expand Up @@ -231,7 +232,7 @@ pub type ReduceFn<S> = fn(Arc<Context>, &mut S, &ActionWrapper);

/// The unique key that represents a GetLinks request, used to associate the eventual
/// response with this GetLinks request
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize)]
pub struct GetLinksKey {
/// The address of the Link base
pub base_address: Address,
Expand All @@ -245,7 +246,7 @@ pub struct GetLinksKey {

/// The unique key that represents a Get request, used to associate the eventual
/// response with this Get request
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize)]
pub struct GetEntryKey {
/// The address of the entry to get
pub address: Address,
Expand All @@ -256,7 +257,7 @@ pub struct GetEntryKey {

/// Everything the network module needs to know in order to send a
/// direct message.
#[derive(Clone, PartialEq, Debug)]
#[derive(Clone, PartialEq, Debug, Serialize)]
pub struct DirectMessageData {
/// The address of the node to send a message to
pub address: Address,
Expand All @@ -274,7 +275,7 @@ pub struct DirectMessageData {
}

/// Everything the network needs to initialize
#[derive(Clone, PartialEq, Debug)]
#[derive(Clone, PartialEq, Debug, Serialize)]
pub struct NetworkSettings {
/// P2pConfig that gets passed to [P2pNetwork](struct.P2pNetwork.html)
/// determines how to connect to the network module.
Expand Down
2 changes: 1 addition & 1 deletion core/src/nucleus/actions/call_zome_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use futures::{
};
use std::{pin::Pin, sync::Arc, thread};

#[derive(Clone, Debug, PartialEq, Hash)]
#[derive(Clone, Debug, PartialEq, Hash, Serialize)]
pub struct ExecuteZomeFnResponse {
call: ZomeFnCall,
result: ZomeFnResult,
Expand Down
2 changes: 1 addition & 1 deletion core/src/nucleus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use snowflake;
use std::sync::Arc;

/// Struct holding data for requesting the execution of a Zome function (ExecutionZomeFunction Action)
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
pub struct ZomeFnCall {
id: snowflake::ProcessUniqueId,
pub zome_name: String,
Expand Down
2 changes: 1 addition & 1 deletion core/src/nucleus/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod link_entry;
mod provenances;
mod remove_entry;

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Serialize)]
/// A failed validation.
pub enum ValidationError {
/// `Fail` means the validation function did run successfully and recognized the entry
Expand Down
24 changes: 3 additions & 21 deletions core/src/signal.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
use crate::action::ActionWrapper;
use crossbeam_channel::{unbounded, Receiver, Sender};
use holochain_core_types::{error::HolochainError, json::JsonString};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::{Deserialize, Deserializer};
use std::thread;

#[derive(Clone, Debug, DefaultJson)]
#[derive(Clone, Debug, Serialize, DefaultJson)]
#[serde(tag = "signal_type")]
pub enum Signal {
Internal(ActionWrapper),
User(JsonString),
}

impl Serialize for Signal {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
Signal::Internal(action_wrapper) => serializer.serialize_newtype_variant(
"Signal",
0,
"Internal",
&format!("{:?}", action_wrapper.action()),
),
Signal::User(msg) => {
serializer.serialize_newtype_variant("Signal", 1, "User", &msg.to_string())
}
}
}
}

impl<'de> Deserialize<'de> for Signal {
fn deserialize<D>(_deserializer: D) -> Result<Signal, D::Error>
where
Expand Down

0 comments on commit cbd91ef

Please sign in to comment.