Skip to content

[Feat]: arrays in nbt! macro should support signed bytes #43

@Fisch37

Description

@Fisch37

My suggestion

The syntax of nbt! is (as stated in the docs) based on the syntax of SNBT. This carries over to the array types, but -- unlike Int and Long arrays -- a bytes array targets unsigned values, instead of their signed counterparts.

While this has merit and arises from the implementation of the macro itself, I feel it is an unnecessary divergence from the expected standard. Therefore I suggest, that either the current byte array syntax is changed to support i8 values (and the old behaviour added as a separate macro branch) or the opposite approach is taken and a new branch is added that supports signed values.

I imagine the latter option to look something like this:

// Old (unsigned, no signed option exists)
nbt!("", {"hello!": [B; 45, 219, 111, 166]})
// New (signed)
nbt!("", {"hello!": [B; 45, -37, 111, -90]})
// New (unsigned)
nbt!("", {"hello!": [UB; 45, 219, 111, 166]})

(the former would equivalently use SB)

The primary use for this is better readability in Unit Tests

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions