Пример #1
0
        public virtual void Serialize(BitWriter writer, BitWriter fork)
        {
            switch (id)
            {
            case 9:
                offset = (uint)(fork.offset + fork.Length);
                data.Serialize(fork);

                size = (uint)(fork.offset + fork.Length) - offset;
                size = 3760;     // ¯\_(ツ)_/¯
                break;

            case 2:
                size   = 286;
                offset = 3810;
                break;

            default:
                Console.WriteLine($"Unknown Entry type id '{id}'");
                break;
            }

            writer.Write(id);
            writer.Write(offset);
            writer.Write(size);
        }
Пример #2
0
 public void WriteFile(string path, IBinarySerializable value)
 {
     using (var stream = _fileSystem.CreateFile(path))
     {
         value.Serialize(stream);
     }
 }
Пример #3
0
 public void Write(IBinarySerializable value)
 {
     if (value == null)
     {
         Write((ulong)0);
     }
     else
     {
         ulong token;
         if (writeCache.TryGetValue(value, out token))
         {
             Write(token);
         }
         else
         {
             token = (ulong)writeCache.Count + 1;
             writeCache.Add(value, token);
             Write(token);
             Write(value.GetType());
             using (var writer = new Serializer(this))
             {
                 value.Serialize(writer);
             }
         }
     }
 }
        /// <summary>
        /// Serializes an object to a <see cref="MemoryStream"/> using a <see cref="Formatters.Binary.BinaryFormatter"/>.
        /// </summary>
        /// <param name="instance">The instance to serialize.</param>
        /// <returns>The <see cref="Stream"/> to serialize the <paramref name="instance"/> too.</returns>
        /// <exception cref="ArgumentNullException"> thrown if the <paramref name="instance"/> or <paramref name="stream"/> is <c>Null</c>.</exception>
        public static MemoryStream Serialize(this IBinarySerializable instance)
        {
            MemoryStream stream = new MemoryStream();

            instance.Serialize(stream);

            return(stream);
        }
Пример #5
0
        public static byte[] Write(IBinarySerializable binaryObject)
        {
            BitWriter br = new BitWriter(0);

            binaryObject.Serialize(br);
            byte[] bytes = br.GetBytes().ToArray();
            return(bytes);
        }
 public static void SerializeToFile(this IBinarySerializable obj, string path)
 {
     using (Stream stream = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.Write))
         using (var writer = new BinaryWriter(stream))
         {
             obj.Serialize(writer);
         }
 }
 public static byte[] SerializeToBytes(this IBinarySerializable obj)
 {
     using (var stream = new MemoryStream())
         using (var writer = new BinaryWriter(stream))
         {
             obj.Serialize(writer);
             return(stream.ToArray());
         }
 }
Пример #8
0
        public void SerializeFork(BitWriter fork)
        {
            valueOffset = (uint)(fork.offset + fork.Length);

            value.Serialize(fork);

            valueLen = (uint)(fork.offset + fork.Length) - valueOffset;

            nameLen = (byte)name.Length;
        }
Пример #9
0
 /// <summary>
 /// Writes the specified value.
 /// </summary>
 /// <param name="value">The value.</param>
 public void Write(IBinarySerializable value)
 {
     if (value == null)
     {
         WriteClassId(0);
     }
     else
     {
         value.Serialize(this);
     }
 }
Пример #10
0
 public static void Write(this BinaryWriter writer, IBinarySerializable obj)
 {
     obj.Serialize(writer);
 }
Пример #11
0
 public void Write(IBinarySerializable item)
 {
     item.Serialize(this);
 }
Пример #12
0
 // Custom
 public void Write(IBinarySerializable data)
 {
     data.Serialize(this);
 }
Пример #13
0
        private void Serialize(object o, Type type)
        {
            // Check for primitive types.
            if (type.IsPrimitive())
            {
                this.SerializePrimitive(o);
                return;
            }

            // Check for string.
            if (type == typeof(string))
            {
                string s = (string)o;
                this.writer.Write(string.IsNullOrEmpty((string)o) ? string.Empty : s);
                return;
            }

            // Check for derived types.
            if (type == typeof(ValueWithType))
            {
                this.SerializeValueWithType((ValueWithType)o);
                return;
            }

            // Check for list.
            if (typeof(IList).IsAssignableFrom(type))
            {
                this.SerializeList((IList)o);
                return;
            }

            // Check for dictionary.
            if (typeof(IDictionary).IsAssignableFrom(type))
            {
                this.SerializeDictionary((IDictionary)o);
                return;
            }

            // Check for enum.
            if (type.IsEnum())
            {
                this.writer.Write(o.ToString());
                return;
            }

            // Check for custom implementation.
            if (typeof(IBinarySerializable).IsAssignableFrom(type))
            {
                IBinarySerializable binarySerializable = (IBinarySerializable)o;
                binarySerializable.Serialize(this);
                return;
            }

            // Serialize with reflection.
            try
            {
                this.SerializeReflection(o);
            }
            catch (Exception e)
            {
                throw new SerializationException(string.Format("Unsupported type: {0}", type.Name), e);
            }
        }
Пример #14
0
        protected override void SerializeOverride(IBitStream stream, EventShuttle eventShuttle)
        {
            var serializationContext = CreateSerializationContext();

            _binarySerializable.Serialize(stream.BaseStream, Endianness, serializationContext);
        }
Пример #15
0
 /// <summary>
 /// Writes the specified value.
 /// </summary>
 /// <param name="value">The value.</param>
 public void Write(IBinarySerializable value)
 {
     if (value == null)
         WriteClassId(0);
     else
         value.Serialize(this);
 }
Пример #16
0
 public void Write(IBinarySerializable serializable)
 {
     serializable.Serialize(this);
 }
Пример #17
0
 public static void Write(this BinaryWriter writer, IBinarySerializable value)
 {
     value.Serialize(writer);
 }