-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
NetworkCodecs #180
NetworkCodecs #180
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't expose impl classes from an API class.
Yeah I noticed that. I'll get on it. |
Random thought, does this allow to transform a normal Codec into a network codec? |
Depends on what 'transform' refers to. Currently you can create a NetworkCodec from a normal Codec. But that just writes NBT. There might be ways to properly create a NetworkCodec though. However, I feel as if it's gonna be a huge pain to do so. |
Wouldn't it be possible to create a PacketByteBuf-backed Ops class? like JsonOps or NbtOps? |
That's something I have been thinking about. It just doesn't work. |
I originally started with that as my idea. However, from what I have gathered, it's just not possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for getting the split done; that's all i really had to say about this PR at the moment
private final NetworkCodec<A> entryCodec; | ||
private final IntFunction<? extends A[]> arrayFactory; | ||
|
||
public ArrayNetworkCodec(NetworkCodec<A> entryCodec, IntFunction<? extends A[]> arrayFactory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of construction methods left public through all these classes.
Are users meant to be able to construct these codecs directly, or always go through NetworkCodec
, NetworkCodecBuilder
, etc?
As discussed on Discord some time ago, I'd like to point to CBOR as prior art on binary representations of JSON-like structures, maps, lists, nulls and all. Full spec found in RFC 8949. I see two options for implementing this. First, the easy route: piggyback off of JsonOps, grab the resulting JsonElement, write it into CBOR by following the spec. No Ops implementation needed. However, JSON has worse typing than CBOR, not being able to distinguish between floating-point and integer numbers, and not allowing non-string keys in maps, meaning the format would lose efficiency and expressive power: Second option is a full-fledged DynamicOps implementation, and here I'd like to give some pointers on implementing:
Encoding maps and lists is a pretty crucial operation, so it should be implemented either way, and this provides a well-described and known format to do so. For my personal use-cases, I have a packet which sends a |
This PR adds:
Split from #179 because it had 2 features, one of which needed further discussion.