Created
October 9, 2015 10:00
-
-
Save danielshaya/3022dcb292315dadcfff 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 WireDeserialiseIntoObjectDemo { | |
public static void main(String[] args) { | |
new WireDeserialiseIntoObjectDemo().test(); | |
} | |
public void test(){ | |
Person person = new Person(); | |
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("net.openhft.engine.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 into existing object:"); | |
//to deserialise that data into an existing object | |
tw.readDocument(null, w -> w.read(() -> "data") | |
.marshallable( | |
m -> m.read(() -> "name").text(person, Person::setName) | |
.read(() -> "age").int8(person, Person::setAge))); | |
System.out.println(person); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment