Search in sources :

Example 1 with Note

use of org.infinispan.protostream.domain.Note in project protostream by infinispan.

the class AnnotationsPerformanceTest method testReadWrite.

@Test
public void testReadWrite() throws Exception {
    SerializationContext ctx1 = createCtxWithHandWrittenMarshaller();
    SerializationContext ctx2 = createCtxWithGeneratedMarshaller();
    User user = new User();
    user.setId(1);
    user.setName("John");
    user.setSurname("Batman");
    user.setSalutation("Sir");
    user.setGender(User.Gender.MALE);
    user.setAccountIds(new HashSet<>(Arrays.asList(1, 3)));
    List<Address> addresses = new ArrayList<>();
    addresses.add(new Address("Old Street", "XYZ42", -12));
    addresses.add(new Address("Bond Street", "QQ42", 312));
    user.setAddresses(addresses);
    Note note = new Note();
    note.setText("Lorem Ipsum");
    note.setCreationDate(new Date());
    note.setDigest(new byte[10]);
    note.setBlurb(new byte[3]);
    note.setAuthor(user);
    Note note2 = new Note();
    note2.setText("Lorem Ipsum");
    note2.setAuthor(user);
    note2.setBlurb(new byte[3]);
    Note note3 = new Note();
    note3.setText("Lorem Ipsum");
    note3.setAuthor(user);
    note3.setBlurb(new byte[3]);
    note.note = note2;
    note.notes = Collections.singletonList(note3);
    byte[] bytes = writeWithProtoStream(ctx1, note);
    writeWithProtoStream(ctx2, note);
    long d1 = readWithProtoStream(ctx1, bytes);
    log.infof("ProtoStream read duration           = %d ns", d1);
    long d2 = readWithProtoStream(ctx2, bytes);
    log.infof("ProtoStream read duration           = %d ns", d2);
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) User(org.infinispan.protostream.domain.User) Address(org.infinispan.protostream.domain.Address) Note(org.infinispan.protostream.domain.Note) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Example 2 with Note

use of org.infinispan.protostream.domain.Note in project protostream by infinispan.

the class NoteMarshaller method readFrom.

@Override
public Note readFrom(ProtoStreamReader reader) throws IOException {
    String text = reader.readString("text");
    User author = reader.readObject("author", User.class);
    Note note2 = reader.readObject("note", Note.class);
    List<Note> notes = reader.readCollection("notes", new ArrayList<>(), Note.class);
    Date creationDate = reader.readDate("creationDate");
    byte[] digest = reader.readBytes("digest");
    byte[] blurb = reader.readBytes("blurb");
    Note note = new Note();
    note.setText(text);
    note.setAuthor(author);
    note.note = note2;
    note.notes = notes;
    note.setCreationDate(creationDate);
    note.setDigest(digest);
    note.setBlurb(blurb);
    return note;
}
Also used : User(org.infinispan.protostream.domain.User) Note(org.infinispan.protostream.domain.Note) Date(java.util.Date)

Aggregations

Date (java.util.Date)2 Note (org.infinispan.protostream.domain.Note)2 User (org.infinispan.protostream.domain.User)2 ArrayList (java.util.ArrayList)1 SerializationContext (org.infinispan.protostream.SerializationContext)1 Address (org.infinispan.protostream.domain.Address)1 Test (org.junit.Test)1