-
Notifications
You must be signed in to change notification settings - Fork 157
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
关于在写onebot12协议java-sdk的一些想法 #248
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discussed in https://github.com/orgs/botuniverse/discussions/247
Originally posted by eiriksgata October 25, 2023
讨论1: 关于事件的数据拓展字段。
我们都知道在12标准协议中,必填字段有 id、time、type、detail_type、sub_type ,其余如果想要进行拓展,那么其拓展的字段是位于 当前 Event 所在的并级下,我认为这是一种不合理的设计。
如文档中给出的例子:
根据例子来看,其事件是往机器人平台发送一条私聊消息,其中包含 message、 user_id 等相关字段,这些字段都是位于 Event 所在的当前层级,对于常规的弱语言(形如脚本语言)来说,json增加字段确实没什么问题,但是对于强语言类型来说,我们必然是要定义一个Class 来 实现实体类,或者是 ts 定义一个 type | interface 来增强语言类型。
想message、user_id 这种拓展字段 ,本身应该是填写在 Event 所在的 某个字段下级,例如下面例子:
上述例子中 将 message 、user_id等数据 ,放入 content 中, 随着你 type 不同而 对 content 中的字段而不同。
因此我们在写 实体类时,可以采用 泛型 的形式对 json 进行轻松的反序列化,同时也增强了语言的可读性。
The text was updated successfully, but these errors were encountered: