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

[YamlWire] Reading int arrays does not work #272

Closed
jonatino opened this issue Apr 13, 2021 · 1 comment
Closed

[YamlWire] Reading int arrays does not work #272

jonatino opened this issue Apr 13, 2021 · 1 comment
Assignees
Milestone

Comments

@jonatino
Copy link

When attempting to read an int array (and possibly all other types) from a yaml wire, it throws the following error/warning and will fill the array with 0's.

Unable to read *number* as a long.

Test application:

import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.wire.YamlWire;

import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        var buffer = Bytes.allocateElasticDirect(10 * 4);
        int[] one = {1, 2, 3, 4, 5};
        int[] two = {101, 102, 103, 104, 105};

        // Create wire for saving two int arrays
        var wire = new YamlWire(buffer);
        wire.write("one").array(one, 5);
        wire.write("two").array(two, 5);
        System.out.println("Write wire:");
        System.out.println(wire);
        System.out.println();

        buffer.readPosition(0);

        // Copy buffer into a new wire for reading (mocks saving/loading)
        var copyWire = new YamlWire(buffer);
        System.out.println("Read wire:");
        System.out.println(copyWire);
        System.out.println();

        int[] readBuffer = new int[5];
        int amtRead = copyWire.read("one").array(readBuffer);
        System.out.println("Read: " + amtRead + ", " + Arrays.toString(readBuffer));
    }

}

Output from above:

Write wire:
one: [ 1, 2, 3, 4, 5 ],
two: [ 101, 102, 103, 104, 105 ]

Read wire:
one: [ 1, 2, 3, 4, 5 ],
two: [ 101, 102, 103, 104, 105 ]

Read: 5, [0, 0, 0, 0, 0]

As you can see, it reads the correct amount of elements (5 in this case), but does not fill the array with the appropriate values due to the following code in YamlWire -> TextValueIn public long int64()

            if (yt.current() != YamlToken.TEXT) {
                Jvm.warn().on(getClass(), "Unable to read " + valueIn.object() + " as a long.");
                return 0;
            }
jonatino added a commit to jonatino/Chronicle-Wire that referenced this issue Apr 14, 2021
@jonatino
Copy link
Author

The fix for this specific use case is consuming SEQUENCE_START with padding, but that breaks the usecase when saving arrays with .object instead of .array.

See: jonatino@672b529

@peter-lawrey peter-lawrey added this to the x.22 milestone Jun 16, 2021
peter-lawrey added a commit that referenced this issue Aug 2, 2023
* In creating tests to show #272 had been fixed, other issues were found and fixed.

* Improve test coverage for decoding different values
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

2 participants