Add example, set release version 1.0.0

This commit is contained in:
Andrew Lalis 2023-09-22 09:56:47 -04:00
parent c32524387a
commit d88ce58e6e
2 changed files with 32 additions and 3 deletions

View File

@ -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 serialize and deserialize records and their contents for use in network or
filesystem IO. filesystem IO.
## Example ## 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();
}
}
}
```

View File

@ -6,7 +6,7 @@
<groupId>com.andrewlalis</groupId> <groupId>com.andrewlalis</groupId>
<artifactId>record-net</artifactId> <artifactId>record-net</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0</version>
<name>Record-Net</name> <name>Record-Net</name>
<description>A simple library for reading and writing records deterministically and efficiently.</description> <description>A simple library for reading and writing records deterministically and efficiently.</description>
<url>https://github.com/andrewlalis/record-net</url> <url>https://github.com/andrewlalis/record-net</url>