Example #1
0
        /// <summary>
        /// Writes a structure of type T into a slice of bytes.
        /// </summary>
        public static void Write <[Primitive] T>(this Slice <byte> slice, T value)
            where T : struct
        {
            Contract.Requires(slice.Length >= PtrUtils.SizeOf <T>());
            var cast = slice.Cast <byte, T>();

            cast[0] = value;
        }
Example #2
0
 /// <summary>
 /// Reads a structure of type T out of a slice of bytes.
 /// </summary>
 public static T Read <[Primitive] T>(this Slice <byte> slice)
     where T : struct
 {
     Contract.Requires(slice.Length >= PtrUtils.SizeOf <T>());
     return(slice.Cast <byte, T>()[0]);
 }