Esempio n. 1
0
        public static bool MsgPackLuaTable(ref LuaTable luatable, ref Packer pker)
        {

            if (luatable == null)
            {
                pker = null;
                return false;
            }
            else
            {
                pker.PackMapHeader(luatable.Count);
            }
            foreach (var item in luatable)
            {
                //object key = item.Key;
                bool kFlag = luatable.IsKeyString(item.Key);
                if (kFlag)
                {
                    pker.PackRawHeader(item.Key.Length);
                    pker.PackRawBody(System.Text.Encoding.UTF8.GetBytes(item.Key));
                }
                else
                {
                    pker.Pack(double.Parse(item.Key.ToString()));
                }

                var valueType = item.Value.GetType();
                if (valueType == typeof(String))
                {

                    pker.PackRawHeader(item.Value.ToString().Length);
                    pker.PackRawBody(System.Text.Encoding.UTF8.GetBytes(item.Value.ToString()));
                }
                else if (valueType == typeof(LuaTable))
                {
                    LuaTable luaTbl = item.Value as LuaTable;
                    MsgPackLuaTable(ref luaTbl, ref pker);
                }
                else if (valueType == typeof(bool))
                {
                    pker.Pack(bool.Parse(item.Value.ToString()));
                }
                else
                {
                    pker.Pack(double.Parse(item.Value.ToString()));
                }
            }
            return true;
        }