jsonhash 0.2.0

A command-line tool to generate hash values for files. SHA256 and MD5. Output and Error messages in JSON format.
Documentation
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use serde_json::Value;

/// Represents request parameters as a Map of String key and Value
pub type Params = HashMap<String, Value>;

/// Represents a request with method, parameters, timestamp, and version
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Request {
    /// Request method used
    pub method: String,
    
    /// Request parameters
    pub params: Params,
    
    /// Timestamp in nanoseconds since epoch
    pub ts: u128,
    
    /// Crate version
    pub version: String,
}

/// Represents the response object
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Response {
    /// Timestamp in nanoseconds when the request was responded
    pub ts: u128,
    
    /// Absolute path of the file
    pub absfilepath: String,
    
    /// Hash of the file content
    pub hash: String,
    
    /// Name of the file
    pub filename: String,
    
    /// Short path relative to current directory
    pub shortpath: String,
    
    /// Hash of the absolute filepath
    pub pathid: String,
    
    /// Hash of the short path
    pub shortpathid: String,
}

/// Output JSON message structure
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OutputJsonMessage {
    pub request: Request,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub response: Option<Response>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error: Option<super::error::ErrorMessage>,
}

impl OutputJsonMessage {
    pub fn success(request: Request, response: Response) -> Self {
        Self {
            request,
            response: Some(response),
            error: None,
        }
    }
    
    pub fn error(request: Request, error: super::error::ErrorMessage) -> Self {
        Self {
            request,
            response: None,
            error: Some(error),
        }
    }
}