From d88ce58e6ee69293bf5d381d53cd2a5f328a23a1 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Fri, 22 Sep 2023 09:56:47 -0400 Subject: [PATCH] Add example, set release version 1.0.0 --- README.md | 33 +++++++++++++++++++++++++++++++-- pom.xml | 2 +- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 73868ef..e526b16 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,35 @@ Simple, performant message library for Java, using records. It allows you to serialize and deserialize records and their contents for use in network or filesystem IO. - - ## Example + +```java +import com.andrewlalis.record_net.RecordMappedSerializer; +import java.io.*; + +class Main { + public static void main(String[] args) throws IOException { + record MyData(int a, float b, String s) {} + record FileData(String name, byte[] data) {} + + // Register the record types you want to use. + RecordMappedSerializer serializer = new RecordMappedSerializer(); + serializer.registerType(MyData.class); + serializer.registerType(FileData.class); + + // Write records. + ByteArrayOutputStream out = new ByteArrayOutputStream(); + serializer.writeMessage(new MyData(42, 3.1415f, "Hello world!"), out); + serializer.writeMessage(new FileData("test.txt", new byte[]{1, 2, 3, 4}), out); + byte[] serialized = out.toByteArray(); + + // Read records. + Object obj = serializer.readMessage(new ByteArrayInputStream(serialized)); + switch (obj) { + case MyData d -> System.out.println("Got MyData: " + d); + case FileData d -> System.out.println("Got file data: " + d); + default -> throw new RuntimeException(); + } + } +} +``` diff --git a/pom.xml b/pom.xml index fe646b9..78ab36b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.andrewlalis record-net - 1.0.0-SNAPSHOT + 1.0.0 Record-Net A simple library for reading and writing records deterministically and efficiently. https://github.com/andrewlalis/record-net