Deserialize() public abstract method

Creates a new instance from bytes.
public abstract Deserialize ( Byte content ) : Value
content Byte The binary content.
return Value
コード例 #1
0
ファイル: SubPlotValue.cs プロジェクト: bluntwcrackrap/YAMP
        /// <summary>
        /// Creates a new instance from a given binary content.
        /// </summary>
        /// <param name="content">The binary content.</param>
        /// <returns>The new instance.</returns>
        public override Value Deserialize(byte[] content)
        {
            var sp = new SubPlotValue();

            using (var ds = Deserializer.Create(content))
            {
                sp.Title   = ds.GetString();
                sp.Rows    = ds.GetInt();
                sp.Columns = ds.GetInt();
                var length = ds.GetInt();

                for (var i = 0; i < length; i++)
                {
                    var subplot = new SubPlot();
                    subplot.Row        = ds.GetInt();
                    subplot.RowSpan    = ds.GetInt();
                    subplot.Column     = ds.GetInt();
                    subplot.ColumnSpan = ds.GetInt();
                    var name = ds.GetString();
                    subplot.Plot = (PlotValue)Value.Deserialize(name, ds.GetBytes());
                    sp.subplots.Add(subplot);
                }
            }

            return(sp);
        }
コード例 #2
0
 /// <summary>
 /// Reads the next value.
 /// </summary>
 /// <returns>The deserialized value.</returns>
 public Value GetValue()
 {
     var header = GetString();
     var content = GetBytes();
     return Value.Deserialize(header, content);
 }
コード例 #3
0
        static IDictionary <string, Value> Load(string filename, out bool error)
        {
            var ht        = new Dictionary <string, Value>();
            var lenbuffer = new byte[4];
            var ctnbuffer = new byte[0];

            error = false;

            using (var fs = File.Open(filename, FileMode.Open))
            {
                while (fs.Position < fs.Length)
                {
                    fs.Read(lenbuffer, 0, lenbuffer.Length);
                    var length = BitConverter.ToInt32(lenbuffer, 0);

                    if (fs.Position + length > fs.Length || length < 0)
                    {
                        error = true;
                        break;
                    }

                    ctnbuffer = new byte[length];
                    fs.Read(ctnbuffer, 0, ctnbuffer.Length);
                    var name = Encoding.Unicode.GetString(ctnbuffer);

                    fs.Read(lenbuffer, 0, lenbuffer.Length);
                    length = BitConverter.ToInt32(lenbuffer, 0);

                    if (fs.Position + length > fs.Length || length < 0)
                    {
                        error = true;
                        break;
                    }

                    ctnbuffer = new byte[length];
                    fs.Read(ctnbuffer, 0, ctnbuffer.Length);
                    var header = Encoding.ASCII.GetString(ctnbuffer);

                    fs.Read(lenbuffer, 0, lenbuffer.Length);
                    length = BitConverter.ToInt32(lenbuffer, 0);

                    if (fs.Position + length > fs.Length || length < 0)
                    {
                        error = true;
                        break;
                    }

                    ctnbuffer = new byte[length];
                    fs.Read(ctnbuffer, 0, ctnbuffer.Length);
                    var value = Value.Deserialize(header, ctnbuffer);
                    ht.Add(name, value);
                }
            }

            if (error)
            {
                ht.Add("FileParsingError", Value.Empty);
            }

            return(ht);
        }