GSF.IO.BinaryStreamBase.ReadGuid C# (CSharp) Method

ReadGuid() public method

Reads from the underlying stream in little endian format. Advancing the position.
public ReadGuid ( ) : System.Guid
return System.Guid
        public Guid ReadGuid()
        {
            ReadAll(m_buffer, 0, 16);

            Guid rv;
            byte* dst = (byte*)&rv;
            fixed (byte* src = m_buffer)
            {
                if (BitConverter.IsLittleEndian)
                {
                    //internal stucture is correct, just copy
                    *(long*)(dst + 0) = *(long*)(src + 0);
                    *(long*)(dst + 8) = *(long*)(src + 8);
                }
                else
                {
                    //Guid._a (int) //swap endian
                    dst[0] = src[3];
                    dst[1] = src[2];
                    dst[2] = src[1];
                    dst[3] = src[0];
                    //Guid._b (short) //swap endian
                    dst[4] = src[5];
                    dst[5] = src[4];
                    //Guid._c (short) //swap endian
                    dst[6] = src[7];
                    dst[7] = src[6];
                    //Guid._d - Guid._k (8 bytes)
                    *(long*)(dst + 8) = *(long*)(src + 8);
                }

                return rv;
            }
        }
        /// <summary>

Usage Example

 /// <summary>
 /// Reads the header data.
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="treeNodeType"></param>
 /// <param name="blockSize"></param>
 internal static void ReadHeader(BinaryStreamBase stream, out EncodingDefinition treeNodeType, out int blockSize)
 {
     stream.Position = 0;
     byte version = stream.ReadUInt8();
     if (version == 109)
     {
         stream.Position = 0;
         stream.ReadGuid();
         treeNodeType = new EncodingDefinition(stream.ReadGuid());
         blockSize = stream.ReadInt32();
     }
     else if (version == 1)
     {
         blockSize = stream.ReadInt32();
         treeNodeType = new EncodingDefinition(stream);
     }
     else
     {
         throw new VersionNotFoundException();
     }
 }
All Usage Examples Of GSF.IO.BinaryStreamBase::ReadGuid