<commit_before>// Copyright 2006 <NAME> <<EMAIL>>
// This software is made available under the MIT License
// See COPYING for details

//defined by default, since this is not a controversial extension
#define PROTO_TYPE_SINGLE

using System;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;

namespace NDesk.DBus
{
	public class MessageWriter
	{
		//TODO: use endianness instead of writing the message is in native format
		protected EndianFlag endianness;
		protected MemoryStream stream;
		protected BinaryWriter bw;

		public MessageWriter (EndianFlag endianness)
		{
			if (endianness != EndianFlag.Little)
				throw new NotImplementedException ("Only little-endian message writing is currently supported");

			this.endianness = endianness;
			stream = new MemoryStream ();
			bw = new BinaryWriter (stream);
		}

		public byte[] ToArray ()
		{
			//TODO: mark the writer locked or something here
			return stream.ToArray ();
		}

		public void CloseWrite ()
		{
			int needed = Padding.PadNeeded ((int)stream.Position, 8);
			for (int i = 0 ; i != needed ; i++)
				stream.WriteByte (0);
		}

		public void Write (byte val)
		{
			WritePad (1);
			bw.Write (val);
		}

		public void Write (bool val)
		{
			WritePad (4);
			bw.Write ((uint) (val ? 1 : 0));
		}

		public void Write (short val)
		{
			WritePad (2);
			bw.Write (val);
		}

		public void Write (ushort val)
		{
			WritePad (2);
			bw.Write (val);
		}

		public void Write (int val)
		{
			WritePad (4);
			bw.Write (val);
		}

		public void Write (uint val)
		{

			WritePad (4);
			bw.Write (val);
		}

		public void Write (long val)
		{
			WritePad (8);
			bw.Write (val);
		}

		public void Write (ulong val)
		{
			WritePad (8);
			bw.Write (val);
		}

#if PROTO_TYPE_SINGLE
		public void Write (float val)
		{
			WritePad (4);
			bw.Write (val);
		}
#endif

		public void Write (double val)
		{
			WritePad (8);
			bw.Write (val);
		}

		public void Write (string val)
		{
			Write ((uint)val.Length);

			bw.Write (Encoding.UTF8.GetBytes (val));
			bw.Write ((byte)0); //NULL string terminator
		}

		public void Write (ObjectPath val)
		{
			Write (val.Value);
		}
<commit_msg>UTF-8 sending fix: send the number of bytes, not of characters<commit_after>// Copyright 2006 <NAME> <<EMAIL>>
// This software is made available under the MIT License
// See COPYING for details

//defined by default, since this is not a controversial extension
#define PROTO_TYPE_SINGLE

using System;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;

namespace NDesk.DBus
{
	public class MessageWriter
	{
		//TODO: use endianness instead of writing the message is in native format
		protected EndianFlag endianness;
		protected MemoryStream stream;
		protected BinaryWriter bw;

		public MessageWriter (EndianFlag endianness)
		{
			if (endianness != EndianFlag.Little)
				throw new NotImplementedException ("Only little-endian message writing is currently supported");

			this.endianness = endianness;
			stream = new MemoryStream ();
			bw = new BinaryWriter (stream);
		}

		public byte[] ToArray ()
		{
			//TODO: mark the writer locked or something here
			return stream.ToArray ();
		}

		public void CloseWrite ()
		{
			int needed = Padding.PadNeeded ((int)stream.Position, 8);
			for (int i = 0 ; i != needed ; i++)
				stream.WriteByte (0);
		}

		public void Write (byte val)
		{
			WritePad (1);
			bw.Write (val);
		}

		public void Write (bool val)
		{
			WritePad (4);
			bw.Write ((uint) (val ? 1 : 0));
		}

		public void Write (short val)
		{
			WritePad (2);
			bw.Write (val);
		}

		public void Write (ushort val)
		{
			WritePad (2);
			bw.Write (val);
		}

		public void Write (int val)
		{
			WritePad (4);
			bw.Write (val);
		}

		public void Write (uint val)
		{

			WritePad (4);
			bw.Write (val);
		}

		public void Write (long val)
		{
			WritePad (8);
			bw.Write (val);
		}

		public void Write (ulong val)
		{
			WritePad (8);
			bw.Write (val);
		}

#if PROTO_TYPE_SINGLE
		public void Write (float val)
		{
			WritePad (4);
			bw.Write (val);
		}
#endif

		public void Write (double val)
		{
			WritePad (8);
			bw.Write (val);
		}

		public void Write (string val)
		{
			byte[] utf8_data = Encoding.UTF8.GetBytes (val);
			Write ((uint)utf8_data.Length);
			bw.Write (utf8_data);
			bw.Write ((byte)0); //NULL string terminator
		}

		public void Write (ObjectPath val)
		{
			Write (val.Value);
		}

{'fraction_non_alphanumeric': 0.11511912714317524, 'fraction_numerical': 0.010242707637497217, 'mean_word_length': 2.9681978798586575, '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': '7517378', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1502, 'n_words': 493}