System.IO.Stream.WriteByte(byte)

Here are the examples of the csharp api System.IO.Stream.WriteByte(byte) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1148 Examples 7

19 Source : DisposeActionStream.cs
with MIT License
from 0x0ade

public override void WriteByte(byte value) => Inner.WriteByte(value);

19 Source : PositionAwareStream.cs
with MIT License
from 0x0ade

public override void WriteByte(byte value) {
            Inner.WriteByte(value);
            _Position++;
        }

19 Source : BigEndianBinaryWriter.cs
with MIT License
from 0xC0000054

public void Write(byte value)
        {
            VerifyNotDisposed();

            this.stream.WriteByte(value);
        }

19 Source : CodedOutputStream.cs
with MIT License
from 404Lcc

public void WriteMessage(Action<CodedOutputStream> encoder)
        {
            RefreshBuffer();
            var old_pos = output.Position;
            //��5�ֽ�ռλ���������size
            output.WriteByte(0x80);
            output.WriteByte(0x80);
            output.WriteByte(0x80);
            output.WriteByte(0x80);
            output.WriteByte(0);
            //WriteLength(value.CalculateSize());
            encoder.Invoke(this);
            RefreshBuffer();
            var new_pos = output.Position;
            var size = new_pos - old_pos - 5;
            output.Position = old_pos;
            for (int i = 0; i < 5; ++i)
            {
                var v = (byte)(size & 0x7F);
                if (i != 5 - 1) { v |= 0x80; }
                output.WriteByte(v);
                size = size >> 7;
            }
            output.Position = new_pos;
            if (size > 0) throw new Exception(size + "is big than int32");
        }

19 Source : RangeCoder.cs
with MIT License
from 91Act

public void ShiftLow()
		{
			if ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1)
			{
				byte temp = _cache;
				do
				{
					Stream.WriteByte((byte)(temp + (Low >> 32)));
					temp = 0xFF;
				}
				while (--_cacheSize != 0);
				_cache = (byte)(((uint)Low) >> 24);
			}
			_cacheSize++;
			Low = ((uint)Low) << 8;
		}

19 Source : Host.cs
with MIT License
from acandylevey

public void SendMessage(JObject data)
        {
            Log.LogMessage("Sending Message:" + JsonConvert.SerializeObject(data));

            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data.ToString(Formatting.None));
            Stream stdout = Console.OpenStandardOutput();
            stdout.WriteByte((byte)((bytes.Length >> 0) & 0xFF));
            stdout.WriteByte((byte)((bytes.Length >> 8) & 0xFF));
            stdout.WriteByte((byte)((bytes.Length >> 16) & 0xFF));
            stdout.WriteByte((byte)((bytes.Length >> 24) & 0xFF));
            stdout.Write(bytes, 0, bytes.Length);
            stdout.Flush();
        }

19 Source : RegistryHive.cs
with MIT License
from ADeltaX

public static RegistryHive Create(Stream stream, Ownership ownership)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream), "Attempt to create registry hive in null stream");
            }

            // Construct a file with minimal structure - hive header, plus one (empty) bin
            BinHeader binHeader = new BinHeader();
            binHeader.FileOffset = 0;
            binHeader.BinSize = (int)(4 * Sizes.OneKiB);

            HiveHeader hiveHeader = new HiveHeader();
            hiveHeader.Length = binHeader.BinSize;

            stream.Position = 0;

            byte[] buffer = new byte[hiveHeader.Size];
            hiveHeader.WriteTo(buffer, 0);
            stream.Write(buffer, 0, buffer.Length);

            buffer = new byte[binHeader.Size];
            binHeader.WriteTo(buffer, 0);
            stream.Position = BinStart;
            stream.Write(buffer, 0, buffer.Length);

            buffer = new byte[4];
            EndianUtilities.WriteBytesLittleEndian(binHeader.BinSize - binHeader.Size, buffer, 0);
            stream.Write(buffer, 0, buffer.Length);

            // Make sure the file is initialized out to the end of the firs bin
            stream.Position = BinStart + binHeader.BinSize - 1;
            stream.WriteByte(0);

            // Temporary hive to perform construction of higher-level structures
            RegistryHive newHive = new RegistryHive(stream);
            KeyNodeCell rootCell = new KeyNodeCell("root", -1);
            rootCell.Flags = RegistryKeyFlags.Normal | RegistryKeyFlags.Root;
            newHive.UpdateCell(rootCell, true);

            RegistrySecurity sd = new RegistrySecurity();
            sd.SetSecurityDescriptorSddlForm("O:BAG:BAD:PAI(A;;KA;;;SY)(A;CI;KA;;;BA)", AccessControlSections.All);
            SecurityCell secCell = new SecurityCell(sd);
            newHive.UpdateCell(secCell, true);
            secCell.NextIndex = secCell.Index;
            secCell.PreviousIndex = secCell.Index;
            newHive.UpdateCell(secCell, false);

            rootCell.SecurityIndex = secCell.Index;
            newHive.UpdateCell(rootCell, false);

            // Ref the root cell from the hive header
            hiveHeader.RootCell = rootCell.Index;
            buffer = new byte[hiveHeader.Size];
            hiveHeader.WriteTo(buffer, 0);
            stream.Position = 0;
            stream.Write(buffer, 0, buffer.Length);

            // Finally, return the new hive
            return new RegistryHive(stream, ownership);
        }

19 Source : RegistryHive.cs
with MIT License
from ADeltaX

private BinHeader AllocateBin(int minSize)
        {
            BinHeader lastBin = _bins[_bins.Count - 1];

            BinHeader newBinHeader = new BinHeader();
            newBinHeader.FileOffset = lastBin.FileOffset + lastBin.BinSize;
            newBinHeader.BinSize = MathUtilities.RoundUp(minSize + newBinHeader.Size, 4 * (int)Sizes.OneKiB);

            byte[] buffer = new byte[newBinHeader.Size];
            newBinHeader.WriteTo(buffer, 0);
            _fileStream.Position = BinStart + newBinHeader.FileOffset;
            _fileStream.Write(buffer, 0, buffer.Length);

            byte[] cellHeader = new byte[4];
            EndianUtilities.WriteBytesLittleEndian(newBinHeader.BinSize - newBinHeader.Size, cellHeader, 0);
            _fileStream.Write(cellHeader, 0, 4);

            // Update hive with new length
            _header.Length = newBinHeader.FileOffset + newBinHeader.BinSize;
            _header.Timestamp = DateTime.UtcNow;
            _header.Sequence1++;
            _header.Sequence2++;
            _fileStream.Position = 0;
            byte[] hiveHeader = StreamUtilities.ReadExact(_fileStream, _header.Size);
            _header.WriteTo(hiveHeader, 0);
            _fileStream.Position = 0;
            _fileStream.Write(hiveHeader, 0, hiveHeader.Length);

            // Make sure the file is initialized to desired position
            _fileStream.Position = BinStart + _header.Length - 1;
            _fileStream.WriteByte(0);

            _bins.Add(newBinHeader);
            return newBinHeader;
        }

19 Source : FsBufferedReaderWriter.cs
with MIT License
from Adoxio

protected void WriteHeader()
		{
			var fs = this.fileStream;

			// Write header marker
			fs.Seek(0, SeekOrigin.Begin);
			fs.Write(this.headerMarker, 0, this.headerMarker.Length);

			// Write version
			fs.WriteByte(1);

			this.lengthOffset = fs.Position;
			this.dataOffset = this.lengthOffset + sizeof(long);
		}

19 Source : Stream.cs
with Mozilla Public License 2.0
from ahyahy

public virtual void WriteByte(byte value)
        {
            M_Stream.WriteByte(value);
        }

19 Source : TweakableStream.cs
with MIT License
from airbreather

public override void WriteByte(byte value) => _inner.WriteByte(value);

19 Source : BitStream.cs
with MIT License
from Alexander-Scott

public void WriteBit(Bit data)
        {
            stream.Seek(offset, SeekOrigin.Begin);
            byte value = (byte)stream.ReadByte();
            stream.Seek(offset, SeekOrigin.Begin);
            if (!MSB)
            {
                value &= (byte)~(1 << bit);
                value |= (byte)(data << bit);
            }
            else
            {
                value &= (byte)~(1 << (7 - bit));
                value |= (byte)(data << (7 - bit));
            }
            if (ValidPosition)
            {
                stream.WriteByte(value);
            }
            else
            {
                if (AutoIncreaseStream)
                {
                    if (ChangeLength(Length + (offset - Length) + 1))
                    {
                        stream.WriteByte(value);
                    }
                    else
                    {
                        throw new IOException("Cannot write in an offset bigger than the length of the stream");
                    }
                }
                else
                {
                    throw new IOException("Cannot write in an offset bigger than the length of the stream");
                }
            }
            AdvanceBit();
            stream.Seek(offset, SeekOrigin.Begin);
        }

19 Source : BitStream.cs
with MIT License
from Alexander-Scott

public void circularShift(int bits, bool leftShift)
        {
            if (!ValidPositionWhen(8))
            {
                throw new IOException("Cannot read in an offset bigger than the length of the stream");
            }
            Seek(offset, 0);
            if (bits != 0 && bits <= 7)
            {
                byte value = (byte)stream.ReadByte();
                if (leftShift)
                {
                    value = (byte)(value << bits | value >> (8 - bits));
                }
                else
                {
                    value = (byte)(value >> bits | value << (8 - bits));
                }
                Seek(offset, 0);
                stream.WriteByte(value);
            }
            bit = 0;
            offset++;
        }

19 Source : Context.cs
with MIT License
from alexanderdna

private async Task writeAsync(Message msg)
        {
            var msgJson = Message.Serialize(msg);
            var stream = Client.GetStream();
            int pos = 0, nRemaining = msgJson.Length;
            while (nRemaining > 0 && ShouldDisconnect is false)
            {
                int bytesToCopy = Math.Min(outBuffer.Length, msgJson.Length - pos);
                for (int i = pos, j = 0, c = pos + bytesToCopy; i < c; ++i, ++j)
                {
                    outBuffer[j] = (byte)(msgJson[i] & 0x7f);
                }
                nRemaining -= bytesToCopy;
                pos += bytesToCopy;

                await stream.WriteAsync(outBuffer.AsMemory(0, bytesToCopy));
            }

            stream.WriteByte((byte)'\n');
            await stream.FlushAsync();
        }

19 Source : BitStream.cs
with MIT License
from Alexander-Scott

public void bitwiseShift(int bits, bool leftShift)
        {
            if (!ValidPositionWhen(8))
            {
                throw new IOException("Cannot read in an offset bigger than the length of the stream");
            }
            Seek(offset, 0);
            if (bits != 0 && bits <= 7)
            {
                byte value = (byte)stream.ReadByte();
                if (leftShift)
                {
                    value = (byte)(value << bits);
                }
                else
                {
                    value = (byte)(value >> bits);
                }
                Seek(offset, 0);
                stream.WriteByte(value);
            }
            bit = 0;
            offset++;
        }

19 Source : StreamExtensions.cs
with MIT License
from Aminator

public static void Align(this Stream stream, int size, byte fillByte = 0)
        {
            var mod = stream.Position % size;

            if (mod == 0)
            {
                return;
            }

            for (var i = 0; i < size - mod; i++)
            {
                stream.WriteByte(fillByte);
            }
        }

19 Source : AddCopyList.cs
with Apache License 2.0
from AmpScm

public void GDIFF(Stream Diff)
        {
            //http://www.w3.org/TR/NOTE-gdiff-19970825.html
            //
            //The GDIFF format is a binary format. The mime type of a GDIFF file is "application/gdiff". 
            //All binary numbers in a GDIFF file are stored in big endian format (most significant byte first). 
            //Each diff stream starts with the 4-byte magic number (value 0xd1ffd1ff), followed by a 1-byte 
            //version number (value 4). The version number is followed by a sequence of 1 byte commands which 
            //are interpreted in order. The last command in the stream is the end-of-file command (value 0). 
            //
            //byte - 8 bit signed 
            //ubyte - 8 bit unsigned 
            //ushort - 16 bit unsigned, most significant byte first 
            //int - 32 bit signed, most significant byte first 
            //long - 64 bit signed, most significant byte first 

            //Write the magic number 0xd1ffd1ff ("diff diff")
            for (int i = 0; i < 2; i++)
            {
                Diff.WriteByte(0xd1);
                Diff.WriteByte(0xff);
            }

            //Write the version
            Diff.WriteByte(0x04);

            //Write the data
            foreach (object o in this)
            {
                if (o is Addition)
                    GDIFFAdd(Diff, (Addition)o);
                else
                    GDIFFCopy(Diff, (Copy)o);
            }

            //Write the end-of-file command
            Diff.WriteByte(0x00);
        }

19 Source : AddCopyList.cs
with Apache License 2.0
from AmpScm

private void GDIFFCopy(Stream Diff, Copy C)
        {
            //Name	Cmd		Followed By			Action
            //-----------------------------------------------------------
            //COPY	249		ushort, ubyte		copy <position>, <length>
            //COPY	250		ushort, ushort		copy <position>, <length>
            //COPY	251		ushort, int			copy <position>, <length>
            //COPY	252		int, ubyte			copy <position>, <length>
            //COPY	253		int, ushort			copy <position>, <length>
            //COPY	254		int, int			copy <position>, <length>
            //COPY	255		long, int			copy <position>, <length>

            if (C.iBaseOffset <= ushort.MaxValue)
            {
                if (C.iLength <= byte.MaxValue)
                {
                    Diff.WriteByte(249);
                    WriteBigEndian(Diff, (ushort)C.iBaseOffset);
                    Diff.WriteByte((byte)C.iLength);
                }
                else if (C.iLength <= ushort.MaxValue)
                {
                    Diff.WriteByte(250);
                    WriteBigEndian(Diff, (ushort)C.iBaseOffset);
                    WriteBigEndian(Diff, (ushort)C.iLength);
                }
                else
                {
                    Diff.WriteByte(251);
                    WriteBigEndian(Diff, (ushort)C.iBaseOffset);
                    WriteBigEndian(Diff, C.iLength);
                }
            }
            else
            {
                if (C.iLength <= byte.MaxValue)
                {
                    Diff.WriteByte(252);
                    WriteBigEndian(Diff, C.iBaseOffset);
                    Diff.WriteByte((byte)C.iLength);
                }
                else if (C.iLength <= ushort.MaxValue)
                {
                    Diff.WriteByte(253);
                    WriteBigEndian(Diff, C.iBaseOffset);
                    WriteBigEndian(Diff, (ushort)C.iLength);
                }
                else
                {
                    Diff.WriteByte(254);
                    WriteBigEndian(Diff, C.iBaseOffset);
                    WriteBigEndian(Diff, C.iLength);
                }
            }
        }

19 Source : AddCopyList.cs
with Apache License 2.0
from AmpScm

private void WriteBigEndian(Stream Diff, byte[] arBytes)
        {
            if (BitConverter.IsLittleEndian)
            {
                for (int i = arBytes.Length - 1; i >= 0; i--)
                {
                    Diff.WriteByte(arBytes[i]);
                }
            }
            else
            {
                Diff.Write(arBytes, 0, arBytes.Length);
            }
        }

19 Source : AddCopyList.cs
with Apache License 2.0
from AmpScm

private void GDIFFAdd(Stream Diff, Addition Add)
        {
            //Name	Cmd		Followed By			Action
            //-----------------------------------------------------------
            //DATA	1		1 byte				append 1 data byte
            //DATA	2		2 bytes				append 2 data bytes
            //DATA	<n>		<n> bytes			append <n> data bytes
            //DATA	246		246 bytes			append 246 data bytes
            //DATA	247		ushort, <n> bytes	append <n> data bytes
            //DATA	248		int, <n> bytes		append <n> data bytes

            int iLength = Add.arBytes.Length;
            if (iLength <= 246)
            {
                Diff.WriteByte((byte)iLength);
                Diff.Write(Add.arBytes, 0, iLength);
            }
            else if (iLength <= ushort.MaxValue)
            {
                Diff.WriteByte(247);
                WriteBigEndian(Diff, (ushort)iLength);
                Diff.Write(Add.arBytes, 0, iLength);
            }
            else
            {
                Diff.WriteByte(248);
                WriteBigEndian(Diff, iLength);
                Diff.Write(Add.arBytes, 0, iLength);
            }
        }

19 Source : BoolMarshaler.cs
with GNU General Public License v3.0
from AndreiFedarets

public static void Marshal(bool value, Stream stream)
        {
            byte buffer = (byte) (value ? 1 : 0);
            stream.WriteByte(buffer);
        }

19 Source : ByteMarshaler.cs
with GNU General Public License v3.0
from AndreiFedarets

public static void Marshal(byte value, Stream stream)
        {
            stream.WriteByte(value);
        }

19 Source : HttpUtility.cs
with MIT License
from andruzzzhka

private static void urlEncode (byte b, Stream output)
    {
      if (b > 31 && b < 127) {
        var c = (char) b;
        if (c == ' ') {
          output.WriteByte ((byte) '+');
          return;
        }

        if (isNumeric (c)) {
          output.WriteByte (b);
          return;
        }

        if (isAlphabet (c)) {
          output.WriteByte (b);
          return;
        }

        if (isUnreserved (c)) {
          output.WriteByte (b);
          return;
        }
      }

      var i = (int) b;
      var bytes = new byte[] {
                    (byte) '%',
                    (byte) _hexChars[i >> 4],
                    (byte) _hexChars[i & 0x0F]
                  };

      output.Write (bytes, 0, 3);
    }

19 Source : ClippedStream.cs
with GNU General Public License v3.0
from anotak

public override void WriteByte(byte value)
		{
			// Check if this exceeds limits
			if((this.position + 1) > (this.length + 1))
				throw new ArgumentException("Attempted to write outside the range of the stream.");

			// Seek if needed
			if(basestream.Position != (this.offset + this.position))
				basestream.Seek(this.offset + this.position, SeekOrigin.Begin);

			// Read from base stream
			position++;
			basestream.WriteByte(value);
		}

19 Source : BinarySerializer.cs
with MIT License
from ansel86castro

public unsafe void Serialize(Stream stream, object obj)
        {
            if (obj == null)
            {
                stream.WriteByte((byte)Types.TYPE_NONE);
                return;
            }

            var type = obj.GetType();
            type = Nullable.GetUnderlyingType(type) ?? type;

            switch (obj)
            {
                case bool boolValue:
                    stream.WriteByte(boolValue ? (byte)Types.TYPE_TRUE : (byte)Types.TYPE_FALSE);
                    break;
                case byte byteV:
                    WriteInteger(stream, byteV);
                    break;
                case sbyte sByteV:
                    WriteInteger(stream, sByteV);
                    break;
                case short shortV:
                    WriteInteger(stream, shortV);
                    break;
                case ushort ushortV:
                    WriteInteger(stream, ushortV);
                    break;
                case int intV:
                    WriteInteger(stream, intV);
                    break;
                case uint uintV:
                    WriteInteger(stream, uintV);
                    break;
                case long longV:
                    WriteInteger(stream, longV);
                    break;
                case ulong ulongV:
                    WriteInteger(stream, ulongV);
                    break;
                case decimal decV:
                    WriteDecimal(stream, decV);
                    break;
                case float floatV:
                    WriteFloat(stream, floatV);
                    break;
                case double doubleV:
                    WriteDouble(stream, doubleV);
                    break;
                case char ch:
                    WriteChar(stream, ch);
                    break;
                case string str:
                    WriteString(stream, str);
                    break;
                case byte[] bytes:
                    WriteLenght(stream, bytes.Length, Types.TYPE_BINARY_8, Types.TYPE_BINARY_16, Types.TYPE_BINARY_32);
                    stream.Write(bytes, 0, bytes.Length);
                    break;
                case DateTime dateTime:
                    stream.WriteByte((byte)Types.TYPE_DATETIME);
                    TimeSpan span = dateTime - EPOCH;
                    WriteNumber(span.Ticks, stream);
                    break;
                case Guid guid:
                    WriteGuid(stream, guid);                    
                    break;
                case Array array:
                    WriteLenght(stream, array.Length, Types.TYPE_ARRAY_8, Types.TYPE_ARRAY_16, Types.TYPE_ARRAY_32);
                    WriteArray(stream, array);
                    break;
                case ICollection collection:
                    if (collection is IDictionary dict)
                    {
                        WriteLenght(stream, dict.Count, Types.TYPE_MAP_8, Types.TYPE_MAP_16, Types.TYPE_MAP_32);
                        WriteMap(stream, dict);
                    }
                    else if(collection is IList list)
                    {
                        WriteLenght(stream, list.Count, Types.TYPE_LIST_8, Types.TYPE_LIST_16, Types.TYPE_LIST_32);
                        WriteList(stream, list);
                    }
                    else
                    {
                        WriteLenght(stream, collection.Count, Types.TYPE_LIST_8, Types.TYPE_LIST_16, Types.TYPE_LIST_32);
                        WriteEnumerable(stream, collection);
                    }
                    break;                
                case IReflectorMetadataProvider accesorProvider:
                    WriteObject(stream, accesorProvider);
                    break;
                case Stream st:
                    if (st.Length > int.MaxValue)
                        throw new InvalidOperationException("Can not serialize more than 2GB of data for an stream");
                    WriteLenght(stream, (int)st.Length, Types.TYPE_STREAM_8, Types.TYPE_STREAM_16, Types.TYPE_STREAM_32);
                    WriteStream(stream, st);
                    break;
                default:
                    if (type.IsEnum)
                    {
                        WriteInteger(stream, System.Convert.ToInt32(obj));
                    }
                    else
                    {
                        WriteObject(stream, obj, type);
                    }
                    break;
            }
        }

19 Source : BinarySerializer.cs
with MIT License
from ansel86castro

private static void WriteInteger(Stream stream, long value)
        {
            if (value >= sbyte.MinValue && value <= sbyte.MaxValue)
            {
                stream.WriteByte((byte)Types.TYPE_INT_8);
                stream.WriteByte((byte)value);
            }
            else if (value >= byte.MinValue && value <= byte.MaxValue)
            {
                stream.WriteByte((byte)Types.TYPE_UINT_8);
                stream.WriteByte((byte)value);
            }
            else if (value >= short.MinValue && value <= short.MaxValue)
            {
                stream.WriteByte((byte)Types.TYPE_INT_16);
                WriteNumber((short)value, stream);
            }
            else if (value >= ushort.MinValue && value <= ushort.MaxValue)
            {
                stream.WriteByte((byte)Types.TYPE_UINT_16);
                WriteNumber((ushort)value, stream);
            }
            else if (value >= int.MinValue && value <= int.MaxValue)
            {
                stream.WriteByte((byte)Types.TYPE_INT_32);
                WriteNumber((int)value, stream);
            }
            else if (value >= uint.MinValue && value <= uint.MaxValue)
            {
                stream.WriteByte((byte)Types.TYPE_UINT_32);
                WriteNumber((uint)value, stream);
            }
            else
            {
                stream.WriteByte((byte)Types.TYPE_INT_64);
                WriteNumber(value, stream);
            }
        }

19 Source : StreamUtils.cs
with MIT License
from ansel86castro

public static void WriteString8(Stream stream, string s)
        {
            if (s == null)
            {
                stream.WriteByte(0);
            }
            else
            {
                byte[] bytes = UTF8.GetBytes(s);

                stream.WriteByte((byte)bytes.Length);
                stream.Write(bytes, 0, bytes.Length);
            }
        }

19 Source : StreamUtils.cs
with MIT License
from ansel86castro

public static void WriteHexBinaryFixed(Stream stream, string hex, int len)
        {
            if (hex == null)
            {
                for (int i = 0; i < len; i++)
                {
                    stream.WriteByte(0);
                }
            }
            else
            {
                int realLen = hex.Length / 2;

                if (realLen != len)
                {
                    throw new Exception();
                }

                stream.Write(HexToByteArray(hex), 0, len);
            }
        }

19 Source : StreamUtils.cs
with MIT License
from ansel86castro

public static void WriteHexBinary16(Stream stream, string hex)
        {
            if (hex == null)
            {
                stream.WriteByte(0);
            }
            else
            {
                WriteBinary16(stream, HexToByteArray(hex));
            }
        }

19 Source : BinarySerializer.cs
with MIT License
from ansel86castro

private static void WriteInteger(Stream stream, ulong value)
        {
            if (value <= byte.MaxValue)
            {
                stream.WriteByte((byte)Types.TYPE_UINT_8);
                stream.WriteByte((byte)value);
            }
            else if (value <= ushort.MaxValue)
            {
                stream.WriteByte((byte)Types.TYPE_UINT_16);
                WriteNumber((ushort)value, stream);
            }
            else if (value <= uint.MaxValue)
            {
                stream.WriteByte((byte)Types.TYPE_UINT_32);
                WriteNumber((int)value, stream);
            }
            else if (value <= uint.MaxValue)
            {
                stream.WriteByte((byte)Types.TYPE_UINT_32);
                WriteNumber((uint)value, stream);
            }
            else
            {
                stream.WriteByte((byte)Types.TYPE_UINT_64);
                WriteNumber(value, stream);
            }
        }

19 Source : BinarySerializer.cs
with MIT License
from ansel86castro

private static void WriteFloat(Stream stream, float floatV)
        {
            int i = (int)floatV;
            if (i == floatV)
            {
                WriteInteger(stream, i);
            }
            else
            {
                stream.WriteByte((byte)Types.TYPE_FLOAT);
                WriteNumber(floatV, stream);
            }
        }

19 Source : BinarySerializer.cs
with MIT License
from ansel86castro

private static void WriteDouble(Stream stream, double doubleV)
        {
            float floatV = (float)doubleV;
            if (floatV == doubleV)
            {
                WriteFloat(stream, floatV);
            }
            else
            {
                stream.WriteByte((byte)Types.TYPE_DOUBLE);
                WriteNumber(doubleV, stream);
            }
        }

19 Source : BinarySerializer.cs
with MIT License
from ansel86castro

private static unsafe void WriteDecimal(Stream stream, decimal decimalV)
        {
            double doubleV = (double)decimalV;
            if ((decimal)doubleV == decimalV)
            {
                WriteDouble(stream, doubleV);
            }
            else
            {
                stream.WriteByte((byte)Types.TYPE_DECIMAL);
                WriteNumber(decimalV, stream);
            }
        }

19 Source : BinarySerializer.cs
with MIT License
from ansel86castro

private void WriteLenght(Stream stream, int length, Types type1, Types type2, Types type3)
        {
            if (length >= byte.MinValue && length <= byte.MaxValue)
            {
                stream.WriteByte((byte)type1);
                WriteNumber((byte)length, stream);
            }
            else if (length >= ushort.MinValue && length <= ushort.MaxValue)
            {
                stream.WriteByte((byte)type2);
                WriteNumber((ushort)length, stream);
            }
            else
            {
                stream.WriteByte((byte)type3);
                WriteNumber(length, stream);
            }
        }

19 Source : BinarySerializer.cs
with MIT License
from ansel86castro

private void WriteLenght(Stream stream, long length, Types type1, Types type2, Types type3, Types type4)
        {
            if (length >= byte.MinValue && length <= byte.MaxValue)
            {
                stream.WriteByte((byte)type1);
                WriteNumber((byte)length, stream);
            }
            else if (length >= ushort.MinValue && length <= ushort.MaxValue)
            {
                stream.WriteByte((byte)type2);
                WriteNumber((ushort)length, stream);
            }
            else if (length >= int.MinValue && length <= int.MaxValue)
            {
                stream.WriteByte((byte)type3);
                WriteNumber((int)length, stream);
            }
            else
            {
                stream.WriteByte((byte)type4);
                WriteNumber(length, stream);
            }
        }

19 Source : BinarySerializer.cs
with MIT License
from ansel86castro

private unsafe void WriteGuid(Stream stream, Guid guid)
        {
            stream.WriteByte((byte)Types.TYPE_GUID);
            Span<byte> span = stackalloc byte[16];

            if (!guid.TryWriteBytes(span))
                throw new InvalidOperationException("Unable to serialize Guid");

            stream.Write(span);
        }

19 Source : Hash.cs
with Apache License 2.0
from AnthonyLloyd

public static void WriteBool(Stream stream, bool val)
            {
                stream.WriteByte((byte)(val ? 1 : 0));
            }

19 Source : Hash.cs
with Apache License 2.0
from AnthonyLloyd

public static void WriteUShort(Stream stream, ushort val)
            {
                stream.WriteByte((byte)val);
                stream.WriteByte((byte)(val >> 8));
            }

19 Source : Hash.cs
with Apache License 2.0
from AnthonyLloyd

public static void WriteInt(Stream stream, int val)
            {
                stream.WriteByte((byte)val);
                stream.WriteByte((byte)(val >> 8));
                stream.WriteByte((byte)(val >> 16));
                stream.WriteByte((byte)(val >> 24));
            }

19 Source : Hash.cs
with Apache License 2.0
from AnthonyLloyd

public static void WriteUInt(Stream stream, uint val)
            {
                stream.WriteByte((byte)val);
                stream.WriteByte((byte)(val >> 8));
                stream.WriteByte((byte)(val >> 16));
                stream.WriteByte((byte)(val >> 24));
            }

19 Source : Hash.cs
with Apache License 2.0
from AnthonyLloyd

public static void WriteLong(Stream stream, long val)
            {
                stream.WriteByte((byte)val);
                stream.WriteByte((byte)(val >> 8));
                stream.WriteByte((byte)(val >> 16));
                stream.WriteByte((byte)(val >> 24));
                stream.WriteByte((byte)(val >> 32));
                stream.WriteByte((byte)(val >> 40));
                stream.WriteByte((byte)(val >> 48));
                stream.WriteByte((byte)(val >> 56));
            }

19 Source : Hash.cs
with Apache License 2.0
from AnthonyLloyd

public static void WriteULong(Stream stream, ulong val)
            {
                stream.WriteByte((byte)val);
                stream.WriteByte((byte)(val >> 8));
                stream.WriteByte((byte)(val >> 16));
                stream.WriteByte((byte)(val >> 24));
                stream.WriteByte((byte)(val >> 32));
                stream.WriteByte((byte)(val >> 40));
                stream.WriteByte((byte)(val >> 48));
                stream.WriteByte((byte)(val >> 56));
            }

19 Source : Hash.cs
with Apache License 2.0
from AnthonyLloyd

public static void WriteVarint(Stream stream, uint val)
            {
                if (val < 128u) stream.WriteByte((byte)val);
                else if (val < 0x4000u)
                {
                    stream.WriteByte((byte)((val >> 7) | 128u));
                    stream.WriteByte((byte)(val & 127u));
                }
                else if (val < 0x200000u)
                {
                    stream.WriteByte((byte)((val >> 14) | 128u));
                    stream.WriteByte((byte)((val >> 7) | 128u));
                    stream.WriteByte((byte)(val & 127u));
                }
                else if (val < 0x10000000u)
                {
                    stream.WriteByte((byte)((val >> 21) | 128u));
                    stream.WriteByte((byte)((val >> 14) | 128u));
                    stream.WriteByte((byte)((val >> 7) | 128u));
                    stream.WriteByte((byte)(val & 127u));
                }
                else
                {
                    stream.WriteByte((byte)((val >> 28) | 128u));
                    stream.WriteByte((byte)((val >> 21) | 128u));
                    stream.WriteByte((byte)((val >> 14) | 128u));
                    stream.WriteByte((byte)((val >> 7) | 128u));
                    stream.WriteByte((byte)(val & 127u));
                }
            }

19 Source : Hash.cs
with Apache License 2.0
from AnthonyLloyd

public static void WriteSByte(Stream stream, sbyte val)
            {
                stream.WriteByte((byte)val);
            }

19 Source : Hash.cs
with Apache License 2.0
from AnthonyLloyd

public static void WriteByte(Stream stream, byte val)
            {
                stream.WriteByte(val);
            }

19 Source : Hash.cs
with Apache License 2.0
from AnthonyLloyd

public static void WriteShort(Stream stream, short val)
            {
                stream.WriteByte((byte)val);
                stream.WriteByte((byte)(val >> 8));
            }

19 Source : Hash.cs
with Apache License 2.0
from AnthonyLloyd

public static void WriteChar(Stream stream, char val)
            {
                var bs = BitConverter.GetBytes(val);
                stream.WriteByte((byte)bs.Length);
                stream.Write(bs, 0, bs.Length);
            }

19 Source : ZipHelperStream.cs
with GNU General Public License v3.0
from anydream

public void WriteLEShort(int value)
		{
			stream_.WriteByte((byte)(value & 0xff));
			stream_.WriteByte((byte)((value >> 8) & 0xff));
		}

19 Source : ZipHelperStream.cs
with GNU General Public License v3.0
from anydream

public void WriteLEUshort(ushort value)
		{
			stream_.WriteByte((byte)(value & 0xff));
			stream_.WriteByte((byte)(value >> 8));
		}

19 Source : FileAppender.cs
with Apache License 2.0
from apache

public override void WriteByte(byte value)
			{
				replacedertLocked();
				m_realStream.WriteByte(value);
			}

See More Examples