Example #1
0
 public static void SetUInt64(byte[] Dest, int Offset, ulong Value, EndianTypes Endian)
 {
     if (Endian == EndianTypes.LittleEndian)
     {
         Dest[Offset]     = (byte)Value;
         Dest[Offset + 1] = (byte)(Value >> 8);
         Dest[Offset + 2] = (byte)(Value >> 16);
         Dest[Offset + 3] = (byte)(Value >> 24);
         Dest[Offset + 4] = (byte)(Value >> 32);
         Dest[Offset + 5] = (byte)(Value >> 40);
         Dest[Offset + 6] = (byte)(Value >> 48);
         Dest[Offset + 7] = (byte)(Value >> 56);
     }
     else
     {
         Dest[Offset]     = (byte)(Value >> 56);
         Dest[Offset + 1] = (byte)(Value >> 48);
         Dest[Offset + 2] = (byte)(Value >> 40);
         Dest[Offset + 3] = (byte)(Value >> 32);
         Dest[Offset + 4] = (byte)(Value >> 24);
         Dest[Offset + 5] = (byte)(Value >> 16);
         Dest[Offset + 6] = (byte)(Value >> 8);
         Dest[Offset + 7] = (byte)Value;
     }
 }
Example #2
0
 public virtual void Write(char[] Data, EndianTypes EndianType)
 {
     if (EndianType == EndianTypes.BigEndian)
     {
         Array.Reverse(Data);
     }
     base.Write(Data);
 }
Example #3
0
        public virtual char[] ReadChars(int Count, EndianTypes EndianType)
        {
            var chars = base.ReadChars(Count);

            if (EndianType == EndianTypes.BigEndian)
            {
                Array.Reverse(chars);
            }
            return(chars);
        }
Example #4
0
        public virtual byte[] ReadBytes(int Count, EndianTypes EndianType)
        {
            var data = base.ReadBytes(Count);

            if (EndianType == EndianTypes.BigEndian)
            {
                Array.Reverse(data);
            }
            return(data);
        }
Example #5
0
        public virtual void WriteUInt56(ulong Value, EndianTypes EndianType)
        {
            if (Value > 0xFFFFFFFFFFFFFF)
            {
                throw new Exception("EndianWriter.WriteUInt56: Invalid value specified. It is too large for a uint56.");
            }
            var buffer = BitConverter.GetBytes(Value);

            Array.Resize(ref buffer, 7);
            Write(buffer, EndianType);
        }
Example #6
0
 public static void SetUInt16(byte[] Dest, int Offset, ushort Value, EndianTypes Endian)
 {
     if (Endian == EndianTypes.LittleEndian)
     {
         Dest[Offset]     = (byte)Value;
         Dest[Offset + 1] = (byte)(Value >> 8);
     }
     else
     {
         Dest[Offset]     = (byte)(Value >> 8);
         Dest[Offset + 1] = (byte)Value;
     }
 }
Example #7
0
 public static void SetUInt32(byte[] Dest, int Offset, uint Value, EndianTypes Endian)
 {
     if (Endian == EndianTypes.LittleEndian)
     {
         Dest[Offset]     = (byte)Value;
         Dest[Offset + 1] = (byte)(Value >> 8);
         Dest[Offset + 2] = (byte)(Value >> 16);
         Dest[Offset + 3] = (byte)(Value >> 24);
     }
     else
     {
         Dest[Offset]     = (byte)(Value >> 24);
         Dest[Offset + 1] = (byte)(Value >> 16);
         Dest[Offset + 2] = (byte)(Value >> 8);
         Dest[Offset + 3] = (byte)Value;
     }
 }
Example #8
0
 public EndianIO(Stream Stream, EndianTypes EndianType)
 {
     if (!Stream.CanSeek)
     {
         throw new Exception("EndianIO: Invalid stream specified. It doesn't support seeking.");
     }
     if (Stream.CanRead)
     {
         rdr = new EndianReader(Stream, EndianType);
     }
     if (Stream.CanWrite)
     {
         wtr = new EndianWriter(Stream, EndianType);
     }
     this.EndianType = EndianType;
     this.Stream     = Stream;
     IsOpen          = true;
 }
Example #9
0
 public static ulong GetUInt64(byte[] Source, int Offset, EndianTypes Endian)
 {
     return((ulong)GetInt64(Source, Offset, Endian));
 }
Example #10
0
 public static uint GetUInt32(byte[] Source, int Offset, EndianTypes Endian)
 {
     return((uint)GetInt32(Source, Offset, Endian));
 }
Example #11
0
 public static long GetInt64(byte[] Source, int Offset, EndianTypes Endian)
 {
     return(Endian == EndianTypes.LittleEndian ? (uint)(((Source[Offset] | (Source[Offset + 1] << 8)) | (Source[Offset + 2] << 0x10)) | (Source[Offset + 3] << 0x18)) | ((long)(((Source[Offset + 4] | (Source[Offset + 5] << 8)) | (Source[Offset + 6] << 0x10)) | (Source[Offset + 7] << 0x18)) << 32) : (uint)((((Source[Offset + 4] << 0x18) | (Source[Offset + 5] << 0x10)) | (Source[Offset + 6] << 8)) | Source[Offset + 7]) | ((long)((((Source[Offset] << 0x18) | (Source[Offset + 1] << 0x10)) | (Source[Offset + 2] << 8)) | Source[Offset + 3]) << 32));
 }
Example #12
0
 public virtual double ReadDouble(EndianTypes EndianType)
 {
     return(BitConverter.ToDouble(ReadBytes(8, EndianType), 0));
 }
Example #13
0
 public static int GetInt32(byte[] Source, int Offset, EndianTypes Endian)
 {
     return(Endian == EndianTypes.LittleEndian ? (((Source[Offset] | (Source[Offset + 1] << 8)) | (Source[Offset + 2] << 0x10)) | (Source[Offset + 3] << 0x18)) : ((((Source[Offset] << 0x18) | (Source[Offset + 1] << 0x10)) | (Source[Offset + 2] << 8)) | Source[Offset + 3]));
 }
Example #14
0
 public static void SetInt32(byte[] Dest, int Offset, int Value, EndianTypes Endian)
 {
     SetUInt32(Dest, Offset, (uint)Value, Endian);
 }
Example #15
0
 public static void SetInt64(byte[] Dest, int Offset, long Value, EndianTypes Endian)
 {
     SetUInt64(Dest, Offset, (ulong)Value, Endian);
 }
Example #16
0
 public EndianIO(byte[] ByteArray, EndianTypes EndianType) : this(new MemoryStream(ByteArray), EndianType)
 {
 }
 /// <summary>
 /// Converts a byte array into a DIS1998 PDU
 /// </summary>
 /// <param name="rawPDU">Byte array that hold raw 1998 PDU</param>
 /// <param name="pdu_type">Type of pdu</param>
 /// <returns>PDU object</returns>
 public DIS1998net.Pdu ConvertByteArrayToPDU1998(uint pdu_type, byte[] rawPDU, EndianTypes.Endian endian)
 {
     DIS1998net.Pdu pdu = DISnet.Utilities.PDUBank.GetPDU(pdu_type);
     DataInputStream ds = new DataInputStream(rawPDU, endian);
     ReturnUnmarshalledPDU(pdu, ds);
     return pdu;
 }
Example #18
0
 public virtual uint ReadUInt32(EndianTypes EndianType)
 {
     return(BitConverter.ToUInt32(ReadBytes(4, EndianType), 0));
 }
Example #19
0
 public virtual void Write(float Value, EndianTypes EndianType)
 {
     Write(BitConverter.GetBytes(Value), EndianType);
 }
Example #20
0
        public virtual ulong ReadUInt56(EndianTypes EndianType)
        {
            var array = ReadBytes(7, EndianType);

            return((ulong)array[6] << 48 | (ulong)array[5] << 40 | (ulong)array[4] << 32 | (ulong)array[3] << 24 | (ulong)array[2] << 16 | (ulong)array[1] << 8 | (ulong)array[0]);
        }
Example #21
0
 public EndianWriter(Stream Input, EndianTypes EndianType) : base(Input)
 {
     this.EndianType = EndianType;
 }
Example #22
0
 public virtual float ReadSingle(EndianTypes EndianType)
 {
     return(BitConverter.ToSingle(ReadBytes(4, EndianType), 0));
 }
Example #23
0
        //Setting

        public static void SetInt16(byte[] Dest, int Offset, short Value, EndianTypes Endian)
        {
            SetUInt16(Dest, Offset, (ushort)Value, Endian);
        }
        /// <summary>
        /// Converts a byte array into a DIS1998 PDU
        /// </summary>
        /// <param name="rawPDU">Byte array that hold raw 1998 PDU</param>
        /// <param name="pdu_type">Type of pdu</param>
        /// <returns>PDU object</returns>
        public DIS1998net.Pdu ConvertByteArrayToPDU1998(byte pdu_type, byte[] rawPDU, EndianTypes.Endian endian)
        {
            DIS1998net.Pdu pdu = DISnet.Utilities.PDUBank.GetPDU(pdu_type);
            DataInputStream ds = new DataInputStream(rawPDU, endian);

            //ReturnUnmarshalledPDU(pdu, ds);  //Removed this method to get rid of using Reflection
            return UnMarshalRawPDU(pdu_type, rawPDU, endian);
            //return pdu;
        }
Example #25
0
        public virtual uint ReadUInt24(EndianTypes EndianType)
        {
            var array = ReadBytes(3, EndianType);

            return((uint)(array[2] << 16) | (uint)(array[1] << 8) | (uint)array[0]);
        }
Example #26
0
        //Getting

        public static short GetInt16(byte[] Source, int Offset, EndianTypes Endian)
        {
            return(Endian == EndianTypes.LittleEndian ? (short)(Source[Offset] | (Source[Offset + 1] << 8)) : (short)((Source[Offset] << 8) | Source[Offset + 1]));
        }
Example #27
0
 public virtual ushort ReadUInt16(EndianTypes EndianType)
 {
     return(BitConverter.ToUInt16(ReadBytes(2, EndianType), 0));
 }
Example #28
0
 public static ushort GetUInt16(byte[] Source, int Offset, EndianTypes Endian)
 {
     return((ushort)GetInt16(Source, Offset, Endian));
 }
Example #29
0
 public EndianIO(string FileLocation, EndianTypes EndianType, FileMode Mode = FileMode.Open, FileAccess Access = FileAccess.ReadWrite, FileShare Share = FileShare.Read) : this(new FileStream(FileLocation, Mode, Access, Share), EndianType)
 {
     this.FileLocation = FileLocation;
 }
Example #30
0
 public virtual ulong ReadUInt64(EndianTypes EndianType)
 {
     return(BitConverter.ToUInt64(ReadBytes(8, EndianType), 0));
 }