Ejemplo n.º 1
0
        public void BinDumpBinaryStreams_TestIntWrites()
        {
            int[] values = new int[] { 0, 1, -1, 10, -10, 32767, 32768, -32767, -32768, int.MinValue, int.MaxValue };

            using (MemoryStream ms_orig = new MemoryStream())
            {
                UndisposableStream ms = new UndisposableStream(ms_orig);

                using (BinDumpBinaryWriter bdbw = new BinDumpBinaryWriter(ms, Encoding.UTF8))
                {
                    for (int i = 0; i < values.Length; i++)
                    {
                        bdbw.Write(values[i]);
                    }
                }

                ms.Seek(0, SeekOrigin.Begin);

                using (BinDumpBinaryReader bdbr = new BinDumpBinaryReader(ms, Encoding.UTF8))
                {
                    for (int i = 0; i < values.Length; i++)
                    {
                        int v = bdbr.ReadInt32();
                        Assert.AreEqual(values[i], v, "i = " + i.ToString());
                    }
                }
            }
        }
Ejemplo n.º 2
0
        internal int Undump(Stream stream, int sourceID, Table envTable, out bool hasUpvalues)
        {
            int       baseAddress = m_RootChunk.Code.Count;
            SourceRef sourceRef   = new SourceRef(sourceID, 0, 0, 0, 0, false);

            using (BinaryReader br = new BinDumpBinaryReader(stream, Encoding.UTF8))
            {
                ulong headerMark = br.ReadUInt64();

                if (headerMark != DUMP_CHUNK_MAGIC)
                {
                    throw new ArgumentException("Not a MoonSharp chunk");
                }

                int version = br.ReadInt32();

                if (version != DUMP_CHUNK_VERSION)
                {
                    throw new ArgumentException("Invalid version");
                }

                hasUpvalues = br.ReadBoolean();

                int len = br.ReadInt32();

                int         numSymbs = br.ReadInt32();
                SymbolRef[] allSymbs = new SymbolRef[numSymbs];

                for (int i = 0; i < numSymbs; i++)
                {
                    allSymbs[i] = SymbolRef.ReadBinary(br);
                }

                for (int i = 0; i < numSymbs; i++)
                {
                    allSymbs[i].ReadBinaryEnv(br, allSymbs);
                }

                for (int i = 0; i <= len; i++)
                {
                    Instruction I = Instruction.ReadBinary(sourceRef, br, baseAddress, envTable, allSymbs);
                    m_RootChunk.Code.Add(I);
                }

                return(baseAddress);
            }
        }