Example #1
0
        protected override void SerializeValue <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s)
        {
            bool reading = s.IsReading;

            model.MegaloVariant.SerializeStringTableIndex(s, "stringIndex", ref mStringIndex);

            if (!s.StreamAttributeOpt("tokenCount", ref mTokenCount, Predicates.IsNotZero) &&
                reading)
            {
                TokenCount = 0;
            }

            if (reading)
            {
                ValidateTokenCount();

                int max_tokens = MaxTokens;
                if (max_tokens >= 1)
                {
                    Token0.Nullify();
                }
                if (max_tokens >= 2)
                {
                    Token1.Nullify();
                }
                if (max_tokens >= 3)
                {
                    Token2.Nullify();
                }
            }

            if (TokenCount >= 1)
            {
                using (s.EnterCursorBookmark("Token0")) Token0.Serialize(model, s);
            }
            if (TokenCount >= 2)
            {
                using (s.EnterCursorBookmark("Token1")) Token1.Serialize(model, s);
            }
            if (TokenCount >= 3)
            {
                using (s.EnterCursorBookmark("Token2")) Token2.Serialize(model, s);
            }
        }
Example #2
0
        public override void Serialize(MegaloScriptModel model, IO.BitStream s)
        {
            model.MegaloVariant.StreamStringTableIndexPointer(s, ref mStringIndex);
            s.Stream(ref mTokenCount, ValueType.BitLength);

            if (s.IsReading)
            {
                ValidateTokenCount();

                int max_tokens = MaxTokens;
                if (max_tokens >= 1)
                {
                    Token0.Nullify();
                }
                if (max_tokens >= 2)
                {
                    Token1.Nullify();
                }
                if (max_tokens >= 3)
                {
                    Token2.Nullify();
                }
            }

            if (TokenCount >= 1)
            {
                Token0.Serialize(model, s);
            }
            if (TokenCount >= 2)
            {
                Token1.Serialize(model, s);
            }
            if (TokenCount >= 3)
            {
                Token2.Serialize(model, s);
            }
        }