<commit_before>﻿using Microsoft.WindowsAzure.Storage.Queue;
using Storage.Net.Messaging;
using System;
using System.IO;
using System.Linq;
using System.Text;

namespace Storage.Net.Microsoft.Azure.Messaging.Storage
{
   internal static class Converter
   {
      private const string PropEndWord = "PROPEND";
      private static readonly Guid CustomFlag = new Guid("820e7dc0-46a3-4177-a241-cdac97275ca9");
      private static readonly byte[] CustomFlagBytes = CustomFlag.ToByteArray();

      public static CloudQueueMessage ToCloudQueueMessage(QueueMessage message)
      {
         //when there are no properties pack the data as binary in raw form
         if(message.Properties == null || message.Properties.Count == 0)
         {
            return new CloudQueueMessage(message.Content);
         }

         //note that Azure Storage doesn't have properties on message, therefore I can do a simulation instead

         var clazz = new JsonProps
         {
            Properties = message.Properties.Select(p => new JsonProp { Name = p.Key, Value = p.Value }).ToArray()
         };
         byte[] propBytes = Encoding.UTF8.GetBytes(clazz.ToCompressedJsonString());

         CloudQueueMessage result;
         using (var ms = new MemoryStream())
         {
            using (var writer = new BinaryWriter(ms, Encoding.UTF8))
            {
               writer.Write(CustomFlagBytes);
               writer.Write(propBytes.Length);
               writer.Write(propBytes);
               writer.Write(message.Content);
            }

            result = new CloudQueueMessage(ms.ToArray());
         }

         return result;
      }

      public static QueueMessage ToQueueMessage(CloudQueueMessage message)
      {
         if(message == null) return null;

         byte[] mb = message.AsBytes;
         QueueMessage result;
         if (!IsCustomMessage(mb))
         {<commit_msg>adopting to new CloudQueueMessage constructor which doesnt' support byte arrays anymore<commit_after>﻿using Microsoft.WindowsAzure.Storage.Queue;
using Storage.Net.Messaging;
using System;
using System.IO;
using System.Linq;
using System.Text;

namespace Storage.Net.Microsoft.Azure.Messaging.Storage
{
   internal static class Converter
   {
      private const string PropEndWord = "PROPEND";
      private static readonly Guid CustomFlag = new Guid("820e7dc0-46a3-4177-a241-cdac97275ca9");
      private static readonly byte[] CustomFlagBytes = CustomFlag.ToByteArray();

      public static CloudQueueMessage ToCloudQueueMessage(QueueMessage message)
      {
         //when there are no properties pack the data as binary in raw form
         if(message.Properties == null || message.Properties.Count == 0)
         {
            var r = new CloudQueueMessage((string)null);
            r.SetMessageContent(message.Content);
            return r;
         }

         //note that Azure Storage doesn't have properties on message, therefore I can do a simulation instead

         var clazz = new JsonProps
         {
            Properties = message.Properties.Select(p => new JsonProp { Name = p.Key, Value = p.Value }).ToArray()
         };
         byte[] propBytes = Encoding.UTF8.GetBytes(clazz.ToCompressedJsonString());

         CloudQueueMessage result;
         using (var ms = new MemoryStream())
         {
            using (var writer = new BinaryWriter(ms, Encoding.UTF8))
            {
               writer.Write(CustomFlagBytes);
               writer.Write(propBytes.Length);
               writer.Write(propBytes);
               writer.Write(message.Content);
            }

            result = new CloudQueueMessage((string)null);
            result.SetMessageContent(ms.ToArray());
         }

         return result;
      }

      public static QueueMessage ToQueueMessage(CloudQueueMessage message)
      {
         if(message == null) return null;

         byte[] mb = message.AsBytes;
         QueueMessage result;
         if (!IsCustomMessage(mb))
         {
{'fraction_non_alphanumeric': 0.08788182273410115, 'fraction_numerical': 0.012018027040560842, 'mean_word_length': 2.337510442773601, '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': '3633564', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1002, 'n_words': 277}