Add Byte Mapper
This commit is contained in:
5
byte-mapper/.metadata.json
Normal file
5
byte-mapper/.metadata.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"displayName": "Byte Mapper",
|
||||
"pubDate": "17.02.2026",
|
||||
"hide": true
|
||||
}
|
||||
48
byte-mapper/index.md
Normal file
48
byte-mapper/index.md
Normal file
@@ -0,0 +1,48 @@
|
||||
# byte-mapper
|
||||
|
||||
Удобный сериализатор и десериализатор Java объектов в виде компактного массива байт. Берет лучшее из нескольких технологий:
|
||||
- Компактность, схожая с ProtoBuf;
|
||||
- Синтаксическое удобство, как у JPA;
|
||||
- Простота использования, как у Jackson ObjectMapper;
|
||||
|
||||
[GitHub](https://github.com/FalmerF/byte-mapper)
|
||||
|
||||
## Пример
|
||||
|
||||
```java title="User.class"
|
||||
@ByteEntity(1)
|
||||
public class User {
|
||||
|
||||
@ByteProperty(1)
|
||||
private int id;
|
||||
|
||||
@ByteProperty(2)
|
||||
private String firstName;
|
||||
|
||||
@ByteProperty(3)
|
||||
private short age;
|
||||
|
||||
@ByteProperty(4)
|
||||
private Address address;
|
||||
|
||||
@ByteProperty(5)
|
||||
private Contact[] contacts;
|
||||
|
||||
// Getters and Setters...
|
||||
}
|
||||
```
|
||||
|
||||
```java
|
||||
// Create Byte Mapper Context
|
||||
ByteMapperContext context = new ByteMapperContext();
|
||||
mapper = context.getByteMapper();
|
||||
|
||||
// Write User object to ByteBuffer
|
||||
ByteBuffer exampleBuffer = ByteBuffer.allocate(1024);
|
||||
mapper.write(exampleBuffer, user);
|
||||
|
||||
buffer.flip();
|
||||
|
||||
// Read User object from ByteBuffer
|
||||
user = mapper.read(exampleBuffer);
|
||||
```
|
||||
Reference in New Issue
Block a user