Пример #1
0
        public void Write(int identifier, System.IO.Stream stream)
        {
            byte[] buffer;

            // Command
            stream.WriteByte(1);

            // Identifier
            buffer = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(identifier));
            stream.Write(buffer, 0, buffer.Length);

            // Expiry
            buffer = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(expiry));
            stream.Write(buffer, 0, buffer.Length);

            // Token length
            stream.WriteByte(0);
            stream.WriteByte(tokenLength);

            // Device token
            stream.Write(deviceToken, 0, tokenLength);

            // Payload length
            buffer = payload.ToBytes();
            stream.WriteByte(0);
            stream.WriteByte((byte) buffer.Length);

            // Payload
            stream.Write(buffer, 0, buffer.Length);
        }
Пример #2
0
		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);
		}
Пример #3
0
 public override void WriteToStream(System.IO.Stream stream)
 {
     byte[] buffer=Encoding.BigEndianUnicode.GetBytes(this.Text);
     stream.Write(buffer, 0, buffer.Length);	// char data
     stream.WriteByte(0);					// null terminator
     stream.WriteByte(0);					// null terminator
 }
Пример #4
0
 private static void EncodePEMLength(System.IO.Stream s, uint length)
 {
     s.WriteByte((byte)((length >> 24) & 0xff));
     s.WriteByte((byte)((length >> 16) & 0xff));
     s.WriteByte((byte)((length >> 8) & 0xff));
     s.WriteByte((byte)(length & 0xff));
 }
Пример #5
0
        public void SendData(System.IO.Stream stream)
        {
            int n = AssociatedAnimation.CubeSize;
            stream.WriteByte (LEDCore.ESC);
            stream.WriteByte (LEDCore.SYNC);

            for(int layer = 0; layer < n; layer++)
            {
                for(int x = 0; x < n; x++)
                {

                    for (int y = 0; y < n; y++)
                    {
                        if (FrameData [layer, x, y]) {

                            //TODO: fix maxsize from 16x16x16 to nxnxn (split to multiple bytes)
                            if ((byte)layer == LEDCore.ESC) {
                                stream.WriteByte (LEDCore.ESC);
                            }

                            stream.WriteByte ((byte)layer);

                            if ((byte)(x + n * y) == LEDCore.ESC) {
                                stream.WriteByte (LEDCore.ESC);
                            }

                            stream.WriteByte ((byte)(x + n * y));
                        }
                    }
                }
            }
        }
Пример #6
0
		public void Serialise(System.IO.Stream stream, Version version)
		{
            if (_PublicKeyBytes == null)
            {
                stream.WriteByte(0);
            }
            else
            {
                stream.WriteByte((byte)_PublicKeyBytes.Length);
                stream.Write(_PublicKeyBytes, 0, _PublicKeyBytes.Length);
            }
		}
        private static bool WriteCommentVer01( System.IO.Stream stream, XyzCommentReader xyzComment )
        {
            if ( stream == null )
                throw new ArgumentNullException( "stream" );

            if ( xyzComment == null )
                throw new ArgumentNullException( "xyzComment" );

            byte[] byteULong = new byte[8];

            // 00 ~ 01: 标识符号 : 是否是评论信息的标识( 0x02 标识为评论信息 )(写入)
            stream.WriteByte( xyzComment.Tag );

            // 01 ~ 02: 评论信息的版本号 ( 当前支持 0x01 版本 )(写入)
            stream.WriteByte( (byte)xyzComment.Version );

            // 02 ~ 10: 对应XYZ文件内实体的唯一序号 ( 0 为XYZ主文件的主要评论信息, 1... 为其它XYZ文件内实体的评论信息 )(写入)
            xyzComment.EntryId.ToArrayInByte( ref byteULong, 0 );
            stream.Write( byteULong, 0, byteULong.Length );

            // 10 ~ 11: 评论信息的压缩方式 (0xFF 为该评论信息已删除, 0 为无压缩, 1... 为其它压缩方式)(写入)
            stream.WriteByte( (byte)xyzComment.CompressionType );

            // 11 ~ 13: 评论信息被压缩后的有效长度 ( 如果该评论信息已删除,当有新增的评论信息压缩后的有效长度小于此评论信息的有效长度则覆盖掉此评论信息,然后在此评论信息尾部新增一个新的空XYZ文件内实体来填充剩余的字节 )(写入)
            xyzComment.CompressedLength.ToArrayInByte( ref byteULong, 0 );
            stream.Write( byteULong, 0, byteULong.Length );

            // 13 ~ 15: 原评论信息的有效长度(写入)
            xyzComment.UncompressedLength.ToArrayInByte( ref byteULong, 0 );
            stream.Write( byteULong, 0, byteULong.Length );

            // 15 ~ 31: 原评论信息的CRC校验字节(写入)
            stream.Write( xyzComment.Crc, 0, xyzComment.Crc.Length );

            // 31 ~ ..: 评论信息被压缩后的字节
            if ( xyzComment.CompressedData == null )
            {
                if ( xyzComment.CompressedLength > 0 )
                    throw new ArgumentException( "xyzComment.CompressedData == null && xyzComment.CompressedData.Length > 0 error!", "xyzComment.CompressedData & xyzComment.CompressedLength" );
                else
                    return true;
            }

            if ( xyzComment.CompressedLength > xyzComment.CompressedData.Length )
                throw new ArgumentException( "xyzComment.CompressedLength > xyzComment.CompressedData.Length error!", "xyzComment.CompressedData & xyzComment.CompressedLength" );

            stream.Write( xyzComment.CompressedData, 0, xyzComment.CompressedLength );

            return true;
        }
Пример #8
0
        public override int Compress(System.IO.Stream instream, long inLength, System.IO.Stream outstream)
        {
            // don't bother trying to get the optimal not-compressed - compressed ratio for now.
            // Either compress fully or don't compress (as the format cannot handle decompressed
            // sizes that are smaller than the compressed file).

            if (inLength > 0xFFFFFF)
                throw new InputTooLargeException();

            // read the input and reverse it
            byte[] indata = new byte[inLength];
            instream.Read(indata, 0, (int)inLength);
            Array.Reverse(indata);

            MemoryStream inMemStream = new MemoryStream(indata);
            MemoryStream outMemStream = new MemoryStream();
            int compressedLength = this.CompressNormal(inMemStream, inLength, outMemStream);

            int totalCompFileLength = (int)outMemStream.Length + 8;
            // make the file 4-byte aligned with padding in the header
            if (totalCompFileLength % 4 != 0)
                totalCompFileLength += 4 - totalCompFileLength % 4;

            if (totalCompFileLength < inLength)
            {
                byte[] compData = outMemStream.ToArray();
                Array.Reverse(compData);
                outstream.Write(compData, 0, compData.Length);
                int writtenBytes = compData.Length;
                // there always seem to be some padding FFs. Let's pad to make the file 4-byte aligned
                while (writtenBytes % 4 != 0)
                {
                    outstream.WriteByte(0xFF);
                    writtenBytes++;
                }

                outstream.WriteByte((byte)((compressedLength) & 0xFF));
                outstream.WriteByte((byte)((compressedLength >> 8) & 0xFF));
                outstream.WriteByte((byte)((compressedLength >> 16) & 0xFF));

                int headerLength = totalCompFileLength - compData.Length;
                outstream.WriteByte((byte)headerLength);

                int extraSize = (int)inLength - totalCompFileLength;
                outstream.WriteByte((byte)((extraSize) & 0xFF));
                outstream.WriteByte((byte)((extraSize >> 8) & 0xFF));
                outstream.WriteByte((byte)((extraSize >> 16) & 0xFF));
                outstream.WriteByte((byte)((extraSize >> 24) & 0xFF));

                return totalCompFileLength;
            }
            else
            {
                Array.Reverse(indata);
                outstream.Write(indata, 0, (int)inLength);
                outstream.WriteByte(0); outstream.WriteByte(0); outstream.WriteByte(0); outstream.WriteByte(0);
                return (int)inLength + 4;
            }
        }
Пример #9
0
        public override void Save(Image i, System.IO.Stream dest)
        {
            MemoryStream m = new MemoryStream();
            m.WriteByte(0);
#warning Change this next byte to 255 if you update Image with UInt64 for width and height.
            m.WriteByte(0);
            m.WriteByte(0);
            m.WriteByte(0); // Write the 8 empty bytes at the start of the file.
            m.WriteByte(0);
            m.WriteByte(0);
            m.WriteByte(0);
            m.WriteByte(0);

            byte[] dat = BitConverter.GetBytes(i.Height); // Write the height.
            m.Write(dat, 0, dat.Length);
            dat = BitConverter.GetBytes(i.Width); // Write the width.
            m.Write(dat, 0, dat.Length);

            // Now to write the actual data.
            Pixel p;
            for (uint x = 0; x < i.Width; x++)
            {
                for (uint y = 0; y < i.Height; y++)
                {
                    p = i.GetPixel(x, y);
                    m.WriteByte(p.R);
                    m.WriteByte(p.G);
                    m.WriteByte(p.B);
                    m.WriteByte(p.A);
                }
            }
            dat = Orvid.Compression.LZMA.Compress(m.GetBuffer());
            dest.WriteByte(255);
            dest.Write(dat, 0, dat.Length);
        }
Пример #10
0
        public static int encodeLength(int length, System.IO.Stream stream)
        {
            int resultSize = 0;

            if (length < 0)
            {
                throw new System.ArgumentException();
            }
            else if (length < 128)
            {
                stream.WriteByte((byte)length);
                resultSize++;
            }
            else if (length < 256)
            {
                stream.WriteByte((byte)length);
                stream.WriteByte((byte)0x81);
                resultSize += 2;
            }
            else if (length < 65536)
            {
                stream.WriteByte((byte)(length));
                stream.WriteByte((byte)(length >> 8));
                stream.WriteByte((byte)0x82);
                resultSize += 3;
            }
            else if (length < 16777126)
            {
                stream.WriteByte((byte)(length));
                stream.WriteByte((byte)(length >> 8));
                stream.WriteByte((byte)(length >> 16));
                stream.WriteByte((byte)0x83);
                resultSize += 4;
            }
            else
            {
                stream.WriteByte((byte)(length));
                stream.WriteByte((byte)(length >> 8));
                stream.WriteByte((byte)(length >> 16));
                stream.WriteByte((byte)(length >> 24));
                stream.WriteByte((byte)0x84);
                resultSize += 5;
            }
            return resultSize;
        }
Пример #11
0
 public static void encodeAndWrite(System.IO.Stream os, int ch)
 {
     if (ch < 0x10000)
     {
         os.WriteByte((byte)(ch & 0xff));
         os.WriteByte((byte)((ch & 0xff00) >> 8));
     }
     else
     {
         int tmp = ch - 0x10000;
         int w1 = 0xd800 | (tmp & 0xffc00);
         int w2 = 0xdc00 | (tmp & 0x3ff);
         os.WriteByte((byte)(w1 & 0xff));
         os.WriteByte((byte)(((w1 & 0xff00) >> 8)));
         os.WriteByte((byte)(w2 & 0xff));
         os.WriteByte((byte)((w2 & 0xff00) >> 8));
     }
 }
 protected override void SendPayload(System.IO.Stream str)
 {
     WriteToStream(str, _messageID);
     // Write the subscription payload
     foreach (Subscription s in _subscriptions)
     {
         WriteToStream(str, s.Topic);
         str.WriteByte((byte)s.QualityOfService);
     }
 }
Пример #13
0
 //public override byte[] GetData(Assembler aAssembler) {
 public override void WriteData( Cosmos.Assembler.Assembler aAssembler, System.IO.Stream aOutput )
 {
     aOutput.WriteByte(0xEA);
     ulong xAddress = 0;
     if (DestinationRef != null && DestinationRef.Resolve(aAssembler, out xAddress)) {
         xAddress = (ulong)(((long)xAddress) + DestinationRef.Offset);
     }
     aOutput.Write(BitConverter.GetBytes((uint)(xAddress)), 0, 4);
     aOutput.Write(BitConverter.GetBytes(Segment), 0, 2);
 }
Пример #14
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;
        }
Пример #15
0
		/// <summary> BER Encode an Asn1Boolean directly into the specified output stream.</summary>
		public virtual void  encode(Asn1Boolean b, System.IO.Stream out_Renamed)
		{
			/* Encode the id */
			encode(b.getIdentifier(), out_Renamed);
			
			/* Encode the length */
			out_Renamed.WriteByte((System.Byte) 0x01);
			
			/* Encode the boolean content*/
			out_Renamed.WriteByte((byte) (b.booleanValue()?(sbyte) SupportClass.Identity(0xff):(sbyte) 0x00));
			
			return ;
		}
Пример #16
0
 public static void encodeAndWrite(System.IO.Stream os, int ch)
 {
     if (ch < 128){
         os.WriteByte((byte)ch);
         return;
     }
     if (ch < 0x800){
         os.WriteByte((byte)(((ch & 0x7c0) >> 6) | 0xc0));
         os.WriteByte((byte)((ch & 0x3f) | 0x80));
         return;
     }
     if (ch < 0xe000){
         os.WriteByte((byte)(((ch & 0xf000) >> 12) | 0xe0));
         os.WriteByte((byte)(((ch & 0xfc) >> 6) | 0x80));
         os.WriteByte((byte)((ch & 0x3f) | 0x80));
         return;
     }
     os.WriteByte((byte)(((ch & 0x1c0000) >> 18) | 0xf0));
     os.WriteByte((byte)(((ch & 0x3f0) >> 12) | 0x80));
     os.WriteByte((byte)(((ch & 0xfc) >> 6) | 0x80));
     os.WriteByte((byte)((ch & 0x3f) | 0x80));
 }
Пример #17
0
        public void RandomizeAndWrite(System.IO.FileStream stream, Random rand)
        {
            Index = rand.Next(ColorBytes.Count);

            for (int i = 0; i < addresses.GetLength(0); i++)
            {
                for (int j = 0; j < addresses.GetLength(1); j++)
                {
                    stream.Position = addresses[i, j];
                    stream.WriteByte(ColorBytes[Index][i,j]);
                }
            }
        }
Пример #18
0
        public override void WriteHeader(System.IO.Stream stream, FrameHeader frameHeader)
        {
            // Frame ID   $xx xx xx xx  (four characters)
            // Size       $xx xx xx xx
            // Flags      $xx xx
            string frameID=frameHeader.FrameID;
            stream.Write(Encoding.GetEncoding("ISO-8859-1").GetBytes(frameID), 0, 4);

            int size=frameHeader.Length;
            byte[] sizeData=new byte[4];
            sizeData[3]=(byte)(size%0x100);
            size/=0x100;
            sizeData[2]=(byte)(size%0x100);
            size/=0x100;
            sizeData[1]=(byte)(size%0x100);
            size/=0x100;
            sizeData[0]=(byte)(size%0x100);
            stream.Write(sizeData, 0, 4);

            stream.WriteByte(0); // Flags
            stream.WriteByte(0); // Flags
        }
Пример #19
0
        public void writeFileStream(System.IO.FileStream fs) {
            byte[] bytearray = System.Text.Encoding.ASCII.GetBytes("blaat");
            try
            {
                bytearray = System.Text.Encoding.ASCII.GetBytes(filecontents);
            }
            catch (NullReferenceException) { Console.WriteLine("nothing to export"); }
            foreach (byte character in bytearray)
            {
                fs.WriteByte(character);
            }
            fs.Close();

        }
Пример #20
0
 private static void EncodeDERLength(System.IO.Stream s, uint length)
 {
     if (length < 0x7f)
     {
         s.WriteByte((byte)length);
     }
     else if (length <= 0x7fff)
     {
         s.WriteByte(0x82);
         s.WriteByte((byte)((length >> 8) & 0xff));
         s.WriteByte((byte)(length & 0xff));
     }
     else
     {
         s.WriteByte(0x84);
         s.WriteByte((byte)((length >> 24) & 0xff));
         s.WriteByte((byte)((length >> 16) & 0xff));
         s.WriteByte((byte)((length >> 8) & 0xff));
         s.WriteByte((byte)(length & 0xff));
     }
 }
        public void Encode(System.IO.Stream stream, WADL.WADLRepresentation param, object value)
        {
            switch (System.Type.GetTypeCode(value.GetType()))
            {
                case TypeCode.SByte:
                case TypeCode.Byte:
                    stream.WriteByte((byte)value);
                    break;
                case TypeCode.Object:
                    if (value is Byte[])
                    {
                        byte[] bytes = (byte[])value;
                        stream.Write(bytes, 0, bytes.Length);
                    }
                    else
                    {
                        StreamWriter objWriter = new StreamWriter(stream);
                        objWriter.AutoFlush = true;
                        objWriter.Write(value.ToString());
                    }
                    break;
                case TypeCode.Empty:
                case TypeCode.DBNull:
                    break;
                case TypeCode.Char:
                case TypeCode.UInt16:
                case TypeCode.UInt32:
                case TypeCode.UInt64:
                case TypeCode.Boolean:
                case TypeCode.Int16:
                case TypeCode.Int32:
                case TypeCode.Int64:
                case TypeCode.Single:
                case TypeCode.Double:
                case TypeCode.Decimal:
                case TypeCode.DateTime:
                case TypeCode.String:
                default:
                    StreamWriter defaultWriter = new StreamWriter(stream);
                    defaultWriter.AutoFlush = true;
                    defaultWriter.Write(value.ToString());

                    break;
            }

        }
Пример #22
0
        /// <summary>
        /// 'Compresses' the given input stream using the NULL format.
        /// </summary>
        public override int Compress(System.IO.Stream instream, long inLength, System.IO.Stream outstream)
        {
            if (inLength > 0xFFFFFFFF)
                throw new InputTooLargeException();

            long outSize = 4;

            outstream.WriteByte(0);
            if (inLength <= 0xFFFFFF)
            {
                outstream.WriteByte((byte)(inLength & 0xFF));
                outstream.WriteByte((byte)((inLength >> 8) & 0xFF));
                outstream.WriteByte((byte)((inLength >> 16) & 0xFF));
            }
            else
            {
                outstream.WriteByte(0);
                outstream.WriteByte(0);
                outstream.WriteByte(0);
                outstream.WriteByte((byte)(inLength & 0xFF));
                outstream.WriteByte((byte)((inLength >> 8) & 0xFF));
                outstream.WriteByte((byte)((inLength >> 16) & 0xFF));
                outstream.WriteByte((byte)((inLength >> 24) & 0xFF));
                outSize = 8;
            }

            byte[] buffer = new byte[Math.Min(int.MaxValue, inLength)];
            long remaining = inLength;
            while (remaining > 0)
            {
                int readLength = instream.Read(buffer, 0, (int)Math.Min(buffer.Length, remaining));
                if (readLength == 0)
                    throw new StreamTooShortException();
                remaining -= readLength;
                outstream.Write(buffer, 0, readLength);
                outSize += readLength;
            }

            return (int)Math.Min(int.MaxValue, outSize);
        }
Пример #23
0
            public override void OnRemote(IEnumerator<ByteSlice> input, System.IO.Stream output)
            {

                long TopCount = long.Parse(DSpace_ExecArgs[0]);

                while ((TopCount == -1 || TopCount > 0) && input.MoveNext())
                {
                    ByteSlice row = input.Current;
                    for (int i = 0; i < row.Length; i++)
                    {
                        output.WriteByte(row[i]);
                    }

                    if (TopCount != -1)
                    {
                        TopCount--;
                    }
                }

            }
Пример #24
0
        private void StoreChunk(System.IO.FileStream fs, string chunkID)
        {
            System.Text.ASCIIEncoding Decoder = new ASCIIEncoding();
            // den Namen in Bytes konvertieren und schreiben
            fs.Write(Decoder.GetBytes(chunkID), 0, 4);

            if (chunkID == "RIFF")
            {
                // im RIFF Chunk, FileSize als Größe und das Audioformat schreiben
                fs.Write(System.BitConverter.GetBytes(FileSize), 0, 4);
                fs.Write(Decoder.GetBytes(Format), 0, 4);
            }
            if (chunkID == "fmt ")
            {
                // beim fmt Chunk die Größe dieses sowie die weiteren kodierten Informationen schreiben
                fs.Write(System.BitConverter.GetBytes(FmtChunkSize), 0, 4);
                fs.Write(System.BitConverter.GetBytes(AudioFormat), 0, 2);
                fs.Write(System.BitConverter.GetBytes(NumChannels), 0, 2);
                fs.Write(System.BitConverter.GetBytes(SampleRate), 0, 4);
                fs.Write(System.BitConverter.GetBytes(ByteRate), 0, 4);
                fs.Write(System.BitConverter.GetBytes(BlockAlign), 0, 2);
                fs.Write(System.BitConverter.GetBytes(BitsPerSample), 0, 2);
            }
            if (chunkID == "data")
            {
                // beim data Chunk die Größe des Datenblocks als Größenangabe schreiben
                fs.Write(System.BitConverter.GetBytes(DataSize), 0, 4);
                // dann die einzelnen Amplituden, wie beschrieben Sample für Sample mit jeweils allen
                // Audiospuren, schreiben
                // CAVE: z.Zt. werden Channels ignoriert!!!!
                int count = 0;
                for (int i = 0; i < Data.Length; i++)
                {
                        fs.WriteByte(Data[i]);
                        count++;                
                }
                Console.WriteLine("Durchlaeufe: {0}", count);
            }
        }
Пример #25
0
        public static void ImportImmutableProperty(PCCPackage pcc, PCCPackage importpcc, Property p, string className, System.IO.MemoryStream m, bool inStruct = false)
        {
            string name = importpcc.GetName(p.Name);
            int idxname = pcc.FindNameOrAdd(name);
            if (name == "None")
                return;
            string type = importpcc.GetName(BitConverter.ToInt32(p.raw, 8));
            int idxtype = pcc.FindNameOrAdd(type);
            string name2;
            int idxname2;
            int size, count, pos;
            List<Property> Props;
            switch (type)
            {
                case "IntProperty":
                case "FloatProperty":
                case "ObjectProperty":
                case "StringRefProperty":
                    m.Write(BitConverter.GetBytes(p.Value.IntValue), 0, 4);
                    break;
                case "NameProperty":
                    m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(importpcc.GetName(p.Value.IntValue))), 0, 4);
                    //preserve index or whatever the second part of a namereference is
                    m.Write(p.raw, 28, 4);
                    break;
                case "BoolProperty":
                    m.WriteByte((byte)p.Value.IntValue);
                    break;
                case "BioMask4Property":
                    m.WriteByte((byte)p.Value.IntValue);
                    break;
                case "ByteProperty":
                    name2 = importpcc.GetName(BitConverter.ToInt32(p.raw, 24));
                    idxname2 = pcc.FindNameOrAdd(name2);
                    if (p.Size == 8)
                    {
                        m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(importpcc.GetName(p.Value.IntValue))), 0, 4);
                        m.Write(new byte[4], 0, 4);
                    }
                    else
                    {
                        m.WriteByte(p.raw[32]);
                    }
                    break;
                case "StrProperty":
                    name2 = p.Value.StringValue;
                    m.Write(BitConverter.GetBytes(-name2.Length), 0, 4);
                    foreach (char c in name2)
                    {
                        m.WriteByte((byte)c);
                        m.WriteByte(0);
                    }
                    break;
                case "StructProperty":
                    size = BitConverter.ToInt32(p.raw, 16);
                    name2 = importpcc.GetName(BitConverter.ToInt32(p.raw, 24));
                    idxname2 = pcc.FindNameOrAdd(name2);
                    pos = 32;
                    Props = new List<Property>();
                    try
                    {
                        Props = ReadProp(importpcc, p.raw, pos);
                    }
                    catch (Exception)
                    {
                    }
                    if (Props.Count == 0 || Props[0].TypeVal == Type.Unknown)
                    {
                        for (int i = 0; i < size; i++)
                            m.WriteByte(p.raw[32 + i]);
                    }
                    else
                    {
                        foreach (Property pp in Props)
                            ImportImmutableProperty(pcc, importpcc, pp, className, m, inStruct);
                    }
                    break;
                case "ArrayProperty":
                    size = BitConverter.ToInt32(p.raw, 16);
                    count = BitConverter.ToInt32(p.raw, 24);
                    UnrealObjectInfo.ArrayType arrayType = UnrealObjectInfo.getArrayType(className, importpcc.GetName(p.Name), inStruct);
                    pos = 28;
                    List<Property> AllProps = new List<Property>();

                    if (arrayType == UnrealObjectInfo.ArrayType.Struct)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            Props = new List<Property>();
                            try
                            {
                                Props = ReadProp(importpcc, p.raw, pos);
                            }
                            catch (Exception)
                            {
                            }
                            AllProps.AddRange(Props);
                            if (Props.Count != 0)
                            {
                                pos = Props[Props.Count - 1].offend;
                            }
                        }
                    }
                    m.Write(BitConverter.GetBytes(count), 0, 4);
                    if (AllProps.Count != 0)
                    {
                        foreach (Property pp in AllProps)
                            ImportImmutableProperty(pcc, importpcc, pp, className, m, inStruct);
                    }
                    else if (arrayType == UnrealObjectInfo.ArrayType.Name)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            string s = importpcc.GetName(BitConverter.ToInt32(p.raw, 28 + i * 8));
                            m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(s)), 0, 4);
                            //preserve index or whatever the second part of a namereference is
                            m.Write(p.raw, 32 + i * 8, 4);
                        }
                    }
                    else
                    {
                        m.Write(p.raw, 28, size - 4);
                    }
                    break;
                default:
                case "DelegateProperty":
                    throw new NotImplementedException(type);
            }
        }
Пример #26
0
        protected override void SendPayload(System.IO.Stream str)
        {
            str.Write(protocolDesc, 0, protocolDesc.Length);

            // TODO: Implement Clean Session Flag
            str.WriteByte(_connectFlags);

            // Write the keep alive value
            WriteToStream(str, _keepAlive);

            // Write the payload
            WriteToStream(str, (ushort)_clientID.Length);
            str.Write(_clientID, 0, _clientID.Length);

            if (_containsWill)
            {
                // Write the will topic
                WriteToStream(str, _willTopic);

                // Write the will payload
                WriteToStream(str, (ushort)_willPayload.Length);
                str.Write(_willPayload, 0, _willPayload.Length);
            }

            if (_containsUsername)
            {
                WriteToStream(str, _username);

                if (_containsPassword)
                    WriteToStream(str, _password);
            }
        }
Пример #27
0
 /// <summary>
 /// Writes the variable header for an MQTT Connect message to the supplied stream.
 /// </summary>
 /// <param name="headerStream"></param>
 public override void WriteTo(System.IO.Stream headerStream)
 {
     // unused additional "compression" byte used within the variable header acknowledgement.
     headerStream.WriteByte(0);
     WriteReturnCode(headerStream);
 }
Пример #28
0
            public static void WriteBytes(string data,System.IO.FileStream fileStream)
            {
                int index = 0;
                int length = data.Length;

                while(index < length)
                    fileStream.WriteByte((byte)data[index++]);
            }
Пример #29
0
        public void Write(System.IO.Stream output)
        {
            BinaryWriter bw = new BinaryWriter(output);

            BitStream bs = new BitStream(output);

            bs.WriteBits(1, 0);     // reserved
            bs.WriteBits(1, 0);     // reserved
            bs.WriteBits(1, _syncstop ? 1 : 0);
            bs.WriteBits(1, _syncnomultiple ? 1 : 0);
            bs.WriteBits(1, _hasEnvelope ? 1 : 0);
            bs.WriteBits(1, _hasLoops ? 1 : 0);
            bs.WriteBits(1, _hasOutPoint ? 1 : 0);
            bs.WriteBits(1, _hasInPoint ? 1 : 0);

            if (_hasInPoint)
            {
                byte[] data = BitConverter.GetBytes(this._inPoint);
                output.Write(data, 0, 4);
            }

            if (_hasOutPoint)
            {
                byte[] data = BitConverter.GetBytes(this._outPoint);
                output.Write(data, 0, 4);
            }

            if (_hasLoops)
            {
                byte[] data = BitConverter.GetBytes(this._loopCount);
                output.Write(data, 0, 2);
            }

            if (_hasEnvelope)
            {
                output.WriteByte(this._envelopePoints);
                for (int i = 0; i < this._envelopePoints; i++)
                    _envelopeRecords[i].Write(output);
            }
        }
Пример #30
0
 public override void WriteToStream(System.IO.Stream stream)
 {
     byte[] buffer=Encoding.Unicode.GetBytes(this.Text);
     stream.WriteByte(0xff);					// first byte of BOM
     stream.WriteByte(0xfe);					// second byte of BOM
     stream.Write(buffer, 0, buffer.Length);	// char data
     stream.WriteByte(0);					// null terminator
     stream.WriteByte(0);					// null terminator
 }