Esempio n. 1
0
 public unsafe static long[] GetSizes(this object structure)
 {
     return(Extractor.GetSizes(structure));
 }
Esempio n. 2
0
 public unsafe static object StructureFrom(this object structure, byte *binary)
 {
     return(Extractor.PointerToStructure(binary, structure));
 }
Esempio n. 3
0
 public unsafe static byte *GetStructurePointer(this object structure)
 {
     return(Extractor.GetStructurePointer(structure));
 }
Esempio n. 4
0
 public unsafe static IntPtr GetStructureIntPtr(this object structure)
 {
     return(Extractor.GetStructureIntPtr(structure));
 }
Esempio n. 5
0
 public unsafe static void StructureTo(this object structure, ref byte[] binary, long offset = 0)
 {
     Extractor.StructureToBytes(structure, ref binary, offset);
 }
Esempio n. 6
0
 public unsafe static byte[] GetStructureBytes(this object structure)
 {
     return(Extractor.GetStructureBytes(structure));
 }
Esempio n. 7
0
 public unsafe static object StructureFrom(this object structure, byte[] binary, long offset = 0)
 {
     return(Extractor.BytesToStructure(binary, structure, offset));
 }
Esempio n. 8
0
 public unsafe static void StructureTo(this object structure, IntPtr binary)
 {
     Extractor.StructureToPointer(structure, binary);
 }
 public unsafe static void StructureFrom(this ValueType structure, byte *binary)
 {
     structure = Extractor.PointerToStructure(binary, structure);
 }
 public unsafe static Byte[] GetBytes(this ValueType objvalue)
 {
     return(Extractor.GetStructureBytes(objvalue));
 }
 public unsafe static void StructureFrom(this ValueType structure, byte[] binary, long offset = 0)
 {
     structure = Extractor.BytesToStructure(binary, structure, offset);
 }
Esempio n. 12
0
        /// <summary>
        /// The GetBytes.
        /// </summary>
        /// <param name="obj">The obj<see cref="IList"/>.</param>
        /// <param name="forKeys">The forKeys<see cref="bool"/>.</param>
        /// <returns>The <see cref="Byte[]"/>.</returns>
        public unsafe static Byte[] GetBytes(this IList obj, bool forKeys = false)
        {
            int   length = 256, offset = 0, postoffset = 0, count = obj.Count, charsize = sizeof(char), s = 0;
            byte *buffer   = stackalloc byte[length];
            bool  toResize = false;

            for (int i = 0; i < count; i++)
            {
                object o = obj[i];
                if (o is string)
                {
                    string str = ((string)o);
                    s          = str.Length * charsize;
                    postoffset = (s + offset);

                    if (postoffset > length)
                    {
                        toResize = true;
                    }
                    else
                        fixed(char *c = str)
                        Extractor.CopyBlock(buffer, (byte *)c, offset, s);
                }
                else
                {
                    if (o is IUnique)
                    {
                        s          = 8;
                        postoffset = (s + offset);

                        if (postoffset > length)
                        {
                            toResize = true;
                        }
                        else
                        {
                            *((ulong *)(buffer + offset)) = ((IUnique)o).UniqueKey;
                        }
                    }
                    else
                    {
                        s          = o.GetSize();
                        postoffset = (s + offset);

                        if (postoffset > length)
                        {
                            toResize = true;
                        }
                        else
                        {
                            Extractor.StructureToPointer(o, new IntPtr(buffer + offset));
                        }
                    }
                }

                if (toResize)
                {
                    i--;
                    toResize = false;
                    byte *_buffer = stackalloc byte[postoffset];
                    Extractor.CopyBlock(_buffer, buffer, offset);
                    buffer = _buffer;
                    length = postoffset;
                }
                else
                {
                    offset = postoffset;
                }
            }

            byte[] result = new byte[offset];
            fixed(byte *result_p = result)
            {
                Extractor.CopyBlock(result_p, buffer, offset);
            }

            return(result);
        }
Esempio n. 13
0
 /// <summary>
 /// The GetSize.
 /// </summary>
 /// <param name="structure">The structure<see cref="object"/>.</param>
 /// <returns>The <see cref="int"/>.</returns>
 public unsafe static int GetSize(this object structure)
 {
     return(Extractor.GetSize(structure));
 }