Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuo 反序列化模块 #426

Open
6 of 8 tasks
cosven opened this issue Nov 29, 2020 · 0 comments
Open
6 of 8 tasks

fuo 反序列化模块 #426

cosven opened this issue Nov 29, 2020 · 0 comments
Labels
FEP feeluown enhancement proposal

Comments

@cosven
Copy link
Member

cosven commented Nov 29, 2020

  • 作者:@cosven
  • 创建时间:2020-11-29
  • 最近更新:2020-11-29 22:00
  • 最新状态:
    • 2020-12-05 10:00 添加“难点及其解决方案”章节

动机

本地歌曲插件(下面简称 local)想避免每次启动都需要重复做以下几件事情

  1. 扫描所有音乐文件
  2. 解析文件 tag 信息变成 model

local 目前的做法中包含重要的一步是:

  1. 将 model 转成 dict,存在一个 json 文件中

model -> dict,dict -> model 的过程其实就是 序列化/反序列化 的过程。

简介与背景

fuocore.serializer 实现了 model 的序列化,而目前实际上缺一个反序列化的模块。

关于 fuocore.models.uri 的 resolve 和 reverse

目前,这两个函数自成体系,但实际上作用和 serializer 功能有些重复。期望能把其逻辑统一到 serializer 模块中去

  • resolve 函数的作用类似反序列化:将一个文本反序列化成一个 model
  • reverse 函数的作用则类似序列化:将一个 model 序列化成一行文本

难点及其解决方案

  • 序列化的数据中需要有字段标明对应的 Model Type
    • plain: 依赖 uri 的 provider_identifier + model_type 来判断
    • json: 目前有 provider_indentifier,但没有 model_type
  • provider 加载比较慢,甚至没加载怎么处理?
    • 拼凑一个 not existence 的 model。等待 local 插件加载的时候,会发送 provider added/removed 信号,到时可以重新处理一次 model。
  • 一个场景:序列化数据包含额外的字段怎么处理?以 LocalSongModel 为例,有 disc 等字段
    • 抛弃 假设允许多余字段 - 根据下面分析,不好实现。why?这么多的 object 序列化反序列化,工作量当然大
      • 多余字段不能是 obj/dict 等复杂对象
        • model 的 fields 里面肯定会包含类似 dict 等对象,所以不能把 model 的 fields 全部序列化掉
          • 需要有一个地方定义序列化/反序列化的字段
            • 还是统一字段列表比较好,否则 provider 开发者工作量很大
      • 在没找到真正 model 的时候,多余字段怎样处理?
    • 不允许多个字段,那多余的字段怎样处理?
      • 多余字段可能本身就是伪需求?因为都应该让 fuo 先支持,插件才有支持的意义。
@cosven cosven added the FEP feeluown enhancement proposal label Nov 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FEP feeluown enhancement proposal
Projects
None yet
Development

No branches or pull requests

1 participant