コード例 #1
0
ファイル: TestBase.cs プロジェクト: ABCo-Src/ABSave
        public void ResetState()
        {
            // Reset the serializer and deserializer
            Serializer.Reset();
            Deserializer.Reset();

            ResetPosition();
        }
コード例 #2
0
ファイル: TestBase.cs プロジェクト: ABCo-Src/ABSave
        public byte[] GetByteArr(object[] itms, params short[] data)
        {
            List <byte>      bytes      = new List <byte>(64);
            ABSaveSerializer serializer = null;
            int currentItmsPos          = 0;

            for (int i = 0; i < data.Length; i++)
            {
                if (data[i] <= 255)
                {
                    bytes.Add((byte)data[i]);
                }
                else
                {
                    switch ((GenType)data[i])
                    {
                    case GenType.Numerical:
                        bytes.AddRange(BitConverter.GetBytes((dynamic)itms[currentItmsPos++]));
                        break;

                    case GenType.String:
                        bytes.AddRange(Encoding.UTF8.GetBytes((string)itms[currentItmsPos++]));
                        break;

                    case GenType.ByteArr:
                        bytes.AddRange((byte[])itms[currentItmsPos++]);
                        break;

                    case GenType.Action:

                        SetupSerializer();
                        ((Action <ABSaveSerializer>)itms[currentItmsPos++])(serializer);
                        bytes.AddRange(((MemoryStream)serializer.Output).ToArray());

                        break;

                    case GenType.MapItem:

                        SetupSerializer();

                        var genMap = (GenMap)itms[currentItmsPos++];
                        serializer.SerializeExactNonNullItem(genMap.Obj, genMap.Item);
                        bytes.AddRange(((MemoryStream)serializer.Output).ToArray());

                        break;

                    case GenType.Size:

                        SetupSerializer();
                        serializer.WriteCompressedLong((ulong)itms[currentItmsPos++]);

                        bytes.AddRange(((MemoryStream)serializer.Output).ToArray());
                        break;
                    }
                }
            }

            return(bytes.ToArray());

            void SetupSerializer()
            {
                if (serializer == null)
                {
                    serializer = CurrentMap.GetSerializer(new MemoryStream());
                }
                else
                {
                    serializer.Reset();
                    serializer.Output.Position = 0;
                }
            }
        }