Skip to content

Commit 2a24b98

Browse files
author
Dan Geabunea
committed
Modified README.md to include info about creating custom SP and RE implementations in the ASTERIX decoder/encoder
1 parent 7eeee00 commit 2a24b98

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,49 @@ for (AsterixDataBlock asterixDataBlock : dataBlocks) {
5858
}
5959
}
6060
```
61+
62+
## How to implement a custom Reserved Field
63+
64+
In order to implement a custom reserved AsterixField, you first need to create
65+
a new class and inherit ReservedAsterixField. Then, you have to add implementations
66+
for the encode and decode methods, like in the example bellow.
67+
68+
```java
69+
public class SomeCustomReservedFiled extends ReservedAsterixField {
70+
@Override
71+
public int decode(byte[] input, int offset, int inputLength) {
72+
//TODO: add custom logic
73+
}
74+
75+
@Override
76+
public byte[] encode() {
77+
//TODO: add custom logic
78+
}
79+
}
80+
81+
```
82+
83+
Then, you need to create a custom factory for the new custom fields.
84+
85+
```java
86+
public class SomeCustomAsterixFieldFactory implements ReservedFieldFactory {
87+
@Override
88+
public ReservedAsterixField createSpField() {
89+
//The SP field will contain the new custom field
90+
return new SomeCustomReservedFiled();
91+
}
92+
93+
@Override
94+
public ReservedAsterixField createReField() {
95+
//We leave the default implementation
96+
return new ReservedAsterixField();
97+
}
98+
}
99+
```
100+
101+
Finally, we have to attach the custom factory to our Cat062Record.
102+
103+
```java
104+
ReservedFieldFactory customFieldFactory = new SomeCustomAsterixFieldFactory();
105+
Cat062Record cat062Record = new Cat062Record(customFieldFactory);
106+
```

0 commit comments

Comments
 (0)