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


C# MemoryStream.ReadShort方法代码示例

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


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

示例1: Read

 public uint Read(MemoryStream ms)
 {
     base.Read(ms, "MODR");
     if (size > 0)
     {
         long end_chunk = ms.Position + size;
         while (ms.Position < end_chunk)
         {
             doodadrefs.Add(ms.ReadShort());
         }
     }
     return size;
 }
开发者ID:ostapus,项目名称:WoW2Mesh,代码行数:13,代码来源:WmoGroup.cs

示例2: TestStreamshort

        public void TestStreamshort()
        {
            short obj = 100;

            using (MemoryStream ms = new MemoryStream())
            {
                ms.WriteShort(obj);
                ms.Seek(0, SeekOrigin.Begin);
                short res = ms.ReadShort();

                Assert.IsTrue(obj.Equals(res), "Streaming failed!");
            }
        }
开发者ID:CHiiLD,项目名称:net-toolkit,代码行数:13,代码来源:StreamExtensionsTest.cs

示例3: Read

                public uint Read(MemoryStream ms, long data_offset = 0)
                {
                    type = (ushort)ms.ReadShort();
                    flags = (ushort)ms.ReadShort();
                    heightLevel1 = ms.ReadFloat();
                    heightLevel2 = ms.ReadFloat();
                    xOffset = (byte)ms.ReadByte();
                    yOffset = (byte)ms.ReadByte();
                    width = (byte)ms.ReadByte();
                    height = (byte)ms.ReadByte();
                    mask2_offset = (uint)ms.ReadInt32();
                    heightMap_offset = (uint)ms.ReadInt32();

                    long save_point = ms.Position;
                    if (mask2_offset != 0 && height > 0)
                    {
                        ms.Position = data_offset + mask2_offset;
                        mask2 = new List<byte>(sizeof(byte) * height);
                        for (int i = 0; i < height; i++)
                            mask2.Add((byte)ms.ReadByte());
                    }

                    if (heightMap_offset != 0 && width * height > 0)
                    {
                        ms.Position = data_offset + heightMap_offset;
                        heightMap = new List<float>(width * height);
                        for (int i = 0; i < width * height; i++)
                            heightMap.Add(ms.ReadFloat());
                    }
                    ms.Position = save_point;

                    return 0;
                }
开发者ID:ostapus,项目名称:WoW2Mesh,代码行数:33,代码来源:Adt.cs

示例4: Deserialize

        public static object Deserialize(this IColumnSpec columnSpec, byte[] rawData)
        {
            object data;
            Type colType;
            switch (columnSpec.ColumnType)
            {
                default:
                    data = Deserialize(columnSpec.ColumnType, rawData);
                    break;

                case ColumnType.List:
                    colType = columnSpec.CollectionValueType.ToType();
                    Type typedColl = typeof(ListInitializer<>).MakeGenericType(colType);
                    ICollectionInitializer list = (ICollectionInitializer) Activator.CreateInstance(typedColl);
                    using (MemoryStream ms = new MemoryStream(rawData))
                    {
                        short nbElem = ms.ReadShort();
                        while (0 < nbElem)
                        {
                            byte[] elemRawData = ms.ReadShortBytes();
                            object elem = Deserialize(columnSpec.CollectionValueType, elemRawData);
                            list.Add(elem);
                        }
                        data = list.Collection;
                    }
                    break;

                case ColumnType.Map:
                    Type keyType = columnSpec.CollectionKeyType.ToType();
                    colType = columnSpec.CollectionValueType.ToType();
                    Type typedDic = typeof(DictionaryInitializer<,>).MakeGenericType(keyType, colType);
                    IDictionaryInitializer dic = (IDictionaryInitializer) Activator.CreateInstance(typedDic);
                    using (MemoryStream ms = new MemoryStream(rawData))
                    {
                        short nbElem = ms.ReadShort();
                        while (0 < nbElem)
                        {
                            byte[] elemRawKey = ms.ReadShortBytes();
                            byte[] elemRawValue = ms.ReadShortBytes();
                            object key = Deserialize(columnSpec.CollectionValueType, elemRawKey);
                            object value = Deserialize(columnSpec.CollectionValueType, elemRawValue);
                            dic.Add(key, value);
                        }
                        data = dic.Collection;
                    }
                    break;

                case ColumnType.Set:
                    colType = columnSpec.CollectionValueType.ToType();
                    Type typedSet = typeof(HashSetInitializer<>).MakeGenericType(colType);
                    ICollectionInitializer set = (ICollectionInitializer) Activator.CreateInstance(typedSet);
                    using (MemoryStream ms = new MemoryStream(rawData))
                    {
                        short nbElem = ms.ReadShort();
                        while (0 < nbElem--)
                        {
                            byte[] elemRawData = ms.ReadShortBytes();
                            object elem = Deserialize(columnSpec.CollectionValueType, elemRawData);
                            set.Add(elem);
                        }
                        data = set.Collection;
                    }
                    break;
            }

            return data;
        }
开发者ID:kpaskal,项目名称:cassandra-sharp,代码行数:67,代码来源:ValueSerialization.cs

示例5: M2

        public M2(mpq.Wrapper mpq_h, string name)
        {
            MemoryStream ms = new MemoryStream(mpq_h.GetFile(name));

            // read in chunk by chunk
            ms.Read(id, 0, id.Length);
            ms.Read(version, 0, id.Length);
            nameLength = (uint) ms.ReadInt32();
            nameOff = (uint)ms.ReadInt32();
            flags = (uint)ms.ReadInt32();

            ms.Read(pad0, 0, pad0.Length);

            numVertices = (uint) ms.ReadInt32();
            verticesOff = (uint)ms.ReadInt32();

            ms.Read(pad1, 0, pad1.Length);

            numBoundingTriangles = (uint)ms.ReadInt32();
            boundingTriangleOff = (uint)ms.ReadInt32();
            numBoundingVertices = (uint)ms.ReadInt32();
            boundingVerticesOff = (uint)ms.ReadInt32();
            numBoundingNormals = (uint)ms.ReadInt32();
            boundingNormalsOff = (uint)ms.ReadInt32();

            isCollide = numBoundingTriangles > 0;

            // ignore non collidable M2s
            if (!isCollide)
                return;

            // get M2 model name
            ms.Position = nameOff;
            byte[] _b = new byte[nameLength];
            ms.Read(_b, 0, (int) nameLength);
            System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
            _m2name = enc.GetString(_b);

            if (numVertices > 0)
            {
                ms.Position = verticesOff;
                for (int i = 0; i < numVertices; i++)
                {
                    Vector3 v;
                    v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat();
                    _vertices.Add(v);
                }
            }

            // get bounding triangles
            if (numBoundingTriangles > 0)
            {
                ms.Position = boundingTriangleOff;
                for (int i = 0; i < numBoundingTriangles; i++)
                {
                    // in the file those are 16bit, so read short
                    _boundingIndices.Add(ms.ReadShort());
                }
            }

            // get bounding vertices
            if (numBoundingVertices > 0)
            {
                ms.Position = boundingVerticesOff;
                for (int i = 0; i < numBoundingVertices; i++)
                {
                    Vector3 v;
                    v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat();
                    _boundingVertices.Add(v);
                }
            }

            // get bounding normals
            if (numBoundingNormals > 0)
            {
                ms.Position = boundingNormalsOff;
                for (int i = 0; i < numBoundingNormals; i++)
                {
                    Vector3 v;
                    v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat();
                    _boundingNormals.Add(v);
                }
            }

            bbox = BoundingBox.CreateFromPoints(_boundingVertices);
        }
开发者ID:ostapus,项目名称:WoW2Mesh,代码行数:86,代码来源:m2.cs

示例6: Read

 public uint Read(MemoryStream ms)
 {
     id = (uint)ms.ReadInt32();
     uid = (uint)ms.ReadInt32();
     pos.X = ms.ReadFloat(); pos.Y = ms.ReadFloat(); pos.Z = ms.ReadFloat();
     rot.X = ms.ReadFloat(); rot.Y = ms.ReadFloat(); rot.Z = ms.ReadFloat();
     scale = (ushort)ms.ReadShort();
     flags = (ushort)ms.ReadShort();
     return 0;
 }
开发者ID:ostapus,项目名称:WoW2Mesh,代码行数:10,代码来源:wmo.cs

示例7: Read

 public void Read(MemoryStream ms)
 {
     startVertex = (ushort)ms.ReadShort();
     numVertices = (ushort)ms.ReadShort();
     normal.X = ms.ReadFloat(); normal.Y = ms.ReadFloat(); normal.Z = ms.ReadFloat();
     unknown = (uint)ms.ReadInt32();
 }
开发者ID:ostapus,项目名称:WoW2Mesh,代码行数:7,代码来源:wmo_model.cs

示例8: Deserialize

        public static object Deserialize(this CqlColumn cqlColumn, byte[] rawData)
        {
            //skip parsing and return null value when rawData is null
            if (rawData == null)
                return null;

            object data;
            Type colType;
            switch (cqlColumn.CqlType)
            {
                default:
                    data = Deserialize(cqlColumn.CqlType, rawData);
                    break;

                case CqlType.List:
                    if (!cqlColumn.CollectionValueType.HasValue)
                        throw new CqlException("CqlColumn collection type must has its value type set");

                    colType = cqlColumn.CollectionValueType.Value.ToType();
                    Type typedColl = typeof(List<>).MakeGenericType(colType);
                    var list = (IList)Activator.CreateInstance(typedColl);
                    using (var ms = new MemoryStream(rawData))
                    {
                        short nbElem = ms.ReadShort();
                        for (int i = 0; i < nbElem; i++)
                        {
                            byte[] elemRawData = ms.ReadShortByteArray();
                            object elem = Deserialize(cqlColumn.CollectionValueType.Value, elemRawData);
                            list.Add(elem);
                        }
                        data = list;
                    }
                    break;

                case CqlType.Set:
                    if (!cqlColumn.CollectionValueType.HasValue)
                        throw new CqlException("CqlColumn collection type must has its value type set");

                    colType = cqlColumn.CollectionValueType.Value.ToType();
                    Type tempListType = typeof(List<>).MakeGenericType(colType);
                    var tempList = (IList)Activator.CreateInstance(tempListType);
                    using (var ms = new MemoryStream(rawData))
                    {
                        short nbElem = ms.ReadShort();
                        for (int i = 0; i < nbElem; i++)
                        {
                            byte[] elemRawData = ms.ReadShortByteArray();
                            object elem = Deserialize(cqlColumn.CollectionValueType.Value, elemRawData);
                            tempList.Add(elem);
                        }

                        Type typedSet = typeof(HashSet<>).MakeGenericType(colType);
                        data = Activator.CreateInstance(typedSet, tempList);
                    }
                    break;

                case CqlType.Map:
                    if (!cqlColumn.CollectionKeyType.HasValue)
                        throw new CqlException("CqlColumn map type must has its key type set");

                    if (!cqlColumn.CollectionValueType.HasValue)
                        throw new CqlException("CqlColumn map type must has its value type set");

                    Type keyType = cqlColumn.CollectionKeyType.Value.ToType();
                    colType = cqlColumn.CollectionValueType.Value.ToType();
                    Type typedDic = typeof(Dictionary<,>).MakeGenericType(keyType, colType);
                    var dic = (IDictionary)Activator.CreateInstance(typedDic);
                    using (var ms = new MemoryStream(rawData))
                    {
                        short nbElem = ms.ReadShort();
                        for (int i = 0; i < nbElem; i++)
                        {
                            byte[] elemRawKey = ms.ReadShortByteArray();
                            byte[] elemRawValue = ms.ReadShortByteArray();
                            object key = Deserialize(cqlColumn.CollectionKeyType.Value, elemRawKey);
                            object value = Deserialize(cqlColumn.CollectionValueType.Value, elemRawValue);
                            dic.Add(key, value);
                        }
                        data = dic;
                    }
                    break;
            }

            return data;
        }
开发者ID:priyaparul,项目名称:CqlSharp,代码行数:85,代码来源:ValueSerialization.cs


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