Skip to content

Commit

Permalink
WIP #509
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Kaznacheev committed Feb 21, 2023
1 parent d414f11 commit a462dd5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/main/java/net/openhft/chronicle/wire/Marshallable.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package net.openhft.chronicle.wire;

import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.annotation.DontChain;
import net.openhft.chronicle.core.io.IORuntimeException;
import net.openhft.chronicle.core.io.Resettable;
Expand All @@ -34,12 +35,16 @@

import static net.openhft.chronicle.wire.WireMarshaller.WIRE_MARSHALLER_CL;
import static net.openhft.chronicle.wire.WireType.TEXT;
import static net.openhft.chronicle.wire.WireType.YAML;

/**
* The implementation of this interface is both readable and write-able as marshallable data.
*/
@DontChain
public interface Marshallable extends WriteMarshallable, ReadMarshallable, Resettable {
WireType FROM_STRING_WIRE = Jvm.getBoolean("wire.testAsYaml")
? YAML : TEXT;

static boolean $equals(@NotNull WriteMarshallable $this, Object o) {
return o instanceof WriteMarshallable &&
($this == o || Wires.isEquals($this, o));
Expand All @@ -50,17 +55,17 @@ public interface Marshallable extends WriteMarshallable, ReadMarshallable, Reset
}

static String $toString(WriteMarshallable $this) {
return TEXT.asString($this);
return FROM_STRING_WIRE.asString($this);
}

@Nullable
static <T> T fromString(@NotNull CharSequence cs) {
return TEXT.fromString(cs);
return FROM_STRING_WIRE.fromString(cs);
}

@Nullable
static <T> T fromString(@NotNull Class<T> tClass, @NotNull CharSequence cs) {
return TEXT.fromString(tClass, cs);
return FROM_STRING_WIRE.fromString(tClass, cs);
}

/**
Expand All @@ -71,12 +76,12 @@ static <T> T fromString(@NotNull Class<T> tClass, @NotNull CharSequence cs) {
*/
@NotNull
static <T> T fromFile(String filename) throws IOException {
return TEXT.fromFile(filename);
return FROM_STRING_WIRE.fromFile(filename);
}

static <T> T fromString(@NotNull InputStream is) {
Scanner s = new Scanner(is).useDelimiter("\\A");
return TEXT.fromString(s.hasNext() ? s.next() : "");
return FROM_STRING_WIRE.fromString(s.hasNext() ? s.next() : "");
}

/**
Expand All @@ -88,17 +93,17 @@ static <T> T fromString(@NotNull InputStream is) {
*/
@Nullable
static <T> T fromFile(@NotNull Class<T> expectedType, String filename) throws IOException {
return TEXT.fromFile(expectedType, filename);
return FROM_STRING_WIRE.fromFile(expectedType, filename);
}

@NotNull
static <T> Stream<T> streamFromFile(String filename) throws IOException {
return TEXT.streamFromFile(filename);
return FROM_STRING_WIRE.streamFromFile(filename);
}

@Nullable
static <T> Stream<T> streamFromFile(@NotNull Class<T> expectedType, String filename) throws IOException {
return TEXT.streamFromFile(expectedType, filename);
return FROM_STRING_WIRE.streamFromFile(expectedType, filename);
}

@Nullable
Expand Down

0 comments on commit a462dd5

Please sign in to comment.