<commit_before>//
//  MQTTMessage.swift
//  SwiftMQTT
//
//  Created by <NAME> on 5/20/17.
//  Copyright © 2017 Object Computing Inc. All rights reserved.
//

import Foundation

public enum MQTTPayload: CustomStringConvertible {
    case data(Data)
    //case file(FileHandle)
    
    public var stringRep: String? {
        if case .data(let data) = self {
            return String(data: data, encoding: .utf8)
        }
        return nil
    }
    
    public var description: String {
        if let str = stringRep {
            return "'\(str)'"
        }
        if case .data(let data) = self {
            return "#\(data.count)"
        }
        return "##"
    }
}

public struct MQTTMessage: CustomStringConvertible {
	public let topic: String
	public let payload: MQTTPayload
	public let id: UInt16
	public let retain: Bool
	
	internal init(publishPacket: MQTTPublishPacket) {
		self.topic = publishPacket.message.topic
		self.payload = .data(publishPacket.message.payload)
		self.id = publishPacket.messageID<commit_msg>Added data field.<commit_after>//
//  MQTTMessage.swift
//  SwiftMQTT
//
//  Created by <NAME> on 5/20/17.
//  Copyright © 2017 Object Computing Inc. All rights reserved.
//

import Foundation

public enum MQTTPayload: CustomStringConvertible {
    case data(Data)
    //case file(FileHandle)
    
    public var stringRep: String? {
        if case .data(let data) = self {
            return String(data: data, encoding: .utf8)
        }
        return nil
    }
    
    public var data: Data? {
        if case .data(let data) = self {
            return data
        }
        return nil
    }
    
    public var description: String {
        if let str = stringRep {
            return "'\(str)'"
        }
        if case .data(let data) = self {
            return "#\(data.count)"
        }
        return "##"
    }
}

public struct MQTTMessage: CustomStringConvertible {
	public let topic: String
	public let payload: MQTTPayload
	public let id: UInt16
	public let retain: Bool
	
	internal init(publishPacket: MQTTPublishPacket) {
		self.topic = publishPacket.message.topic
		self.payload = .data(publishPacket.message.payload)
		self.id = publishPacket.messageID
{'fraction_non_alphanumeric': 0.09990958408679927, 'fraction_numerical': 0.0108499095840868, 'mean_word_length': 2.2259475218658893, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4813546', 'n_tokens_mistral': 709, 'n_tokens_neox': 662, 'n_words': 194}