<commit_before>namespace EventStore.Persistence.RavenPersistence
{
	using System;
	using System.Collections.Generic;
	using System.Globalization;
	using System.Linq;
	using Serialization;

	public static class ExtensionMethods
	{
		public static string ToRavenCommitId(this Commit commit)
		{
			return string.Format(CultureInfo.InvariantCulture, "{0}/{1}", commit.StreamId, commit.CommitSequence);
		}

		public static RavenCommit ToRavenCommit(this Commit commit, IDocumentSerializer serializer)
		{
			return new RavenCommit
			{
				Id = ToRavenCommitId(commit),
				StreamId = commit.StreamId,
				CommitSequence = commit.CommitSequence,
				StartingStreamRevision = commit.StreamRevision - (commit.Events.Count - 1),
				StreamRevision = commit.StreamRevision,
				CommitId = commit.CommitId,
				CommitStamp = commit.CommitStamp,
				Headers = commit.Headers,
				Payload = serializer.Serialize(commit.Events)
			};
		}

		public static Commit ToCommit(this RavenCommit commit, IDocumentSerializer serializer)
		{
			return new Commit(
				commit.StreamId,
				commit.StreamRevision,
				commit.CommitId,
				commit.CommitSequence,
				commit.CommitStamp,
				commit.Headers,
				serializer.Deserialize<List<EventMessage>>(commit.Payload));
		}

		public static RavenSnapshot ToRavenSnapshot(this Snapshot snapshot, IDocumentSerializer serializer)
		{
			return new RavenSnapshot
			{
				StreamId = snapshot.StreamId,
				StreamRevision = snapshot.StreamRevision,
				Payload = serializer.Serialize(snapshot.Payload)
			};
		}

		public static Snapshot ToSnapshot(this RavenSnapshot snapshot, IDocumentSerializer serializer)
		{
			if (snapshot == null)
				return null;

			return new Snapshot(
				snapshot.StreamId,
				snapshot.StreamRevision,
				serializer.Deserialize<object>(snapshot.Payload));
		}

		public static string ToRavenStreamId(this Guid streamId)
		{
			return string.Format("StreamHeads/{0}", streamId);
		}

		public static RavenStreamHead ToRavenStreamHead(this Commit commit)
		{
			return new RavenStreamHead
			{
				Id = commit.StreamId.ToRavenStreamId(),
				StreamId = commit.StreamId,
				HeadRevision = commit.StreamRevision,
				SnapshotRevision = 0
			};
		}

		public static RavenStreamHead ToRavenStreamHead(this Snapshot snapshot)
		{<commit_msg>Fixed #57--Raven (or mostly likely Newtonsoft JSON.NET) now gives back a byte[] when the ByteStreamSerializer is used which can then be deserialized.<commit_after>namespace EventStore.Persistence.RavenPersistence
{
	using System;
	using System.Collections.Generic;
	using System.Globalization;
	using System.Linq;
	using Serialization;

	public static class ExtensionMethods
	{
		public static string ToRavenCommitId(this Commit commit)
		{
			return string.Format(CultureInfo.InvariantCulture, "{0}/{1}", commit.StreamId, commit.CommitSequence);
		}

		public static RavenCommit ToRavenCommit(this Commit commit, IDocumentSerializer serializer)
		{
			return new RavenCommit
			{
				Id = ToRavenCommitId(commit),
				StreamId = commit.StreamId,
				CommitSequence = commit.CommitSequence,
				StartingStreamRevision = commit.StreamRevision - (commit.Events.Count - 1),
				StreamRevision = commit.StreamRevision,
				CommitId = commit.CommitId,
				CommitStamp = commit.CommitStamp,
				Headers = commit.Headers,
				Payload = serializer.Serialize(commit.Events)
			};
		}

		public static Commit ToCommit(this RavenCommit commit, IDocumentSerializer serializer)
		{
			return new Commit(
				commit.StreamId,
				commit.StreamRevision,
				commit.CommitId,
				commit.CommitSequence,
				commit.CommitStamp,
				commit.Headers,
				serializer.Deserialize<List<EventMessage>>(commit.Payload.FromBase64()));
		}
		private static object FromBase64(this object value)
		{
			return value is string ? Convert.FromBase64String(value as string) : value;
		}

		public static RavenSnapshot ToRavenSnapshot(this Snapshot snapshot, IDocumentSerializer serializer)
		{
			return new RavenSnapshot
			{
				StreamId = snapshot.StreamId,
				StreamRevision = snapshot.StreamRevision,
				Payload = serializer.Serialize(snapshot.Payload)
			};
		}

		public static Snapshot ToSnapshot(this RavenSnapshot snapshot, IDocumentSerializer serializer)
		{
			if (snapshot == null)
				return null;

			return new Snapshot(
				snapshot.StreamId,
				snapshot.StreamRevision,
				serializer.Deserialize<object>(snapshot.Payload.FromBase64()));
		}

		public static string ToRavenStreamId(this Guid streamId)
		{
			return string.Format("StreamHeads/{0}", streamId);
		}

		public static RavenStreamHead ToRavenStreamHead(this Commit commit)
		{
			return new RavenStreamHead
			{
				Id = commit.StreamId.ToRavenStreamId(),
				StreamId = commit.StreamId,
				HeadRevision = commit.StreamRevision,
				SnapshotRevision = 0
			};
		}

		public static RavenStreamHead ToRavenStreamHead(this Snapshot snapshot)
		{
{'fraction_non_alphanumeric': 0.0821216465287733, 'fraction_numerical': 0.0040958427196395655, 'mean_word_length': 4.1847133757961785, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1565868', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1403, 'n_words': 323}