<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using TakeAshUtility;

namespace p2pChat {

    public struct ChatMessage {

        const int StringBufferSize = 128;

        public enum Commands : short {
            Undefined,
            Acknowledge,
            Register,
            Say,
        }

        public ChatMessage(Commands command, string sender, string body, byte[] icon) :
            this() {

            Command = command;
            Sender = sender;
            Body = body;
            Icon = icon;
        }

        public Commands Command;

        public string Sender;

        public string Body;

        public byte[] Icon;

        public override string ToString() {
            return "Command:" + Command + ", Sender:{" + Sender + "}, Message:{" + Body + "}";
        }

        public byte[] ToBytes() {
            using (var stream = new MemoryStream())
            using (var writer = new BinaryWriter(stream, Encoding.UTF8)) {
                writer.Write((short)Command);
                writer.Write(Sender);
                writer.Write(Body);
                if (Icon == null) {
                    writer.Write((int)0);
                } else {
                    writer.Write(Icon.Length);
                    writer.Write(Icon, 0, Icon.Length);
                }
                return stream.ToArray();
            }
        }

        public static ChatMessage FromBytes(byte[] bytes) {
            var ret = new ChatMessage();
            using (var stream = new MemoryStream(bytes))
            using (var reader = new BinaryReader(stream, Encoding.UTF8)) {
                ret.Command = (Commands)reader.ReadInt16();
                ret.Sender = reader.ReadString();
                ret.Body = reader.ReadString();
                var iconLength = reader.ReadInt32();
                if (iconLength > 0) {
                    ret.Icon = reader.ReadBytes(iconLength);
                }
            }
            return ret;
        }
    }
}
<commit_msg>ChatMessage: change ToBytes() return value<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using TakeAshUtility;

namespace p2pChat {

    public struct ChatMessage {

        const int StringBufferSize = 128;

        public enum Commands : short {
            Undefined,
            Acknowledge,
            Register,
            Say,
        }

        public ChatMessage(Commands command, string sender, string body, byte[] icon) :
            this() {

            Command = command;
            Sender = sender;
            Body = body;
            Icon = icon;
        }

        public Commands Command;

        public string Sender;

        public string Body;

        public byte[] Icon;

        public override string ToString() {
            return "Command:" + Command + ", Sender:{" + Sender + "}, Message:{" + Body + "}";
        }

        public byte[] ToBytes() {
            using (var stream = new MemoryStream())
            using (var writer = new BinaryWriter(stream, Encoding.UTF8)) {
                writer.Write((short)Command);
                writer.Write(Sender);
                writer.Write(Body);
                if (Icon == null) {
                    writer.Write((int)0);
                } else {
                    writer.Write(Icon.Length);
                    writer.Write(Icon, 0, Icon.Length);
                }
                return stream.GetBuffer();
            }
        }

        public static ChatMessage FromBytes(byte[] bytes) {
            var ret = new ChatMessage();
            using (var stream = new MemoryStream(bytes))
            using (var reader = new BinaryReader(stream, Encoding.UTF8)) {
                ret.Command = (Commands)reader.ReadInt16();
                ret.Sender = reader.ReadString();
                ret.Body = reader.ReadString();
                var iconLength = reader.ReadInt32();
                if (iconLength > 0) {
                    ret.Icon = reader.ReadBytes(iconLength);
                }
            }
            return ret;
        }
    }
}

{'fraction_non_alphanumeric': 0.09554710226001342, 'fraction_numerical': 0.005817856343701052, 'mean_word_length': 1.3763955342902712, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5487368', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1067, 'n_words': 280}