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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please support List<IPacket>( Map<IPacket,IPacket>,...) in zfoo protocol #59

Open
magicghostVu opened this issue Jun 6, 2023 · 9 comments

Comments

@magicghostVu
Copy link

No description provided.

@magicghostVu magicghostVu changed the title Please support List<IPacket>( Map<IPacket,IPacket>,...) Please support List<IPacket>( Map<IPacket,IPacket>,...) in zfoo protocol Jun 6, 2023
@tiennm99
Copy link
Contributor

I think zfoo protocol already have it. And I've used it for months. This is a simple example using existed IPacket children in tests - ObjectA, ObjectB, ObjectC:

// ObjectD.java - this is the file contains List<IPacket> and Map<IPacket, IPacket>
@Protocol(id = 122)
public class ObjectD implements IPacket {
  public List<ObjectA> list = List.of(new ObjectA(), new ObjectA());
  public Map<ObjectB, ObjectC> map = Map.of(new ObjectB(), new ObjectC());
}
// GenerateGdTest.java - this is the test file to generate protocols
public class GenerateGdTest extends TestCase {

  @Test
  public void testGenerateGd() {
    var op = GenerateOperation.NO_OPERATION;
    op.getGenerateLanguages().add(CodeLanguage.GdScript);
    op.setProtocolPath("out");
    ProtocolManager.initProtocol(Set.of(ObjectA.class, ObjectB.class, ObjectC.class, ObjectD.class), op);
  }
}

And run it using junit, it works fine.
Maybe you forgot to register the IPacket children in List/Map in the GenerateOperation.
If I wrong, please correct me. Thanks.

@magicghostVu
Copy link
Author

magicghostVu commented Jul 16, 2023

It is not my problem, I want to use List<IPacket> in ObjectD class, I must declare List<IPacket> because zfoo doesn't support abstract class

@tiennm99
Copy link
Contributor

Gocha! Sorry for my misunderstanding. Your topic is very interesting. I'll try to implement it later.

@magicghostVu
Copy link
Author

if you use kotlin as language for server-side, please take a look at this MSerialization, it use ksp for code generation and of course it support JS and Gdscipt

@godotg
Copy link
Contributor

godotg commented Jul 17, 2023

Custom generic class such as List<IPacket> are not supported in all languages锛宖or example golang and cpp.

@tiennm99
Copy link
Contributor

I think he wanted to say list of abstract class.
For example: List<AbstractPacket> with AbstractPacket is an abstract class and implements IPacket. I think it's possible, isn't it?

@godotg
Copy link
Contributor

godotg commented Jul 17, 2023

It is easy to support List<AbstractPacket> or List<IPacket> in java,C#,Js, but very difficult in other languages such as golang and cpp

@tiennm99
Copy link
Contributor

I think if we implement this feature, it will be interesting. However, as @godotg said, it's very difficult to implement in golang and cpp. I think I can implement it in other languages as java, c#, js and godot. Can we support it for these languages, if GenerateOperation.generateLanguages contains other languages, we will throw an exception?

@godotg
Copy link
Contributor

godotg commented Aug 14, 2023

Custom generic classes are prone to performance and parsing problems in many frameworks, and are not supported in all languages.

According to the current protocol format,this feature can not be supported.

Keep it simple and stupid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants