Ejemplo n.º 1
0
        public SpiConnection(ProcessorPin clock, ProcessorPin ss, ProcessorPin? miso, ProcessorPin? mosi, Endianness endianness)
        {
            this.clock = clock;
            this.ss = ss;
            this.miso = miso;
            this.mosi = mosi;
            this.endianness = endianness;

            driver = GpioConnectionSettings.DefaultDriver;

            driver.Allocate(clock, PinDirection.Output);
            driver.Write(clock, false);

            driver.Allocate(ss, PinDirection.Output);
            driver.Write(ss, true);

            if (mosi.HasValue)
            {
                driver.Allocate(mosi.Value, PinDirection.Output);
                driver.Write(mosi.Value, false);
            }

            if (miso.HasValue)
                driver.Allocate(miso.Value, PinDirection.Input);
        }
Ejemplo n.º 2
0
 protected EncoderBase(int bufsize, Endianness endian)
 {
     Endian = endian;
     m_buffersize = bufsize;
     m_buf = new byte[bufsize];
     m_error = false;
 }
Ejemplo n.º 3
0
        public static void SaveImage(this FloatMapImage image, string filename, Endianness endianness)
        {
            FileStream fs = new FileStream(filename, FileMode.Create);

            // write the header
            SaveHeader(fs, image, endianness);

            // write the image data
            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    for (int band = 0; band < image.TotalChannelsCount; band++)
                    {
                        float intensity = image.Image[x, y, band];
                        byte[] rawIntensity = BitConverter.GetBytes(intensity);
                        if (endianness == Endianness.BigEndian)
                        {
                            // swap the bytes from little to big endian
                            SwapFloatEndianness(ref rawIntensity);
                        }
                        // write one float
                        fs.Write(rawIntensity, 0, rawIntensity.Length);
                    }
                }
            }

            fs.Flush();
            fs.Close();
        }
        public static byte[] ReadBytes(this BinaryReader binaryReader, Int32 count, Endianness endianness)
        {
            if (endianness == Endianness.Little)
                return binaryReader.ReadBytes(count);

            return binaryReader.ReadBytes(count).Reverse().ToArray();
        }
Ejemplo n.º 5
0
 public RawDecoder(int bufferSize, long maxMsgSize, IMsgSink msgSink,
   Endianness endianness)
     : base(bufferSize, endianness)
 {
     m_msgSink = msgSink;
     m_maxMsgSize = maxMsgSize;
 }
Ejemplo n.º 6
0
        public float ReadSingle(Endianness endianness)
        {
            if (endianness == Endianness.LittleEndian) { return base.ReadSingle(); }

            byte[] b = base.ReadBytes(4);
            return BitConverter.ToSingle(b.Reverse().ToArray(), 0);
        }
Ejemplo n.º 7
0
        public int ReadInt32(Endianness endianness)
        {
            int val = base.ReadInt32();

            if (endianness == Endianness.LittleEndian) { return val; }
            else { return System.Net.IPAddress.NetworkToHostOrder(val); }
        }
Ejemplo n.º 8
0
        public RawEncoder(int bufferSize, IMsgSource msgSource, Endianness endianness)
            : base(bufferSize, endianness)
        {
            m_msgSource = msgSource;

            NextStep(null, 0, RawMessageReadyState, true);
        }
 public BlenderFileHeaderToken(string identifer, int sz, Endianness endianness, string version)
 {
     Identifier = identifer;
     PointerSize = sz;
     Endianness = endianness;
     Version = version;
 }
Ejemplo n.º 10
0
        public UInt24(byte[] bytes, Endianness endianness)
        {
            if (bytes == null) throw new ArgumentNullException("bytes");
            if (bytes.Length != 3) throw new ArgumentException("UInt24 should consist of exactly 3 bytes.", "bytes");

            _bytes = ConvertConditional(bytes, endianness);
        }
 public static void WriteEndian(this BinaryWriter BinaryWriter, uint Value, Endianness Endian)
 {
     BinaryWriter.Write((byte)((Value >> 24) & 0xFF));
     BinaryWriter.Write((byte)((Value >> 16) & 0xFF));
     BinaryWriter.Write((byte)((Value >> 8) & 0xFF));
     BinaryWriter.Write((byte)((Value >> 0) & 0xFF));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Write the given 64-bit value into the buffer, at the position marked by the offset plus the given index i.
 /// </summary>
 /// <param name="endian">an Endianness to specify in which order to write the bytes</param>
 /// <param name="value">the 64-bit value to write into the byte-array buffer</param>
 /// <param name="i">the index position beyond the offset to start writing the bytes</param>
 public void PutLong(Endianness endian, long value, int i)
 {
     if (endian == Endianness.Big)
     {
         m_innerBuffer[i + Offset] = (byte)(((value) >> 56) & 0xff);
         m_innerBuffer[i + Offset + 1] = (byte)(((value) >> 48) & 0xff);
         m_innerBuffer[i + Offset + 2] = (byte)(((value) >> 40) & 0xff);
         m_innerBuffer[i + Offset + 3] = (byte)(((value) >> 32) & 0xff);
         m_innerBuffer[i + Offset + 4] = (byte)(((value) >> 24) & 0xff);
         m_innerBuffer[i + Offset + 5] = (byte)(((value) >> 16) & 0xff);
         m_innerBuffer[i + Offset + 6] = (byte)(((value) >> 8) & 0xff);
         m_innerBuffer[i + Offset + 7] = (byte)(value & 0xff);
     }
     else
     {
         m_innerBuffer[i + Offset + 7] = (byte)(((value) >> 56) & 0xff);
         m_innerBuffer[i + Offset + 6] = (byte)(((value) >> 48) & 0xff);
         m_innerBuffer[i + Offset + 5] = (byte)(((value) >> 40) & 0xff);
         m_innerBuffer[i + Offset + 4] = (byte)(((value) >> 32) & 0xff);
         m_innerBuffer[i + Offset + 3] = (byte)(((value) >> 24) & 0xff);
         m_innerBuffer[i + Offset + 2] = (byte)(((value) >> 16) & 0xff);
         m_innerBuffer[i + Offset + 1] = (byte)(((value) >> 8) & 0xff);
         m_innerBuffer[i + Offset] = (byte)(value & 0xff);
     }
 }
Ejemplo n.º 13
0
 public void Unpack(Endianness endian, string path)
 {
     if (endian == Endianness.big)
         UnpackBigEndian(path);
     else if(endian == Endianness.little)
         UnpackLittleEndian(path);
 }
Ejemplo n.º 14
0
        public EndianReader(Stream input, Endianness endianess, Encoding encoding, bool leaveOpen)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }
            if (!input.CanRead)
                throw new ArgumentException("Can't read from the output stream", nameof(input));
            Contract.EndContractBlock();

            BaseStream = input;
            decoder = encoding.GetDecoder();
            maxCharsSize = encoding.GetMaxCharCount(MaxCharBytesSize);
            var minBufferSize = encoding.GetMaxByteCount(1);  // max bytes per one char
            if (minBufferSize < 16)
                minBufferSize = 16;
            buffer = new byte[minBufferSize];
            // m_charBuffer and m_charBytes will be left null.

            // For Encodings that always use 2 bytes per char (or more), 
            // special case them here to make Read() & Peek() faster.
            use2BytesPerChar = encoding is UnicodeEncoding;
            this.leaveOpen = leaveOpen;

            Endianness = endianess;
            resolvedEndianess = EndianessHelper.Resolve(endianess);

            Contract.Assert(decoder != null, "[EndianReader.ctor]m_decoder!=null");
        }
Ejemplo n.º 15
0
        //THIS IS UNFINISHED BECAUSE I CAN'T TEST IT. TRY IT LATER
        public static float ReadFloat(byte[] data, int position, Endianness endian = Endianness.BigEndian)
        {
            if (data == null || data.Length < position + 4)
                throw new Exception();

            byte[] bytes = new byte[4];
            Array.Copy(data, position, bytes, 0, 4);
            bytes = bytes.Reverse().ToArray();
            return BitConverter.ToSingle(bytes, 0);

            switch (endian)
            {
                case Endianness.BigEndian:
                    //Do nothing
                    break;
                case Endianness.LittleEndian:
                    //Reverse
                    break;
                case Endianness.ByteSwap:

                    break;
                case Endianness.WordSwap:

                    break;
            }

            return 0;
        }
Ejemplo n.º 16
0
        //THIS IS UNFINISHED BECAUSE I CAN'T TEST IT. TRY IT LATER
        public static byte ReadByte(byte[] data, int position, Endianness endian = Endianness.BigEndian)
        {
            if (data == null || data.Length < position)
                throw new Exception();

            return data[position];
        }
        public EndianBinaryWriter(Stream baseStream, Endianness endianness)
        {
            if (baseStream == null) throw new ArgumentNullException("baseStream");
            if (!baseStream.CanWrite) throw new ArgumentException("base stream is not writeable", "baseStream");

            BaseStream = baseStream;
            Endianness = endianness;
        }
Ejemplo n.º 18
0
 public DecoderBase(int bufsize, Endianness endian)
 {
     Endian = endian;
     m_toRead = 0;
     m_bufsize = bufsize;
     m_buf = new byte[bufsize];
     State = -1;
 }
        public EndianBinaryReader(Stream baseStream, Endianness endianness)
        {
            if (baseStream == null) throw new ArgumentNullException("baseStream");
            if (!baseStream.CanRead) throw new ArgumentException("baseStream");

            BaseStream = baseStream;
            Endianness = endianness;
        }
Ejemplo n.º 20
0
        public Encoder(int bufsize, Endianness endian)
            : base(bufsize, endian)
        {
            m_tmpbuf = new byte[10];

            //  Write 0 bytes to the batch and go to message_ready state.
            NextStep(m_tmpbuf, 0, MessageReadyState, true);
        }
Ejemplo n.º 21
0
        public static byte[] UInt64(UInt64 i, Endianness e = Endianness.Machine)
        {
            byte[] bytes = BitConverter.GetBytes(i);

            if (NeedsFlipping(e)) Array.Reverse(bytes);

            return bytes;
        }
Ejemplo n.º 22
0
        public static UInt32 UInt32(byte[] bytes, Int32 start, Endianness e = Endianness.Machine)
        {
            byte[] intBytes = Utils.GetBytes(bytes, start, 4);

            if (NeedsFlipping(e)) Array.Reverse(intBytes);

            return BitConverter.ToUInt32(intBytes, 0);
        }
Ejemplo n.º 23
0
 public BfsBinaryReader(BinaryReader binaryReader, Endianness fileEndianness)
 {
     reader = binaryReader;
         FileEndianness = fileEndianness;
         asciienc = new ASCIIEncoding();
         utf7enc = new UTF7Encoding();
         utf32enc = new UTF32Encoding();
 }
Ejemplo n.º 24
0
        public UInt24(IEnumerable<byte> bytes, Endianness endianness)
        {
            if (bytes == null) throw new ArgumentNullException("bytes");

            var bytesArray = bytes.ToArray();
            if (bytesArray.Length != 3) throw new ArgumentException("UInt24 should consist of exactly 3 bytes.", "bytes");

            _bytes = ConvertConditional(bytesArray, endianness);
        }
Ejemplo n.º 25
0
        public V1Encoder(int bufsize, IMsgSource session, Endianness endian)
            : base(bufsize, endian)
        {
            m_tmpbuf = new byte [9];
            m_msgSource = session;

            //  Write 0 bytes to the batch and go to message_ready state.
            NextStep(m_tmpbuf, 0, MessageReadyState, true);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Factory method for obtaining a converter for the specified "endianess".
        /// </summary>
        /// <param name="endianness">The endianness.</param>
        /// <returns></returns>
        public static EndianBitConverter GetConverter(Endianness endianness)
        {
            if (endianness == Endianness.LittleEndian)
            {
                return LittleEndianConverter;
            }

            return BigEndianConverter;
        }
Ejemplo n.º 27
0
        public Decoder(int bufsize, long maxmsgsize, Endianness endian)
            : base(bufsize, endian)
        {
            m_maxmsgsize = maxmsgsize;
            m_tmpbuf = new ByteArraySegment(new byte[8]);

            //  At the beginning, read one byte and go to one_byte_size_ready state.
            NextStep(m_tmpbuf, 1, OneByteSizeReadyState);
        }
Ejemplo n.º 28
0
        public V1Encoder(int bufferSize, Endianness endian)
            : base(bufferSize, endian)
        {
            m_inProgress = new Msg();
            m_inProgress.InitEmpty();

            // Write 0 bytes to the batch and go to message_ready state.
            NextStep(m_tmpbuf, 0, MessageReadyState, true);
        }
Ejemplo n.º 29
0
        public RawEncoder(int bufferSize, [NotNull] IMsgSource msgSource, Endianness endianness)
            : base(bufferSize, endianness)
        {
            m_msgSource = msgSource;

            m_inProgress = new Msg();
            m_inProgress.InitEmpty();

            NextStep(null, 0, RawMessageReadyState, true);
        }
Ejemplo n.º 30
0
 public ByteBuffer(Endianness _endianess, System.Text.Encoding _encoding)
 {
     stream = new MemoryStream();
     if (_endianess == Endianness.BigEndian)
         bitConverter = new BigEndianBitConverter();
     else
         bitConverter = new LittleEndianBitConverter();
     writer = new EndianBinaryWriter(bitConverter, stream, _encoding);
     reader = new EndianBinaryReader(bitConverter, stream, _encoding);
 }
Ejemplo n.º 31
0
 private static byte[] ConvertConditional(byte[] bytes, Endianness endianness)
 {
     return(endianness == Endianness.LittleEndian ? bytes :
            bytes.Reverse().ToArray());
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EndianBinaryWriter"/> class
 /// with the given bit converter, writing to the given stream, using UTF-8 encoding.
 /// </summary>
 /// <param name="endianness">Endianness to use when writing data</param>
 /// <param name="stream">Stream to write data to</param>
 public EndianBinaryWriter(Endianness endianness, Stream stream)
     : this(endianness, stream, Encoding.UTF8)
 {
 }
Ejemplo n.º 33
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EndianAwareBinaryReader" /> class based on the specified
 ///     stream, character encoding, and endianness.
 /// </summary>
 /// <param name="input">The input stream.</param>
 /// <param name="encoding">The character encoding to use.</param>
 /// <param name="endianness">The byte ordering to use.</param>
 public EndianAwareBinaryReader(Stream input, Encoding encoding, Endianness endianness) : base(input, encoding)
 {
     Endianness = endianness;
 }
Ejemplo n.º 34
0
 /// <summary>
 ///     Create a new EncoderBase with a buffer of the given size.
 /// </summary>
 /// <param name="bufferSize">how big of an internal buffer to allocate (in bytes)</param>
 /// <param name="endian">the <see cref="Endianness" /> to set this EncoderBase to</param>
 protected EncoderBase(int bufferSize, Endianness endian)
 {
     this.Endian       = endian;
     this.m_bufferSize = bufferSize;
     this.m_buffer     = new byte[bufferSize];
 }
Ejemplo n.º 35
0
 internal unsafe static extern int InitializeSecurityContextW(ref SSPIHandle credentialHandle, ref SSPIHandle contextHandle, [In] byte *targetName, [In] ContextFlags inFlags, [In] int reservedI, [In] Endianness endianness, [In] SecurityBufferDescriptor inputBuffer, [In] int reservedII, ref SSPIHandle outContextPtr, [In][Out] SecurityBufferDescriptor outputBuffer, [In][Out] ref ContextFlags attributes, out long timeStamp);
 public void WriteAsCharArray(string value, Endianness endianness = Endianness.Unspecified)
 {
     // nothing
 }
 public void WriteArray(float[] values, Endianness endianness = Endianness.Unspecified)
 {
     // nothing
 }
Ejemplo n.º 38
0
        public static ISegmentBuildDefinition ExtendedWithLengthAt <TOfType>(this ISegmentBuildDefinition builder, long position, Endianness endianness)
            where TOfType : unmanaged
        {
            if (!(builder is SegmentBuildDefinition def))
            {
                throw new NotSupportedException($"{builder.GetType()} is not supported");
            }
            if (!def.Length.HasValue)
            {
                throw new NotSupportedException("Must start with fixed length");
            }

            unsafe
            {
                def.ExtensionDefinition = new SegmentExtensionDefinition(type: typeof(TOfType), length: sizeof(TOfType), postion: position, endianness: endianness);
            }
            return(builder);
        }
Ejemplo n.º 39
0
 public static void WriteEndian(this BinaryWriter BinaryWriter, ushort Value, Endianness Endian)
 {
     BinaryWriter.Write((byte)((Value >> 8) & 0xFF));
     BinaryWriter.Write((byte)((Value >> 0) & 0xFF));
 }
 internal static ISerializationService CreateSerializationService(int version, Endianness order)
 {
     return(new SerializationServiceBuilder(new NullLoggerFactory())
            .SetEndianness(order).SetPortableVersion(version)
            .AddPortableFactory(SerializationTestsConstants.PORTABLE_FACTORY_ID, new TestPortableFactory())
            .AddDataSerializableFactory(SerializationTestsConstants.DATA_SERIALIZABLE_FACTORY_ID,
                                        GetDataSerializableFactory())
            .Build());
 }
Ejemplo n.º 41
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SpiConnection"/> class.
        /// </summary>
        /// <param name="clockPin">The clock pin.</param>
        /// <param name="selectSlavePin">The select slave pin.</param>
        /// <param name="misoPin">The miso pin.</param>
        /// <param name="mosiPin">The mosi pin.</param>
        /// <param name="endianness">The endianness.</param>
        public SpiConnection(IOutputBinaryPin clockPin, IOutputBinaryPin selectSlavePin, IInputBinaryPin misoPin, IOutputBinaryPin mosiPin, Endianness endianness)
        {
            this.clockPin       = clockPin;
            this.selectSlavePin = selectSlavePin;
            this.misoPin        = misoPin;
            this.mosiPin        = mosiPin;
            this.endianness     = endianness;

            clockPin.Write(false);
            selectSlavePin.Write(true);

            if (mosiPin != null)
            {
                mosiPin.Write(false);
            }
        }
Ejemplo n.º 42
0
 internal abstract IFDHeader GetMakerNotesHeader(byte[] makerNotesFieldBytes, Endianness e, ImageFile processingFile);
Ejemplo n.º 43
0
 internal abstract IFDHeader GetMakerNotesHeader(byte[] makerNotesFieldBytes, Endianness e);
 /// <summary>
 /// Determines whether this endianness is 'little-endian'.
 /// </summary>
 /// <param name="endianness">The endianness.</param>
 /// <returns>true if this endianness is 'little-endian'; otherwise false.</returns>
 public static bool IsLittleEndian(this Endianness endianness) => endianness == Endianness.LittleEndian;
 /// <summary>Converts the given object into a byte array</summary>
 /// <param name="Receiver">The array that receives the final data.</param>
 /// <param name="Value">The object to convert</param>
 /// <param name="endianness">Marks if little or big endian should be used</param>
 /// <param name="StartIndex">The startindex for the data</param>
 /// <returns>Converts the given object into a byte array</returns>
 public static Int32 OntoBytes(Byte[] Receiver, UInt64 Value, Endianness endianness, Int32 StartIndex = 0)
 {
     return(endianness == Endianness.BigEndian ?
            BigEndian.OntoBytes(Receiver, Value, StartIndex) :
            LittleEndian.OntoBytes(Receiver, Value, StartIndex));
 }
Ejemplo n.º 46
0
        public static Section_AHDR GetReversedEndian(Section_AHDR AHDR, Game previousGame, Game currentGame, Endianness previousEndianness)
        {
            EndianConverter e = new EndianConverter
            {
                previousGame       = previousGame,
                newGame            = currentGame,
                previousEndianness = previousEndianness,
                reader             = new BinaryReader(new MemoryStream(AHDR.data))
            };

            return(e.GetReversedEndian(AHDR));
        }
 public void Write(float value, Endianness endianness = Endianness.Unspecified)
 {
     // nothing
 }
Ejemplo n.º 48
0
 public static ushort ReadUShort(byte[] data, uint position, Endianness endian = Endianness.BigEndian)
 {
     return(ReadUShort(data, (int)position, endian));
 }
Ejemplo n.º 49
0
 public PACKManager(Endianness endian)
 {
     _endian = endian;
 }
Ejemplo n.º 50
0
 public static byte ReadByte(byte[] data, uint position, Endianness endian = Endianness.BigEndian)
 {
     return(ReadByte(data, (int)position, endian));
 }
Ejemplo n.º 51
0
 internal unsafe static extern int AcceptSecurityContext(ref SSPIHandle credentialHandle, ref SSPIHandle contextHandle, [In] SecurityBufferDescriptor inputBuffer, [In] ContextFlags inFlags, [In] Endianness endianness, ref SSPIHandle outContextPtr, [In][Out] SecurityBufferDescriptor outputBuffer, [In][Out] ref ContextFlags attributes, out long timeStamp);
Ejemplo n.º 52
0
 public static float ReadFloat(byte[] data, uint position, Endianness endian = Endianness.BigEndian)
 {
     return(ReadFloat(data, (int)position, endian));
 }
Ejemplo n.º 53
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EndianAwareBinaryReader" /> class based on the specified
 ///     stream and endianness using UTF-8 encoding.
 /// </summary>
 /// <param name="input">The input stream.</param>
 /// <param name="endianness">The byte ordering to use.</param>
 public EndianAwareBinaryReader(Stream input, Endianness endianness) : base(input)
 {
     Endianness = endianness;
 }
 /// <summary>
 /// Determines whether this endianness is 'big-endian'.
 /// </summary>
 /// <param name="endianness">The endianness.</param>
 /// <returns>true if this endianness is 'big-endian'; otherwise false.</returns>
 public static bool IsBigEndian(this Endianness endianness) => endianness == Endianness.BigEndian;
Ejemplo n.º 55
0
 public RawDatasetImporter(string filePath, int dimX, int dimY, int dimZ, DataContentFormat contentFormat, Endianness endianness, int skipBytes)
 {
     this.filePath      = filePath;
     this.dimX          = dimX;
     this.dimY          = dimY;
     this.dimZ          = dimZ;
     this.contentFormat = contentFormat;
     this.endianness    = endianness;
     this.skipBytes     = skipBytes;
 }
Ejemplo n.º 56
0
 /// <summary>
 /// Create a bit indexer that will index bits for values stored in the given format.
 /// </summary>
 /// <param name="byteOrder">The byte order.</param>
 /// <param name="bitOrder">The bit order.</param>
 internal EndianBitIndexer(Endianness byteOrder, Endianness bitOrder)
 {
     ByteOrder = byteOrder;
     BitOrder  = bitOrder;
 }
Ejemplo n.º 57
0
        public DataPort(string name, OneDasDataType dataType, DataDirection dataDirection, Endianness endianness)
        {
            this.Name          = name;
            this.DataType      = dataType;
            this.DataDirection = dataDirection;
            this.Endianness    = endianness;

            this.BitOffset = -1; // i.e. bool is treated as byte-oriented
        }
Ejemplo n.º 58
0
 public EndianAttribute(Endianness endianness)
 {
     this.Endianness = endianness;
 }
Ejemplo n.º 59
0
 // Token: 0x06000456 RID: 1110 RVA: 0x0000DF84 File Offset: 0x0000C184
 public RIFFWriter(Stream stream, string characterCode, Endianness endianness) : this(stream, characterCode, endianness, RIFFWriterOptions.Default)
 {
 }
 /// <summary>
 /// Resolves an endianness.
 /// </summary>
 /// <param name="endianness">The endianness.</param>
 /// <param name="defaultValue">An optional default value.</param>
 /// <returns>The <paramref name="endianness"/> if it is specified, else the <paramref name="defaultValue"/>.</returns>
 public static Endianness Resolve(this Endianness endianness, Endianness defaultValue = Endianness.BigEndian)
 => endianness switch
 {