当前位置: 首页>>代码示例>>C#>>正文


C# Stream.ReadUShort方法代码示例

本文整理汇总了C#中Stream.ReadUShort方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.ReadUShort方法的具体用法?C# Stream.ReadUShort怎么用?C# Stream.ReadUShort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stream的用法示例。


在下文中一共展示了Stream.ReadUShort方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendStream

 public override void SendStream(Stream stream,int length)
 {
     var marker = stream.ReadByte() | 0xF0;
     var echoTime = marker == (Target == null ? 0xFE : 0xFD);
     stream.ReadUShort();
     if (echoTime) stream.ReadUShort();
     var type = stream.ReadByte();
     if (type == 0x10)
     {
         var sizePos = stream.Position;
         var size = stream.ReadUShort();
         var flags = stream.ReadByte();
         var idFlow = stream.Read7BitLongValue();
         var stage = stream.Read7BitLongValue();
         if (idFlow == 2 && stage == 1)
         {
             var deltaNAck = stream.Read7BitLongValue();
             var len = (ushort) stream.ReadByte();
             stream.Position += len;
             stream.ReadByte();
             stream.ReadByte();//type
             stream.ReadUInt();//timestamp
             var amfReader = new AMF0Reader(stream);
             var str = amfReader.ReadShortString(true);
             var num = amfReader.ReadAMFDouble(true);
             var pos = stream.Position;
             var connectionInfo = amfReader.ReadVariant();
             connectionInfo["tcUrl"] = MiddleSession.QueryUrl;
             connectionInfo["app"] = MiddleSession.QueryUrl.Split('/').Last();
             stream.Position = pos;
             var amfWriter = new AMF0Writer(stream);
             amfWriter.WriteObject(connectionInfo, true);
             length = (int) stream.Position;
             len = (ushort) (stream.Position - sizePos-2);
             stream.Position = sizePos;
             stream.Write(len);
         }
     }
     stream.Position = 6;
     base.SendStream(stream,length);
 }
开发者ID:langhuihui,项目名称:csharprtmp,代码行数:41,代码来源:Middle.cs

示例2: GetFileExtension

        public static string GetFileExtension(Stream data)
        {
            // Check to see if the file is an archive
            Archive archive = new Archive(data, null);
            if (archive.Format != ArchiveFormat.NULL)
                return archive.FileExtension;

            // Check to see if the file is an image
            Images images = new Images(data, null);
            if (images.Format != GraphicFormat.NULL)
                return images.FileExtension;

            // Check to see if the file is an ADX (special case)
            if (data.Length > 4 && data.ReadUShort(0x00) == 0x0080 &&
                data.Length > data.ReadUShort(0x02).SwapEndian() + 4 &&
                data.ReadString(data.ReadUShort(0x02).SwapEndian() - 0x02, 6, true) == "(c)CRI")
                return ".adx";

            // Unknown
            return String.Empty;
        }
开发者ID:memerdot,项目名称:puyotools,代码行数:21,代码来源:FileTypeInfo.cs

示例3: CreateExceptionFromError

        private static Exception CreateExceptionFromError(Stream stream)
        {
            ErrorCodes code = (ErrorCodes) stream.ReadInt();
            string msg = stream.ReadString();

            switch (code)
            {
                case ErrorCodes.Unavailable:
                    {
                        ConsistencyLevel cl = (ConsistencyLevel) stream.ReadUShort();
                        int required = stream.ReadInt();
                        int alive = stream.ReadInt();
                        return new UnavailableException(msg, cl, required, alive);
                    }

                case ErrorCodes.WriteTimeout:
                    {
                        ConsistencyLevel cl = (ConsistencyLevel) stream.ReadUShort();
                        int received = stream.ReadInt();
                        int blockFor = stream.ReadInt();
                        string writeType = stream.ReadString();
                        return new WriteTimeOutException(msg, cl, received, blockFor, writeType);
                    }

                case ErrorCodes.ReadTimeout:
                    {
                        ConsistencyLevel cl = (ConsistencyLevel) stream.ReadUShort();
                        int received = stream.ReadInt();
                        int blockFor = stream.ReadInt();
                        bool dataPresent = 0 != stream.ReadByte();
                        return new ReadTimeOutException(msg, cl, received, blockFor, dataPresent);
                    }

                case ErrorCodes.Syntax:
                    return new SyntaxException(msg);

                case ErrorCodes.Unauthorized:
                    return new UnauthorizedException(msg);

                case ErrorCodes.Invalid:
                    return new InvalidException(msg);

                case ErrorCodes.AlreadyExists:
                    {
                        string keyspace = stream.ReadString();
                        string table = stream.ReadString();
                        return new AlreadyExistsException(msg, keyspace, table);
                    }

                case ErrorCodes.Unprepared:
                    {
                        byte[] unknownId = stream.ReadShortBytes();
                        return new UnpreparedException(msg, unknownId);
                    }

                default:
                    return new CassandraException(code, msg);
            }
        }
开发者ID:Jacky1,项目名称:cassandra-sharp,代码行数:59,代码来源:StreamingFrameReader.cs

示例4: TranslateData

        /* To simplify the process greatly, we are going to convert
         * the GVM to a new format */
        public override MemoryStream TranslateData(ref Stream stream)
        {
            try
            {
                /* Get the number of files, and format type in the stream */
                ushort files = stream.ReadUShort(0xA).SwapEndian();
                byte formatType = stream.ReadByte(0x9);

                /* Now let's see what information is contained inside the metadata */
                bool containsFilename    = (formatType & (1 << 3)) > 0;
                bool containsPixelFormat = (formatType & (1 << 2)) > 0;
                bool containsDimensions  = (formatType & (1 << 1)) > 0;
                bool containsGlobalIndex = (formatType & (1 << 0)) > 0;

                /* Let's figure out the metadata size */
                int size_filename = 0, size_pixelFormat = 0, size_dimensions = 0, size_globalIndex = 0;
                if (containsFilename)    size_filename = 28;
                if (containsPixelFormat) size_pixelFormat = 2;
                if (containsDimensions)  size_dimensions = 2;
                if (containsGlobalIndex) size_globalIndex = 4;
                int metaDataSize = 2 + size_filename + size_pixelFormat + size_dimensions + size_globalIndex;

                /* Now create the header */
                MemoryStream data = new MemoryStream();
                data.Write(files);

                /* Ok, try to find out data */
                uint sourceOffset = stream.ReadUInt(0x4) + 0x8;

                /* Write each file in the header */
                uint offset = 0x2 + ((uint)files * 0x24);
                for (int i = 0; i < files; i++)
                {
                    /* Ok, get the size of the GVR file */
                    uint length = stream.ReadUInt(sourceOffset + 0x4) + 8;

                    /* Make sure this is a valid file length */
                    if (sourceOffset + length > stream.Length)
                        length -= 16; // For some reason some GVR files are like this.
                    if (sourceOffset + length > stream.Length)
                        throw new Exception();

                    /* Write the offset, file length, and filename */
                    data.Write(offset);      // Offset
                    data.Write(length + 16); // Length

                    if (containsFilename)
                        data.Write(stream.ReadString(0xE + (i * metaDataSize), 28), 28); // Filename
                    else
                        data.Position += 28;

                    /* Add the GBIX header */
                    data.Position = offset;
                    data.Write(GraphicHeader.GBIX);
                    data.Write((int)0x8);

                    /* Copy the global index */
                    if (containsGlobalIndex)
                        data.Write(stream.ReadUInt(0xE + size_filename + size_pixelFormat + size_dimensions + (i * metaDataSize)));
                    else
                        data.Position += 4;

                    /* Write out the 0x0 in the header */
                    data.Write(new byte[] { 0x0, 0x0, 0x0, 0x0 });

                    /* Now copy the file */
                    data.Write(stream, sourceOffset, length);
                    data.Position = 0x26 + (i * 0x24);

                    sourceOffset += length.RoundUp(16);

                    /* Increment the offset */
                    offset += length + 16;
                }

                return data;
            }
            catch
            {
                /* Something went wrong, so send as blank stream */
                return new MemoryStream();
            }
        }
开发者ID:memerdot,项目名称:puyotools,代码行数:85,代码来源:gvm.cs

示例5: GetFileList

        /* Get the offsets, lengths, and filenames of all the files */
        public override ArchiveFileList GetFileList(ref Stream data)
        {
            try
            {
                /* Get the number of files */
                ushort files = data.ReadUShort(0x0);

                /* Create the array of files now */
                ArchiveFileList fileList = new ArchiveFileList(files);

                /* Now we can get the file offsets, lengths, and filenames */
                for (int i = 0; i < files; i++)
                {
                    /* Get the filename */
                    string filename = data.ReadString(0xA + (i * 0x24), 28);

                    fileList.Entries[i] = new ArchiveFileList.Entry(
                        data.ReadUInt(0x2 + (i * 0x24)), // Offset
                        data.ReadUInt(0x6 + (i * 0x24)), // Length
                        (filename == String.Empty ? String.Empty : filename + (filename.IsAllUpperCase() ? ".GVR" : ".gvr")) // Filename
                    );
                }

                return fileList;
            }
            catch
            {
                /* Something went wrong, so return nothing */
                return null;
            }
        }
开发者ID:memerdot,项目名称:puyotools,代码行数:32,代码来源:gvm.cs

示例6: GetFileList

        /* Get the offsets, lengths, and filenames of all the files */
        public override ArchiveFileList GetFileList(ref Stream data)
        {
            try
            {
                /* Get the offset of each section of the NARC file */
                uint offset_fatb = data.ReadUShort(0xC);
                uint offset_fntb = offset_fatb + data.ReadUInt(offset_fatb + 0x4);
                uint offset_fimg = offset_fntb + data.ReadUInt(offset_fntb + 0x4);

                /* Stuff for filenames */
                bool containsFilenames = (data.ReadUInt(offset_fntb + 0x8) == 8);
                uint offset_filename   = offset_fntb + 0x10;

                /* Get the number of files */
                uint files = data.ReadUInt(offset_fatb + 0x8);

                /* Create the array of files now */
                ArchiveFileList fileList = new ArchiveFileList(files);

                /* Now we can get the file offsets, lengths, and filenames */
                for (uint i = 0; i < files; i++)
                {
                    /* Get the offset & length */
                    uint offset = data.ReadUInt(offset_fatb + 0x0C + (i * 0x8));
                    uint length = data.ReadUInt(offset_fatb + 0x10 + (i * 0x8)) - offset;

                    /* Get the filename, if the NARC contains filenames */
                    string filename = String.Empty;
                    if (containsFilenames)
                    {
                        /* Ok, since the NARC contains filenames, let's go grab it now */
                        byte filename_length = data.ReadByte(offset_filename);
                        filename             = data.ReadString(offset_filename + 1, filename_length);
                        offset_filename     += (uint)(filename_length + 1);
                    }

                    fileList.Entries[i] = new ArchiveFileList.Entry(
                        offset + offset_fimg + 0x8, // Offset
                        length,  // Length
                        filename // Filename
                    );
                }

                return fileList;
            }
            catch
            {
                /* Something went wrong, so return nothing */
                return null;
            }
        }
开发者ID:memerdot,项目名称:puyotools,代码行数:52,代码来源:narc.cs

示例7: RawHandler

 protected override void RawHandler(byte type, Stream data)
 {
     var flag = data.ReadUShort();
     if (flag == 0x22) return;
     base.RawHandler(type,data);
 }
开发者ID:langhuihui,项目名称:csharprtmp,代码行数:6,代码来源:FlowStream.cs

示例8: FeedDataAudioMPEG4Generic


//.........这里部分代码省略.........
                        {
                            FATAL("Invalid data length");
                            return false;
                        }

                    }
                }
            }
            var inStreamType = InStream.Type;

            if ((inStreamType == ST_IN_NET_RTMP)
            || (inStreamType == ST_IN_NET_RTP)
            || (inStreamType == ST_IN_NET_LIVEFLV))
            {
                //2. Do we have enough data to read the RTMP header?
                if (dataLength <= 2)
                {
                    WARN("Bogus AAC packet");
                    _audioBuffer.IgnoreAll();
                    return true;
                }
                var firstByte = pData.ReadByte();
                var secondByte = pData.ReadByte();
                //3. Take care of the RTMP headers if necessary
                if (inStreamType == ST_IN_NET_RTMP
                        || inStreamType == ST_IN_NET_LIVEFLV)
                {
                    //3. Is this a RTMP codec setup? If so, ignore it
                    if (secondByte != 1)
                    {
                        _audioBuffer.IgnoreAll();
                        return true;
                    }
                }

                //4. Skip the RTMP header
                dataLength -= 2;
                
            }

            //4. Do we have enough data to detect the ADTS header presence?
            if (dataLength <= 2)
            {
                WARN("Bogus AAC packet");
                _audioBuffer.IgnoreAll();
                return true;
            }

            //4. The packet might start with an ADTS header. Remove it if necessary
            var adtsHeaderLength = 0;

            var temp = pData.ReadUShort();
            if ((temp >> 3) == 0x1fff)
            {
                adtsHeaderLength = 7;
            }

            /*
0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|V=2|P|X|  CC   |M|     PT      |       sequence number         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           timestamp                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           synchronization source (SSRC) identifier            |
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
|            contributing source (CSRC) identifiers             |
|                             ....                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- .. -+-+-+-+-+-+-+-+-+-+
|AU-headers-length|AU-header|AU-header|      |AU-header|padding|
|                 |   (1)   |   (2)   |      |   (n)   | bits  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- .. -+-+-+-+-+-+-+-+-+-+
 */

            //5. counter
            _audioData.Buffers[0].Write(2, AudioCounter++);
            //6. Timestamp
            _audioData.Buffers[0].Write(4, absoluteTimestamp*Capabilities.Samplerate/1000);
            _audioData.Buffers[0].Write(12,(ushort)16);
            var auHeader = (dataLength - adtsHeaderLength) << 3;
           
            Array.Resize(ref _audioData.Buffers[1], 2);
            _audioData.Buffers[1].Write(0, (ushort)auHeader);
            //7. put the actual buffer
            _audioData.Buffers[2] = new byte[dataLength - adtsHeaderLength];
            pData.Position += adtsHeaderLength;
            pData.Read(_audioData.Buffers[2], 0, _audioData.Buffers[2].Length);
            
            if (!Connectivity.FeedAudioData(ref _audioData, absoluteTimestamp))
            {
                FATAL("Unable to feed data");
                _audioBuffer.IgnoreAll();
                return false;
            }
            _audioBuffer.IgnoreAll();
            return true;
        }
开发者ID:langhuihui,项目名称:csharprtmp,代码行数:101,代码来源:OutNetRTPUDPH264Stream.cs


注:本文中的Stream.ReadUShort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。