Exemplo n.º 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;
     }
 }
Exemplo n.º 2
0
 public virtual void Write(char[] Data, EndianTypes EndianType)
 {
     if (EndianType == EndianTypes.BigEndian)
     {
         Array.Reverse(Data);
     }
     base.Write(Data);
 }
Exemplo n.º 3
0
        public virtual char[] ReadChars(int Count, EndianTypes EndianType)
        {
            var chars = base.ReadChars(Count);

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

            if (EndianType == EndianTypes.BigEndian)
            {
                Array.Reverse(data);
            }
            return(data);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
     }
 }
Exemplo n.º 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;
     }
 }
Exemplo n.º 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;
 }
Exemplo n.º 9
0
 public static ulong GetUInt64(byte[] Source, int Offset, EndianTypes Endian)
 {
     return((ulong)GetInt64(Source, Offset, Endian));
 }
Exemplo n.º 10
0
 public static uint GetUInt32(byte[] Source, int Offset, EndianTypes Endian)
 {
     return((uint)GetInt32(Source, Offset, Endian));
 }
Exemplo n.º 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));
 }
Exemplo n.º 12
0
 public virtual double ReadDouble(EndianTypes EndianType)
 {
     return(BitConverter.ToDouble(ReadBytes(8, EndianType), 0));
 }
Exemplo n.º 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]));
 }
Exemplo n.º 14
0
 public static void SetInt32(byte[] Dest, int Offset, int Value, EndianTypes Endian)
 {
     SetUInt32(Dest, Offset, (uint)Value, Endian);
 }
Exemplo n.º 15
0
 public static void SetInt64(byte[] Dest, int Offset, long Value, EndianTypes Endian)
 {
     SetUInt64(Dest, Offset, (ulong)Value, Endian);
 }
Exemplo n.º 16
0
 public EndianIO(byte[] ByteArray, EndianTypes EndianType) : this(new MemoryStream(ByteArray), EndianType)
 {
 }
Exemplo n.º 17
0
 /// <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;
 }
Exemplo n.º 18
0
 public virtual uint ReadUInt32(EndianTypes EndianType)
 {
     return(BitConverter.ToUInt32(ReadBytes(4, EndianType), 0));
 }
Exemplo n.º 19
0
 public virtual void Write(float Value, EndianTypes EndianType)
 {
     Write(BitConverter.GetBytes(Value), EndianType);
 }
Exemplo n.º 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]);
        }
Exemplo n.º 21
0
 public EndianWriter(Stream Input, EndianTypes EndianType) : base(Input)
 {
     this.EndianType = EndianType;
 }
Exemplo n.º 22
0
 public virtual float ReadSingle(EndianTypes EndianType)
 {
     return(BitConverter.ToSingle(ReadBytes(4, EndianType), 0));
 }
Exemplo n.º 23
0
        //Setting

        public static void SetInt16(byte[] Dest, int Offset, short Value, EndianTypes Endian)
        {
            SetUInt16(Dest, Offset, (ushort)Value, Endian);
        }
Exemplo n.º 24
0
        /// <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;
        }
Exemplo n.º 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]);
        }
Exemplo n.º 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]));
        }
Exemplo n.º 27
0
 public virtual ushort ReadUInt16(EndianTypes EndianType)
 {
     return(BitConverter.ToUInt16(ReadBytes(2, EndianType), 0));
 }
Exemplo n.º 28
0
 public static ushort GetUInt16(byte[] Source, int Offset, EndianTypes Endian)
 {
     return((ushort)GetInt16(Source, Offset, Endian));
 }
Exemplo n.º 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;
 }
Exemplo n.º 30
0
 public virtual ulong ReadUInt64(EndianTypes EndianType)
 {
     return(BitConverter.ToUInt64(ReadBytes(8, EndianType), 0));
 }