Пример #1
0
        /// <summary>
        /// 序列化对象
        /// </summary>
        /// <param name="encoder">对象编码器.</param>
        public override void serialization(LuaObjectEncoder encoder)
        {
            base.serialization(encoder);

            if (_context != null)
            {
                encoder.writeInt32(_context.objectId);
            }
            else
            {
                encoder.writeInt32(0);
            }

            encoder.writeString(_tableId);
            encoder.writeInt16((Int16)type);

            switch (type)
            {
            case LuaValueType.Number:
            {
                encoder.writeDouble(toNumber());
                break;
            }

            case LuaValueType.Integer:
            {
                encoder.writeInt32(toInteger());
                break;
            }

            case LuaValueType.String:
            {
                encoder.writeString(toString());
                break;
            }

            case LuaValueType.Data:
            {
                encoder.writeBytes(toData());
                break;
            }

            case LuaValueType.Array:
            {
                List <LuaValue> list = toArray();

                encoder.writeInt32(list.Count);
                foreach (LuaValue value in list)
                {
                    encoder.writeObject(value);
                }
                break;
            }

            case LuaValueType.Map:
            {
                Dictionary <string, LuaValue> map = toMap();
                encoder.writeInt32(map.Count);

                foreach (KeyValuePair <string, LuaValue> kv in map)
                {
                    encoder.writeString(kv.Key);
                    encoder.writeObject(kv.Value);
                }
                break;
            }

            case LuaValueType.Object:
            {
                encoder.writeObject(_value);
                break;
            }

            case LuaValueType.Boolean:
            {
                encoder.writeByte(Convert.ToByte(toBoolean()));
                break;
            }

            case LuaValueType.Function:
            {
                encoder.writeObject(toFunction());
                break;
            }

            case LuaValueType.Ptr:
            {
                encoder.writeObject(toPointer());
                break;
            }

            case LuaValueType.Tuple:
            {
                encoder.writeObject(toTuple());
                break;
            }

            default:
                break;
            }
        }
Пример #2
0
//		/// <summary>
//		/// 获取原生类名称
//		/// </summary>
//		/// <value>类名称.</value>
//		public virtual string nativeClassName
//		{
//			get
//			{
//				return "Object";
//			}
//		}

        /// <summary>
        /// 序列化对象
        /// </summary>
        /// <param name="encoder">对象编码器.</param>
        public virtual void serialization(LuaObjectEncoder encoder)
        {
            encoder.writeByte((byte)'L');
            encoder.writeString(this.GetType().Name);
            encoder.writeByte((byte)';');
        }