public T[] ReadStruct <T>(int count)
            where T : struct
        {
            T[] objects = new T[count];

            int typeSize = Marshal.SizeOf <T>();
            var bytes    = ReadBytes(typeSize * count);

            unsafe
            {
                fixed(byte *ptr = bytes)
                {
                    for (int i = 0; i < objects.Length; i++)
                    {
                        if (mSwap)
                        {
                            objects[i] = EndiannessHelper.Swap(Marshal.PtrToStructure <T>((IntPtr)(ptr + (i * typeSize))));
                        }
                        else
                        {
                            objects[i] = Marshal.PtrToStructure <T>((IntPtr)(ptr + (i * typeSize)));
                        }
                    }
                }
            }

            return(objects);
        }
        public void Write <T>(T[] value)
            where T : struct
        {
            // Allocate bytes for struct
            int typeSize = Marshal.SizeOf <T>();
            var bytes    = new byte[typeSize * value.Length];

            unsafe
            {
                fixed(byte *ptr = bytes)
                {
                    for (int i = 0; i < value.Length; i++)
                    {
                        // Marshal the structure into the allocated byte array
                        if (mSwap)
                        {
                            Marshal.StructureToPtr(EndiannessHelper.Swap(value[i]), (IntPtr)(ptr + (i * typeSize)), true);
                        }
                        else
                        {
                            Marshal.StructureToPtr(value[i], (IntPtr)(ptr + (i * typeSize)), true);
                        }
                    }
                }
            }

            // Lastly write out the bytes
            Write(bytes);
        }
        public void Write <T>(ref T value)
            where T : struct
        {
            // Allocate bytes for struct
            var bytes = new byte[Marshal.SizeOf <T>()];

            unsafe
            {
                fixed(byte *ptr = bytes)
                {
                    // Marshal the structure into the allocated byte array
                    if (mSwap)
                    {
                        Marshal.StructureToPtr(EndiannessHelper.Swap(value), (IntPtr)ptr, true);
                    }
                    else
                    {
                        Marshal.StructureToPtr(value, (IntPtr)ptr, true);
                    }
                }
            }

            // Lastly write out the bytes
            Write(bytes);
        }
 public override ulong ReadUInt64()
 {
     if (mSwap)
     {
         return(EndiannessHelper.Swap(base.ReadUInt64()));
     }
     return(base.ReadUInt64());
 }
 public override uint ReadUInt32()
 {
     if (mSwap)
     {
         return(EndiannessHelper.Swap(base.ReadUInt32()));
     }
     return(base.ReadUInt32());
 }
 public override float ReadSingle()
 {
     if (mSwap)
     {
         return(EndiannessHelper.Swap(base.ReadSingle()));
     }
     return(base.ReadSingle());
 }
 public override double ReadDouble()
 {
     if (mSwap)
     {
         return(EndiannessHelper.Swap(base.ReadDouble()));
     }
     return(base.ReadDouble());
 }
 public override decimal ReadDecimal()
 {
     if (mSwap)
     {
         return(EndiannessHelper.Swap(base.ReadDecimal()));
     }
     return(base.ReadDecimal());
 }
 public override short ReadInt16()
 {
     if (mSwap)
     {
         return(EndiannessHelper.Swap(base.ReadInt16()));
     }
     return(base.ReadInt16());
 }
        public T ReadStruct <T>()
            where T : struct
        {
            T obj;

            var bytes = ReadBytes(Marshal.SizeOf <T>());

            unsafe
            {
                fixed(byte *ptr = bytes)
                {
                    obj = Marshal.PtrToStructure <T>((IntPtr)ptr);
                }
            }

            if (mSwap)
            {
                obj = EndiannessHelper.Swap(obj);
            }

            return(obj);
        }
 public override void Write(decimal value)
 {
     base.Write(mSwap ? EndiannessHelper.Swap(value) : value);
 }
 public override void Write(ushort value)
 {
     base.Write(mSwap ? EndiannessHelper.Swap(value) : value);
 }