WriteByte() public méthode

public WriteByte ( byte value ) : void
value byte
Résultat void
 private static void WriteInt(Stream stream, int value)
 {
     stream.WriteByte((byte)(value));
     stream.WriteByte((byte)(value >> 8));
     stream.WriteByte((byte)(value >> 16));
     stream.WriteByte((byte)(value >> 24));
 }
 public override void WriteValue(Stream stream, object value, SerializerSession session)
 {
     //null = 0
     // [0]
     //length < 255 gives length + 1 as a single byte + payload
     // [B length+1] [Payload]
     //others gives 254 + int32 length + payload
     // [B 254] [I Length] [Payload]
     if (value == null)
     {
         stream.WriteByte(0);
     }
     else
     {
         var bytes = Encoding.UTF8.GetBytes((string) value);
         if (bytes.Length < 255)
         {
             stream.WriteByte((byte)(bytes.Length+1));
             stream.Write(bytes, 0, bytes.Length);
         }
         else
         {
             stream.WriteByte(254);
             stream.WriteInt32(bytes.Length);
             stream.Write(bytes,0,bytes.Length);
         }
         
     }
 }
Exemple #3
0
 public static void WriteInt(Stream outStream,int n)
 {
     outStream.WriteByte((byte)(n >> 24));
     outStream.WriteByte((byte)(n >> 16));
     outStream.WriteByte((byte)(n >> 8));
     outStream.WriteByte((byte)n);
 }
 public static void WriteUInt(Stream stream, uint value)
 {
     stream.WriteByte((byte) (value & 0xff));
     stream.WriteByte((byte) ((value >> 8) & 0xff));
     stream.WriteByte((byte) ((value >> 0x10) & 0xff));
     stream.WriteByte((byte) ((value >> 0x18) & 0xff));
 }
Exemple #5
0
 public static void OutputInt(int n, Stream s)
 {
     s.WriteByte((byte)(n >> 24));
     s.WriteByte((byte)(n >> 16));
     s.WriteByte((byte)(n >> 8));
     s.WriteByte((byte)n);
 }
Exemple #6
0
        public static void Pack(Stream stream, UInt32 value)
        {
            if (value > ZMaxValue)
                throw new ArgumentOutOfRangeException("value", value, "Must be between 0 and " + ZMaxValue);

            byte length;
            if (value <= 0x3F) length = 0;
            else if (value <= 0x3FFF) length = 1;
            else if (value <= 0x3FFFFF) length = 2;
            else length = 3;

            var b = (byte)(value << 26 >> 24);
            b = (byte)(b | length);
            stream.WriteByte(b);

            if (length == 0) return;
            b = (byte)(value << 18 >> 24);
            stream.WriteByte(b);

            if (length == 1) return;
            b = (byte)(value << 10 >> 24);
            stream.WriteByte(b);

            if (length == 2) return;
            b = (byte)(value << 2 >> 24);
            stream.WriteByte(b);
        }
Exemple #7
0
        public void Save(System.IO.Stream stream)
        {
            /*
             * It is possible we should just base this choice off the existance
             * of this.Data, but I'm not sure so I'll do it this way for now
             */

            switch (this.Type)
            {
            case JpegMarker.Soi:
            case JpegMarker.Eoi:
                stream.WriteByte(0xff);
                stream.WriteByte((byte)this.Type);
                break;

            default:
                stream.WriteByte(0xff);
                stream.WriteByte((byte)this.Type);
                ushort length = (ushort)(this.Data.Length + 2);

                byte [] len = FSpot.BitConverter.GetBytes(length, false);
                stream.Write(len, 0, len.Length);

                //workaround for mono bug: http://bugzilla.ximian.com/show_bug.cgi?id=82836
                if (this.Data.Length > 0)
                {
                    stream.Write(this.Data, 0, this.Data.Length);
                }
                break;
            }
        }
		public void Marshal (Stream stream)
		{
			Debug.WriteLineIf (Marshaler.marshalSwitch.Enabled, "ShortString.Marshal ()");
			stream.WriteByte ((byte) BoxTag.DV_SHORT_STRING_SERIAL);
			stream.WriteByte ((byte) bytes.Length);
			stream.Write (bytes, 0, bytes.Length);
		}
 public ZlibDeflateStream(Stream stream, int compressionLevel)
 {
     rawStream = stream;
     int cmf = 0x78;
     int flg = 218;
     if (compressionLevel >= 5 && compressionLevel <= 6){
         flg = 156;
     } else if (compressionLevel >= 3 && compressionLevel <= 4){
         flg = 94;
     } else if (compressionLevel <= 2){
         flg = 1;
     }
     flg -= (cmf*256 + flg)%31;
     if (flg < 0){
         flg += 31;
     }
     rawStream.WriteByte((byte) cmf);
     rawStream.WriteByte((byte) flg);
     CompressionLevel level = CompressionLevel.Optimal;
     if (compressionLevel >= 1 && compressionLevel <= 5){
         level = CompressionLevel.Fastest;
     } else if (compressionLevel == 0){
         level = CompressionLevel.NoCompression;
     }
     deflateStream = new DeflateStream(rawStream, level, true);
 }
Exemple #10
0
 public static void WriteBeUint32(Stream stm, uint u)
 {
     stm.WriteByte((byte)(u >> 24));
     stm.WriteByte((byte)(u >> 16));
     stm.WriteByte((byte)(u >> 8));
     stm.WriteByte((byte)(u));
 }
Exemple #11
0
 public void Encode(Stream stream)
 {
     stream.WriteByte((byte) initialCodeSize);
     curPixel = 0;
     Compress(initialCodeSize + 1, stream);
     stream.WriteByte(GifConstants.terminator);
 }
Exemple #12
0
 public void WriteInt(uint val, Stream s)
 {
     s.WriteByte((byte)(0xff & val));
     s.WriteByte((byte)(0xff & (val >> 8)));
     s.WriteByte((byte)(0xff & (val >> 16)));
     s.WriteByte((byte)(0xff & (val >> 24)));
 }
Exemple #13
0
 public static void writeVarInt(System.IO.Stream stream, UInt64 value)
 {
     if (value > 0xffffffff)
     {
         stream.WriteByte((byte)(0xff));
         var bs = BitConverter.GetBytes(value);
         stream.Write(bs, 0, 8);
     }
     else if (value > 0xffff)
     {
         stream.WriteByte((byte)(0xfe));
         var bs = BitConverter.GetBytes((UInt32)value);
         stream.Write(bs, 0, 4);
     }
     else if (value > 0xfc)
     {
         stream.WriteByte((byte)(0xfd));
         var bs = BitConverter.GetBytes((UInt16)value);
         stream.Write(bs, 0, 2);
     }
     else
     {
         stream.WriteByte((byte)value);
     }
 }
        public void Write(Stream fs, bool comFiles)
        {
            //beginning of the uninstall file info
            if (comFiles)
                fs.WriteByte(0x8B);
            else
                fs.WriteByte(0x8A);

            //path to the file
            WriteFiles.WriteDeprecatedString(fs, 0x01, Path);

            //delete the file?
            if (DeleteFile)
                WriteFiles.WriteBool(fs, 0x02, true);

            if (UnNGENFile)
            {
                WriteFiles.WriteBool(fs, 0x03, true);

                // the CPU version of the file to un-ngen
                WriteFiles.WriteInt(fs, 0x04, (int) CPUVersion);

                WriteFiles.WriteInt(fs, 0x05, (int)FrameworkVersion);
            }

            if (RegisterCOMDll != COMRegistration.None)
                WriteFiles.WriteInt(fs, 0x06, (int) RegisterCOMDll);

            //end of uninstall file info
            fs.WriteByte(0x9A);
        }
Exemple #15
0
 public async Task WriteAsync(Stream stream, TagVersion version)
 {
     byte[] contentBytes = GetContentBytes(version);
     
     var tagId = Encoding.Default.GetBytes(GetTagId(version)); 
     await stream.WriteAsync(tagId, 0, tagId.Length).ConfigureAwait(false);
     switch (version)
     {
         case TagVersion.V23:
             stream.WriteByte((byte)((contentBytes.Length / (256 * 256 * 256))));
             stream.WriteByte((byte)((contentBytes.Length % (256 * 256 * 256)) / (256 * 256)));
             stream.WriteByte((byte)((contentBytes.Length % (256 * 256)) / 256));
             stream.WriteByte((byte)((contentBytes.Length % 256)));
             break;
         case TagVersion.V24:
             stream.WriteByte((byte)((contentBytes.Length / (128 * 128 * 128))));
             stream.WriteByte((byte)((contentBytes.Length % (128 * 128 * 128)) / (128 * 128)));
             stream.WriteByte((byte)((contentBytes.Length % (128 * 128)) / 128));
             stream.WriteByte((byte)((contentBytes.Length % 128)));
             break;
         default:
             throw new ArgumentException($"Unable to write frame with version {version}", nameof(version));
     }
     stream.WriteByte(0x00);
     stream.WriteByte(0x00);
     await stream.WriteAsync(contentBytes, 0, contentBytes.Length).ConfigureAwait(false);
 }
Exemple #16
0
        static void UrlEncodeChar (char c, Stream result, bool isUnicode) {
            if (c > ' ' && NotEncoded (c)) {
                result.WriteByte ((byte)c);
                return;
            }
            if (c==' ') {
                result.WriteByte ((byte)'+');
                return;
            }
            if (    (c < '0') ||
                (c < 'A' && c > '9') ||
                (c > 'Z' && c < 'a') ||
                (c > 'z')) {
                if (isUnicode && c > 127) {
                    result.WriteByte ((byte)'%');
                    result.WriteByte ((byte)'u');
                    result.WriteByte ((byte)'0');
                    result.WriteByte ((byte)'0');
                }
                else
                    result.WriteByte ((byte)'%');

                int idx = ((int) c) >> 4;
                result.WriteByte ((byte)hexChars [idx]);
                idx = ((int) c) & 0x0F;
                result.WriteByte ((byte)hexChars [idx]);
            }
            else {
                result.WriteByte ((byte)c);
            }
        }
 public void Serialise(System.IO.Stream stream, Version version)
 {
     stream.WriteByte((byte)(255 - _ServerVersion.Major));
     stream.WriteByte((byte)(255 - _ServerVersion.Minor));
     stream.WriteByte((byte)_Cookie.Length);
     stream.Write(_Cookie, 0, _Cookie.Length);
 }
Exemple #18
0
 public static void SaveColorToStream(System.IO.Stream AStream, Color color)
 {
     AStream.WriteByte(color.A);
     AStream.WriteByte(color.R);
     AStream.WriteByte(color.G);
     AStream.WriteByte(color.B);
 }
Exemple #19
0
 // write a LE doubleword
 public static void WriteDWord(Stream fs, uint dword)
 {
     fs.WriteByte ((byte)(dword & 0xff));
     fs.WriteByte ((byte)((dword >> 8) & 0xff));
     fs.WriteByte ((byte)((dword >> 16) & 0xff));
     fs.WriteByte ((byte)((dword >> 24) & 0xff));
 }
Exemple #20
0
		private static void WriteLength(
            Stream	outStr,
            int		length)
        {
            if (length > 127)
            {
                int size = 1;
                int val = length;

				while ((val >>= 8) != 0)
                {
                    size++;
                }

				outStr.WriteByte((byte)(size | 0x80));

				for (int i = (size - 1) * 8; i >= 0; i -= 8)
                {
                    outStr.WriteByte((byte)(length >> i));
                }
            }
            else
            {
                outStr.WriteByte((byte)length);
            }
        }
Exemple #21
0
        public override void GetBytes(Vector4sb[] source, int index, int width, int height, System.IO.Stream destination, int rowPitch, int slicePitch, Boxi sourceBoxi, Point3i destinationPoint)
        {
            //seek to start
            destination.Seek(
                destinationPoint.X * 4 + destinationPoint.Y * rowPitch + destinationPoint.Z * slicePitch,
                System.IO.SeekOrigin.Current);

            for (int z = 0; z < sourceBoxi.Depth; ++z)
            {
                int zindex = index + (sourceBoxi.Z + z) * (height * width);

                for (int y = 0; y < sourceBoxi.Height; ++y)
                {
                    int xyindex = sourceBoxi.X + (sourceBoxi.Y + y) * width + zindex;

                    //write scan line
                    for (int x = 0; x < sourceBoxi.Width; ++x)
                    {
                        Vector4sb color = source[xyindex++];

                        destination.WriteByte((byte)color.X);
                        destination.WriteByte((byte)color.Y);
                        destination.WriteByte((byte)color.Z);
                        destination.WriteByte((byte)color.W);
                    }

                    //seek to next scan line
                    destination.Seek(rowPitch - sourceBoxi.Width * 4, System.IO.SeekOrigin.Current);
                }

                //seek to next scan slice
                destination.Seek(slicePitch - sourceBoxi.Height * rowPitch, System.IO.SeekOrigin.Current);
            }
        }
        public void Save(System.IO.Stream stream)
        {
            /*
             * It is possible we should just base this choice off the existance
             * of this.Data, but I'm not sure so I'll do it this way for now
             */

            switch (this.Type)
            {
            case JpegMarker.Soi:
            case JpegMarker.Eoi:
                stream.WriteByte(0xff);
                stream.WriteByte((byte)this.Type);
                break;

            default:
                stream.WriteByte(0xff);
                stream.WriteByte((byte)this.Type);
                ushort length = (ushort)(this.Data.Length + 2);

                byte [] len = FSpot.BitConverter.GetBytes(length, false);
                stream.Write(len, 0, len.Length);

                stream.Write(this.Data, 0, this.Data.Length);
                break;
            }
        }
Exemple #23
0
 public static void WriteBgra(Stream output, Color color)
 {
     output.WriteByte(color.B);
     output.WriteByte(color.G);
     output.WriteByte(color.R);
     output.WriteByte(color.A);
 }
Exemple #24
0
        public static void PackU(Stream stream, UInt32? nullableValue)
        {
            byte length;
            if (!nullableValue.HasValue) {
                stream.WriteByte(7);
                return;
            }
            var value = nullableValue.Value;
            if (value <= 0x1FU) length = 0;
            else if (value <= 0x1FFFU) length = 1;
            else if (value <= 0x1FFFFFU) length = 2;
            else if (value <= 0x1FFFFFFFU) length = 3;
            else length = 4;

            var b = (byte)(value << 27 >> 24);
            b = (byte)(b | length);
            stream.WriteByte(b);

            if (length == 0) return;
            b = (byte)(value << 19 >> 24);
            stream.WriteByte(b);

            if (length == 1) return;
            b = (byte)(value << 11 >> 24);
            stream.WriteByte(b);

            if (length == 2) return;
            b = (byte)(value << 3 >> 24);
            stream.WriteByte(b);

            if (length == 3) return;
            b = (byte)(value >> 29);
            stream.WriteByte(b);
        }
        public void Encode(Stream os)
        {
            var bodyLen = Data.Length + 1;

            if (bodyLen < 192)
            {
                os.WriteByte((byte)bodyLen);
            }
            else if (bodyLen <= 8383)
            {
                bodyLen -= 192;

                os.WriteByte((byte)(((bodyLen >> 8) & 0xff) + 192));
                os.WriteByte((byte)bodyLen);
            }
            else
            {
                os.WriteByte(0xff);
                os.WriteByte((byte)(bodyLen >> 24));
                os.WriteByte((byte)(bodyLen >> 16));
                os.WriteByte((byte)(bodyLen >> 8));
                os.WriteByte((byte)bodyLen);
            }

            if (_critical)
            {
                os.WriteByte((byte)(0x80 | (int)_type));
            }
            else
            {
                os.WriteByte((byte)_type);
            }

            os.Write(Data, 0, Data.Length);
        }
 public override void Write(Stream outputStream)
 {
     base.Write(outputStream);
     outputStream.WriteByte(2);
     outputStream.WriteByte((byte) ((this._number & 0xff00) >> 8));
     outputStream.WriteByte((byte) (this._number & 0xff));
 }
Exemple #27
0
 public static void HCSaveColorToStream(System.IO.Stream aStream, Color color)
 {
     aStream.WriteByte(color.A);
     aStream.WriteByte(color.R);
     aStream.WriteByte(color.G);
     aStream.WriteByte(color.B);
 }
Exemple #28
0
 public static void WriteVariableByte(Stream dst, uint value)
 {
     if ((value & 0xF0000000) != 0) throw new Exception();
     if ((value & ~0x7F) == 0)
     {
         dst.WriteByte((byte)value);
         return;
     }
     if ((value & ~0x1FFF) == 0)
     {
         dst.WriteByte((byte)((value >> 7) | 0x80));
         dst.WriteByte((byte)(value & 0x7F));
         return;
     }
     if ((value & ~0x1FFFFF) == 0)
     {
         dst.WriteByte((byte)((value >> 14) | 0x80));
         dst.WriteByte((byte)(((value >> 7) & 0x7F) | 0x80));
         dst.WriteByte((byte)(value & 0x7F));
         return;
     }
     dst.WriteByte((byte)((value >> 21) | 0x80));
     dst.WriteByte((byte)((value >> 14) | 0x80));
     dst.WriteByte((byte)(((value >> 7) & 0x7F) | 0x80));
     dst.WriteByte((byte)(value & 0x7F));
 }
        public void SaveToStream(Stream fs, bool saveRelativePath)
        {
            fs.WriteByte(0x8D);

            if (!string.IsNullOrEmpty(Path))
                WriteFiles.WriteDeprecatedString(fs, 0x01, Path);

            if (!string.IsNullOrEmpty(WorkingDirectory))
                WriteFiles.WriteDeprecatedString(fs, 0x02, WorkingDirectory);

            if (!string.IsNullOrEmpty(Arguments))
                WriteFiles.WriteDeprecatedString(fs, 0x03, Arguments);

            if (!string.IsNullOrEmpty(Description))
                WriteFiles.WriteDeprecatedString(fs, 0x04, Description);

            if (!string.IsNullOrEmpty(IconPath))
                WriteFiles.WriteDeprecatedString(fs, 0x05, IconPath);

            WriteFiles.WriteInt(fs, 0x06, IconIndex);
            WriteFiles.WriteInt(fs, 0x07, (int)WindowStyle);

            if (saveRelativePath)
                WriteFiles.WriteDeprecatedString(fs, 0x08, RelativeOuputPath);

            fs.WriteByte(0x9A);
        }
Exemple #30
0
 /// <summary>
 /// Write unsigned integer into the stream
 /// </summary>
 public static void WriteUInt(Stream destination, uint value)
 {
     destination.WriteByte((byte)value);
     destination.WriteByte((byte)(value >> 8));
     destination.WriteByte((byte)(value >> 16));
     destination.WriteByte((byte)(value >> 24));
 }
Exemple #31
0
		static void WriteVarint32(Stream stream, uint value)
		{
			for (; value >= 0x80u; value >>= 7)
				stream.WriteByte((byte)(value | 0x80u));

			stream.WriteByte((byte)value);
		}
    // **********************************************************************

    public static void Write(Stream stream, long value)
    {
      if(value >= 0)
        for(; ; )
        {
          int b = (int)(value & 0x7f);
          value >>= 7;

          if(value == 0 && (b & 0x40) == 0)
          {
            stream.WriteByte((byte)b);
            return;
          }

          stream.WriteByte((byte)(b | 0x80));
        }
      else
        for(; ; )
        {
          int b = (int)(value & 0x7f);
          value >>= 7;

          if(value == -1 && (b & 0x40) != 0)
          {
            stream.WriteByte((byte)b);
            return;
          }

          stream.WriteByte((byte)(b | 0x80));
        }
    }
		/**
		* encode the input data producing a base 64 output stream.
		*
		* @return the number of bytes produced.
		*/
		public int Encode(
			byte[]	data,
			int		off,
			int		length,
			Stream	outStream)
		{
			int modulus = length % 3;
			int dataLength = (length - modulus);
			int a1, a2, a3;

			for (int i = off; i < off + dataLength; i += 3)
			{
				a1 = data[i] & 0xff;
				a2 = data[i + 1] & 0xff;
				a3 = data[i + 2] & 0xff;

				outStream.WriteByte(encodingTable[(int) ((uint) a1 >> 2) & 0x3f]);
				outStream.WriteByte(encodingTable[((a1 << 4) | (int) ((uint) a2 >> 4)) & 0x3f]);
				outStream.WriteByte(encodingTable[((a2 << 2) | (int) ((uint) a3 >> 6)) & 0x3f]);
				outStream.WriteByte(encodingTable[a3 & 0x3f]);
			}

			/*
			* process the tail end.
			*/
			int b1, b2, b3;
			int d1, d2;

			switch (modulus)
			{
				case 0:        /* nothing left to do */
					break;
				case 1:
					d1 = data[off + dataLength] & 0xff;
					b1 = (d1 >> 2) & 0x3f;
					b2 = (d1 << 4) & 0x3f;

					outStream.WriteByte(encodingTable[b1]);
					outStream.WriteByte(encodingTable[b2]);
					outStream.WriteByte(padding);
					outStream.WriteByte(padding);
					break;
				case 2:
					d1 = data[off + dataLength] & 0xff;
					d2 = data[off + dataLength + 1] & 0xff;

					b1 = (d1 >> 2) & 0x3f;
					b2 = ((d1 << 4) | (d2 >> 4)) & 0x3f;
					b3 = (d2 << 2) & 0x3f;

					outStream.WriteByte(encodingTable[b1]);
					outStream.WriteByte(encodingTable[b2]);
					outStream.WriteByte(encodingTable[b3]);
					outStream.WriteByte(padding);
					break;
			}

			return (dataLength / 3) * 4 + ((modulus == 0) ? 0 : 4);
		}
Exemple #34
0
        public static void PackS(Stream stream, Int64? nullableValue)
        {
            if (!nullableValue.HasValue) {
                stream.WriteByte(15);
                return;
            }

            var value = nullableValue.Value;
            var isNegative = value < 0;
            var bits = isNegative ? ((UInt64)value) ^ UInt64.MaxValue : ((UInt64)value);
            var signedBit = isNegative ? (byte)16 : (byte)0;

            byte length;
            if (bits <= 0x7U) length = 0;
            else if (bits <= 0x7FFU) length = 1;
            else if (bits <= 0x7FFFFU) length = 2;
            else if (bits <= 0x7FFFFFFU) length = 3;
            else if (bits <= 0x7FFFFFFFFU) length = 4;
            else if (bits <= 0x7FFFFFFFFFFU) length = 5;
            else if (bits <= 0x7FFFFFFFFFFFFU) length = 6;
            else if (bits <= 0x7FFFFFFFFFFFFFFU) length = 7;
            else length = 8;

            var b = (byte)(bits << 61 >> 56);
            b = (byte)(b | length | signedBit);
            stream.WriteByte(b);

            if (length == 0) return;
            b = (byte)(bits << 53 >> 56);
            stream.WriteByte(b);

            if (length == 1) return;
            b = (byte)(bits << 45 >> 56);
            stream.WriteByte(b);

            if (length == 2) return;
            b = (byte)(bits << 37 >> 56);
            stream.WriteByte(b);

            if (length == 3) return;
            b = (byte)(bits << 29 >> 56);
            stream.WriteByte(b);

            if (length == 4) return;
            b = (byte)(bits << 21 >> 56);
            stream.WriteByte(b);

            if (length == 5) return;
            b = (byte)(bits << 13 >> 56);
            stream.WriteByte(b);

            if (length == 6) return;
            b = (byte)(bits << 5 >> 56);
            stream.WriteByte(b);

            if (length == 7) return;
            b = (byte)(bits >> 59);
            stream.WriteByte(b);
        }
Exemple #35
0
 public void Encode(Stream os)
 {
     os.WriteByte(Convert.ToByte(this.initCodeSize));
     this.remaining = this.imgW * this.imgH;
     this.curPixel = 0;
     this.Compress(this.initCodeSize + 1, os);
     os.WriteByte(0);
 }
Exemple #36
0
        public override void WriteBytes(Stream wr)
        {
            base.WriteBytes(wr);

            // For CheckSum
            wr.WriteByte(0);
            wr.WriteByte(0);
        }
Exemple #37
0
 public void Encode(System.IO.Stream os)
 {
     os.WriteByte(Convert.ToByte(this.initCodeSize));
     this.remaining = this.imgW * this.imgH;
     this.curPixel  = 0;
     this.Compress(this.initCodeSize + 1, os);
     os.WriteByte(0);
 }
 public override void Write(Stream outputStream)
 {
     base.Write(outputStream);
     outputStream.WriteByte(3);
     outputStream.WriteByte((byte) ((this._tempo & 0xff0000) >> 0x10));
     outputStream.WriteByte((byte) ((this._tempo & 0xff00) >> 8));
     outputStream.WriteByte((byte) (this._tempo & 0xff));
 }
Exemple #39
0
 internal override void Write(IO.Stream ostream)
 {
     ostream.WriteByte((int)'l');
     foreach (BEncode.Element element in this.list)
     {
         element.Write(ostream);
     }
     ostream.WriteByte((int)'e');
 }
Exemple #40
0
        public static void SaveIntoStream(System.IO.Stream stream, double[] sampleData, long sampleCount)
        {
            // Export
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
            int   RIFF             = 0x46464952;
            int   WAVE             = 0x45564157;
            int   formatChunkSize  = 16;
            int   headerSize       = 8;
            int   format           = 0x20746D66;
            short formatType       = 1;
            short tracks           = 2;
            int   samplesPerSecond = 44100;
            short bitsPerSample    = 16;
            short frameSize        = (short)(tracks * ((bitsPerSample + 7) / 8));
            int   bytesPerSecond   = samplesPerSecond * frameSize;
            int   waveSize         = 4;
            int   data             = 0x61746164;
            int   samples          = (int)sampleCount;
            int   dataChunkSize    = samples * frameSize;
            int   fileSize         = waveSize + headerSize + formatChunkSize + headerSize + dataChunkSize;

            writer.Write(RIFF);
            writer.Write(fileSize);
            writer.Write(WAVE);
            writer.Write(format);
            writer.Write(formatChunkSize);
            writer.Write(formatType);
            writer.Write(tracks);
            writer.Write(samplesPerSecond);
            writer.Write(bytesPerSecond);
            writer.Write(frameSize);
            writer.Write(bitsPerSample);
            writer.Write(data);
            writer.Write(dataChunkSize);

            double sample_l;
            short  sl;

            for (int i = 0; i < sampleCount; i++)
            {
                sample_l = sampleData[i] * 30000.0;
                if (sample_l < -32767.0f)
                {
                    sample_l = -32767.0f;
                }
                if (sample_l > 32767.0f)
                {
                    sample_l = 32767.0f;
                }
                sl = (short)sample_l;
                stream.WriteByte((byte)(sl & 0xff));
                stream.WriteByte((byte)(sl >> 8));
                stream.WriteByte((byte)(sl & 0xff));
                stream.WriteByte((byte)(sl >> 8));
            }
        }
Exemple #41
0
 internal override void Write(IO.Stream ostream)
 {
     ostream.WriteByte((int)'d');
     foreach (BEncode.String key in this.map.Keys)
     {
         key.Write(ostream);
         ((BEncode.Element) this.map[key]).Write(ostream);
     }
     ostream.WriteByte((int)'e');
 }
Exemple #42
0
 public void WriteTo(System.IO.Stream s)
 {
     s.WriteByte(flag);
     s.WriteByte(image_disc_layer_no);
     s.WriteByte(req_locus);
     s.Position += 0xB;
     s.WriteUInt16LE(mchunk_count);
     s.WriteUInt64LE(language_mask);
     s.WriteUInt32LE(mchunks_offset);
     s.WriteUInt32LE(label_offset);
 }
Exemple #43
0
 public static void Write(System.IO.Stream stream, bool value)
 {
     if (value)
     {
         stream.WriteByte((byte)1);
     }
     else
     {
         stream.WriteByte((byte)0);
     }
 }
            public static void WriteInt32(System.IO.Stream stream, int value)
            {
                //m_Buffer[0] = (byte)(value >> 24);
                //m_Buffer[1] = (byte)(value >> 16);
                //m_Buffer[2] = (byte)(value >>  8);
                //m_Buffer[3] = (byte) value;

                //m_Stream.Write( m_Buffer, 0, 4 );
                stream.WriteByte((byte)(value));
                stream.WriteByte((byte)(value >> 8));
                stream.WriteByte((byte)(value >> 16));
                stream.WriteByte((byte)(value >> 24));
            }
            public unsafe static void WriteFloat(System.IO.Stream stream, float f)
            {
                int v = (*((int *)&f));

                byte a = ((byte)(v));
                byte b = ((byte)(v >> 8));
                byte c = ((byte)(v >> 16));
                byte d = ((byte)(v >> 24));

                stream.WriteByte(a);
                stream.WriteByte(b);
                stream.WriteByte(c);
                stream.WriteByte(d);
            }
Exemple #46
0
        public void SerializeUnsigned(System.IO.Stream writer)
        {
            writer.WriteByte(version);
            writer.WriteByte(0xd1);
            writer.Write(BitConverter.GetBytes(nonce), 0, 4);
            writer.Write(BitConverter.GetBytes(gasPrice), 0, 8);
            writer.Write(BitConverter.GetBytes(gasLimit), 0, 8);
            writer.Write(payer.data, 0, 20);
            var len = payload.serialize().Length;

            writeVarInt(writer, (ulong)len);
            writer.Write(payload.serialize(), 0, len);
            writeVarInt(writer, (ulong)0);
        }
        private static bool WriteXyzHeadVer01(System.IO.Stream stream, XyzHeadReader xyzHead)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (xyzHead == null)
            {
                throw new ArgumentNullException("xyzHead");
            }

            byte[] byteULong = new byte[8];

            // 00 ~ 03: 标识符号 : 是否是XYZ的标识(写入)
            stream.Write(xyzHead.Tag, 0, xyzHead.Tag.Length);

            // 03 ~ 04: XYZ文件版本号(写入)
            stream.WriteByte((byte)xyzHead.Version);

            // 04 ~ 05: XYZ文件内实体名称的加密方式 ( 0 为无加密, 1... 为其它加密方式 )(写入)
            stream.WriteByte((byte)xyzHead.EncryptType);

            // 05 ~ 13: 主评论信息的文件偏移(写入)
            xyzHead.CommentOffset.ToArrayInByte(ref byteULong, 0);
            stream.Write(byteULong, 0, byteULong.Length);

            // 13 ~ 21: 第一个XYZ文件内实体的文件偏移(写入)
            xyzHead.FirstEntryOffset.ToArrayInByte(ref byteULong, 0);
            stream.Write(byteULong, 0, byteULong.Length);

            // XYZ文件内实体评论的信息(写入)
            if (xyzHead.CommentReader == null)
            {
                if (xyzHead.CommentOffset > 0)
                {
                    throw new ArgumentException("xyzHead.CommentReader == null && xyzHead.CommentOffset > 0 error!", "xyzComment.CommentReader & xyzComment.CommentOffset");
                }
                else
                {
                    return(true);
                }
            }

            stream.Seek((long)xyzHead.CommentOffset, SeekOrigin.Begin);
            XyzCommentWriter.WriteComment(stream, xyzHead.CommentReader);

            return(true);
        }
Exemple #48
0
        /// <summary>
        /// Serializes to a stream.
        /// </summary>
        public long Serialize(System.IO.Stream stream)
        {
            this.Compress();

            // serialize geometric graph.
            long size = 1;

            // write the version #.
            // v1->v2: Added maxEdgeDistance.
            stream.WriteByte(2);

            // write maxEdgeDistance.
            var bytes = BitConverter.GetBytes(_maxEdgeDistance);

            stream.Write(bytes, 0, 4);
            size += 4;

            // write graph.
            size += _graph.Serialize(stream);

            // serialize edge data.
            _edgeData.CopyTo(stream);
            size += _edgeData.Length * 4;

            return(size);
        }
Exemple #49
0
        private void WriteTail()
        {
            var metadata = _stripeWriter.GetMetadata();
            var footer   = _stripeWriter.GetFooter();

            footer.HeaderLength = (ulong)_magic.Length;

            long metadataLength, footerLength;

            _bufferFactory.SerializeAndCompressTo(_outputStream, metadata, out metadataLength);
            _bufferFactory.SerializeAndCompressTo(_outputStream, footer, out footerLength);

            var postScript       = GetPostscript((ulong)footerLength, (ulong)metadataLength);
            var postScriptStream = new MemoryStream();

            StaticProtoBuf.Serializer.Serialize(postScriptStream, postScript);
            postScriptStream.Seek(0, SeekOrigin.Begin);
            postScriptStream.CopyTo(_outputStream);

            if (postScriptStream.Length > 255)
            {
                throw new InvalidDataException("Invalid Postscript length");
            }

            _outputStream.WriteByte((byte)postScriptStream.Length);
        }
        private static void _WriteToStream(System.IO.Stream s, ReadOnlySpan <Byte> data, int compression)
        {
            if (compression == 1)
            {
                using (var ss = new System.IO.Compression.DeflateStream(s, System.IO.Compression.CompressionLevel.Fastest, true))
                {
                    _WriteToStream(ss, data, 0);
                }

                return;
            }

            if (compression == 0)
            {
                #if NETSTANDARD2_0
                for (int i = 0; i < data.Length; ++i)
                {
                    s.WriteByte(data[i]);
                }
                #else
                s.Write(data);
                #endif

                return;
            }

            throw new ArgumentException("invalid compression", nameof(compression));
        }
Exemple #51
0
        private static void SendMessageHeader(IO.Stream stream, PeerMessage type, int length)
        {
//			Config.LogDebugMessage("Message sent: " + type.ToString());

            WriteInt(stream, length + 1);
            stream.WriteByte((byte)type);
        }
Exemple #52
0
        private void WriteCommand(IEnumerable <string> commandRows)
        {
            try
            {
                foreach (string row in commandRows)
                {
                    byte[] bytes  = _encoding.GetBytes(row.ToCharArray());
                    byte[] length = ApiConnectionHelper.EncodeLength(bytes.Length);

                    _tcpConnectionStream.Write(length, 0, length.Length); //write length of comming sentence
                    _tcpConnectionStream.Write(bytes, 0, bytes.Length);   //write sentence body

                    if (OnWriteRow != null)
                    {
                        OnWriteRow(this, new TikConnectionCommCallbackEventArgs(row));
                    }
                    if (DebugEnabled)
                    {
                        System.Diagnostics.Debug.WriteLine("> " + row);
                    }
                }

                _tcpConnectionStream.WriteByte(0); //final zero byte
            }
            catch (IOException)
            {
                _isOpened = _tcpConnection.Connected;
                throw;
            }
        }
Exemple #53
0
        /// <summary>
        /// Outputs the scheme in the Worms Armageddon scheme format.
        /// </summary>
        /// <param name="stream"></param>
        public void Serialise(System.IO.Stream stream)
        {
            stream.Write(SchemeFileMagicNumber, 0, SchemeFileMagicNumber.Length);

            foreach (Setting setting in Settings)
            {
                setting.Serialise(stream);
            }

            foreach (Weapon weapon in Weapons)
            {
                weapon.Serialise(stream);
            }

            if (ExtendedOptions != null)
            {
                foreach (Setting extendedOption in ExtendedOptions)
                {
                    extendedOption.Serialise(stream);
                }
            }

            if (Version == SchemeVersion.WorldParty)
            {
                stream.Write(new byte[3], 0, 3);
                stream.Write(SchemeFileMagicNumber, 0, SchemeFileMagicNumber.Length);
                stream.WriteByte(1);
            }
        }
Exemple #54
0
        public static void Decompress(Stream instream, Stream outstream)
        {
            System.IO.Stream bos = outstream;
            System.IO.Stream bis = instream;
            int b = bis.ReadByte();

            if (b != 'B')
            {
                return;
            }
            b = bis.ReadByte();
            if (b != 'Z')
            {
                return;
            }
            BZip2InputStream bzis = new BZip2InputStream(bis);
            int ch = bzis.ReadByte();

            while (ch != -1)
            {
                bos.WriteByte((byte)ch);
                ch = bzis.ReadByte();
            }
            bos.Flush();
        }
        internal static void DelimWrite(System.IO.Stream stream, byte[] message)
        {
            Binary.Varint.Write(stream, (ulong)(message.Length + 1));

            stream.Write(message, 0, message.Length);
            stream.WriteByte(Delimiter);
        }
Exemple #56
0
        public static void WriteByte(this System.IO.Stream ms, int position, byte value)
        {
            long prevPosition = ms.Position;

            ms.Position = position;
            ms.WriteByte(value);
            ms.Position = prevPosition;
        }
Exemple #57
0
        public static void Compress(Stream instream, Stream outstream, int blockSize)
        {
            System.IO.Stream bos = outstream;
            bos.WriteByte((byte)'B');
            bos.WriteByte((byte)'Z');
            System.IO.Stream bis = instream;
            int ch = bis.ReadByte();
            BZip2OutputStream bzos = new BZip2OutputStream(bos);

            while (ch != -1)
            {
                bzos.WriteByte((byte)ch);
                ch = bis.ReadByte();
            }
            bis.Close();
            bzos.Close();
        }
Exemple #58
0
 /// <summary>
 /// Write the byte array to the output stream
 ///
 /// </summary>
 /// <param name="bytes">
 /// </param>
 /// <param name="out">
 /// </param>
 /// <throws>  IOException </throws>
 public static void writeToOutput(sbyte[] bytes, System.IO.Stream out_Renamed, long[] tally)
 {
     for (int i = 0; i < bytes.Length; i++)
     {
         out_Renamed.WriteByte((byte)bytes[i]);
         incr(tally);
     }
 }
Exemple #59
0
        protected override void SendPayload(System.IO.Stream str)
        {
            WriteToStream(str, _ackID);

            str.WriteByte(_commondId);
            WriteToStream(str, _leftLength);

            str.Write(_payload, 0, _payload.Length);
        }
Exemple #60
0
 public void WriteTo(System.IO.Stream s)
 {
     s.WriteByte(type);
     s.Position += 0x13;
     s.WriteUInt16BE(initial_chunk_count);
     s.WriteUInt16LE(chunk_count);
     s.WriteUInt32LE(chunks_offset);
     s.WriteUInt32LE(label_offset);
 }