Skip to content

Implicit conversion from integral numbers to byte array #2702

@scordio

Description

@scordio

I'd like to propose the addition of implicit conversion from integral numbers (byte, short, int, long) to byte array. The concrete use case is code dealing with bitwise operations, mostly related to cryptography.

My wish is to write something like this:

  @ParameterizedTest
  @ValueSource(ints = {Integer.MIN_VALUE, 0, 0xFF, 0xFFFF, 0xFFFFFF, Integer.MAX_VALUE})
  void test(byte[] byteArray) {
    assertThat(byteArray).hasSize(4);
  }

where I can leverage binary and hexadecimal literals which are automatically converted to a byte array using a ByteBuffer with Big Endian order.

I put together a small poc with a custom argument converter. If the proposal is accepted, I'm happy to raise a PR about it.

Deliverables

  • A new implicit conversion from byte / short / int / long to byte[]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy