Created
October 9, 2015 09:41
-
-
Save danielshaya/4528109b81567d24ef06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chronicle.demo; | |
import net.openhft.chronicle.bytes.Bytes; | |
import net.openhft.chronicle.wire.BinaryWire; | |
import net.openhft.chronicle.wire.TextWire; | |
/** | |
* Created by daniel on 09/10/2015. | |
*/ | |
public class WireDocumentTypeDemo { | |
public static void main(String[] args) { | |
new WireDocumentTypeDemo().test(); | |
} | |
public void test(){ | |
Bytes bytes = Bytes.elasticByteBuffer(); | |
TextWire tw = new TextWire(bytes); | |
//serialise some data over wire wrapping it in a document | |
System.out.println("---------TextWire Demo--------------"); | |
tw.writeDocument(false, w -> w.write(() -> "data").typePrefix("chronicle.demo.Person").marshallable( | |
v -> v.write(() -> "name").text("dan") | |
.write(() -> "age").int8(44))); | |
System.out.println("Data serialised with TextWire:\n" + bytes.toString()); | |
System.out.println("Data deserialised:"); | |
//to deserialise that data | |
tw.readDocument(null, w -> { | |
Object o = w.read(() -> "data").typedMarshallable(); | |
System.out.println(o.toString()); | |
}); | |
//Do the same thing with BinaryWire | |
BinaryWire bw = new BinaryWire(bytes); | |
//serialise some data over wire wrapping it in a document | |
System.out.println("---------BinaryWire Demo--------------"); | |
bw.writeDocument(false, w -> w.write(() -> "data").typePrefix("chronicle.demo.Person").marshallable( | |
v -> v.write(() -> "name").text("dan") | |
.write(() -> "age").int8(44))); | |
System.out.println("Data serialised with BinaryWire:\n" + bytes.toHexString()); | |
System.out.println("Data deserialised:"); | |
//to deserialise that data | |
bw.readDocument(null, w -> { | |
Object o = w.read(() -> "data").typedMarshallable(); | |
System.out.println(o.toString()); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment