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

Back Nbt*Arrays with Lists, and encode arrays as NbtList by default, and require @NbtArray #34

Open
BenWoodworth opened this issue Apr 16, 2023 · 3 comments
Milestone

Comments

@BenWoodworth
Copy link
Owner

  • Encourages using List instead of Array types (generally a good practice in Kotlin)
  • Allows Arrays to be serialized as NbtLists more easily
    • currently required a custom serializer
    • would otherwise require more machinery to support
  • Lets Nbt*Array types be constructed from lists
    • currently, wrapping lists in NbtArrays was not possible and required copying to new arrays
    • still supports arrays, just with e.g. NbtIntArray(intArray.asList())
@BenWoodworth BenWoodworth added this to the v0.12 milestone Apr 16, 2023
BenWoodworth added a commit that referenced this issue Apr 23, 2023
Now `Nbt*Array`/`NbtList`/`NbtCompound` have `collection` properties, and only have methods useful for introspection/deserialization. (Resolves #28)

The `Nbt*Array` types are now backed by `List`s instead of `Array`s. (See #34)
@BenWoodworth
Copy link
Owner Author

Additional problem with the way it's done in v0.11, and deciding if it should be an NBT Array by detecting if the descriptor is a builtin array serializer's descriptor:

When delegating the serialization process to a Byte/Int/LongArray's serializer the standard way, the outer serializer has to rename the array's serializer (since the serial name needs to be unique). Because of this, the descriptor is no longer equal, meaning the serializer's descriptor alone can't be used to introspect the NBT's schema. Only once the serialization logic is executed will the encoder/decoder see the array serializer's descriptor and be able to determine that the SerialKind.LIST value should be an NBT array.

@BenWoodworth
Copy link
Owner Author

There should be a way for a descriptor to specify that it definitely is or is not an NBT array.

For example, this should not work:

@Serializable
class MyClass(
    @NbtArray
    val collection: NbtList<*>
)

Having an optional way to specify could solve this:

annotation class NbtArray(val isNbtArray: Boolean = true)

NbtList could have @NbtArray(false) in its descriptor to disallow this.

And similarly, the NBT arrays could have @NbtArray, preventing a NBT array property from being marked with @NbtArray(false)

@BenWoodworth
Copy link
Owner Author

It could also be useful to have a configuration option to encode LIST kinds of BYTE/INT/LONG as arrays unless marked with @NbtArray(false).

Inspired by kotlinx.serialization's CborConfiguration.alwaysUseByteString in v1.7.2, applying @ByteString by default

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

1 participant