public static object BytesToLua(int type, byte[] buf, int offset, int len)
        {
            if (len <= 0)
            {
                return(null);
            }

            switch (type)
            {
            case ParticleType.STRING:
                return(ByteUtil.Utf8ToString(buf, offset, len));

            case ParticleType.INTEGER:
                return(ByteUtil.BytesToNumber(buf, offset, len));

            case ParticleType.DOUBLE:
                return(ByteUtil.BytesToDouble(buf, offset));

            case ParticleType.BLOB:
                byte[] dest = new byte[len];
                Array.Copy(buf, offset, dest, 0, len);
                return(new LuaBytes(dest));

            case ParticleType.CSHARP_BLOB:
                return(ByteUtil.BytesToObject(buf, offset, len));

            case ParticleType.LIST:
            {
                Unpacker unpacker = new Unpacker(buf, offset, len, true);
                return(unpacker.UnpackList());
            }

            case ParticleType.MAP:
            {
                Unpacker unpacker = new Unpacker(buf, offset, len, true);
                return(unpacker.UnpackMap());
            }

            case ParticleType.GEOJSON:
            {
                // skip the flags
                int ncells = ByteUtil.BytesToShort(buf, offset + 1);
                int hdrsz  = 1 + 2 + (ncells * 8);
                return(new LuaGeoJSON(ByteUtil.Utf8ToString(buf, offset + hdrsz, len - hdrsz)));
            }

            default:
                return(null);
            }
        }
        public static object BytesToLua(int type, byte[] buf, int offset, int len)
        {
            if (len <= 0)
            {
                return(null);
            }

            switch (type)
            {
            case ParticleType.STRING:
                return(ByteUtil.Utf8ToString(buf, offset, len));

            case ParticleType.INTEGER:
                return(ByteUtil.BytesToNumber(buf, offset, len));

            case ParticleType.DOUBLE:
                return(ByteUtil.BytesToDouble(buf, offset));

            case ParticleType.BLOB:
                byte[] dest = new byte[len];
                Array.Copy(buf, offset, dest, 0, len);
                return(new LuaBytes(dest));

            case ParticleType.CSHARP_BLOB:
                return(ByteUtil.BytesToObject(buf, offset, len));

            case ParticleType.LIST:
            {
                Unpacker unpacker = new Unpacker(buf, offset, len, true);
                return(unpacker.UnpackList());
            }

            case ParticleType.MAP:
            {
                Unpacker unpacker = new Unpacker(buf, offset, len, true);
                return(unpacker.UnpackMap());
            }

            default:
                return(null);
            }
        }