| 1 |
package com.igormaznitsa.mvn.tst; |
| 2 |
|
| 3 |
import com.igormaznitsa.jbbp.compiler.JBBPNamedFieldInfo; |
| 4 |
import com.igormaznitsa.jbbp.compiler.tokenizer.JBBPFieldTypeParameterContainer; |
| 5 |
import com.igormaznitsa.jbbp.io.JBBPBitInputStream; |
| 6 |
import com.igormaznitsa.jbbp.io.JBBPBitOutputStream; |
| 7 |
import com.igormaznitsa.jbbp.io.JBBPByteOrder; |
| 8 |
import com.igormaznitsa.jbbp.model.JBBPAbstractArrayField; |
| 9 |
import com.igormaznitsa.jbbp.model.JBBPAbstractField; |
| 10 |
import com.igormaznitsa.jbbp.model.JBBPFieldArrayLong; |
| 11 |
import com.igormaznitsa.jbbp.model.JBBPFieldLong; |
| 12 |
import com.igormaznitsa.jbbp.model.JBBPFieldShort; |
| 13 |
import com.igormaznitsa.mvn.test.jbbp.VarCustom; |
| 14 |
import java.io.IOException; |
| 15 |
public class VarCustomImpl extends VarCustom { |
| 16 |
|
| 17 |
@Override |
| 18 |
public JBBPAbstractField readCustomFieldType(Object sourceStruct, JBBPBitInputStream inStream, |
| 19 |
JBBPFieldTypeParameterContainer typeParameterContainer, |
| 20 |
JBBPNamedFieldInfo nullableNamedFieldInfo, |
| 21 |
int extraValue, boolean readWholeStream, |
| 22 |
int arraySize) throws IOException { |
| 23 |
return new JBBPFieldShort(nullableNamedFieldInfo, |
| 24 |
(short) inStream.readUnsignedShort(typeParameterContainer.getByteOrder())); |
| 25 |
} |
| 26 |
|
| 27 |
@Override |
| 28 |
public void writeCustomFieldType(Object sourceStruct, JBBPBitOutputStream outStream, |
| 29 |
JBBPAbstractField fieldValue, |
| 30 |
JBBPFieldTypeParameterContainer typeParameterContainer, |
| 31 |
JBBPNamedFieldInfo nullableNamedFieldInfo, int extraValue, |
| 32 |
boolean wholeArray, int arraySize) throws IOException { |
| 33 |
outStream.writeShort(((JBBPFieldShort) fieldValue).getAsInt(), |
| 34 |
typeParameterContainer.getByteOrder()); |
| 35 |
} |
| 36 |
|
| 37 |
@Override |
| 38 |
public JBBPAbstractField readVarField(Object sourceStruct, JBBPBitInputStream inStream, |
| 39 |
JBBPByteOrder byteOrder, |
| 40 |
JBBPNamedFieldInfo nullableNamedFieldInfo, int extraValue) |
| 41 |
throws IOException { |
| 42 |
return new JBBPFieldLong(nullableNamedFieldInfo, inStream.readLong(byteOrder)); |
| 43 |
} |
| 44 |
|
| 45 |
@Override |
| 46 |
public JBBPAbstractArrayField<? extends JBBPAbstractField> readVarArray(Object sourceStruct, |
| 47 |
JBBPBitInputStream inStream, |
| 48 |
JBBPByteOrder byteOrder, |
| 49 |
JBBPNamedFieldInfo nullableNamedFieldInfo, |
| 50 |
int extraValue, |
| 51 |
boolean readWholeStream, |
| 52 |
int arraySize) |
| 53 |
throws IOException { |
| 54 |
if (readWholeStream) { |
| 55 |
return new JBBPFieldArrayLong(nullableNamedFieldInfo, inStream.readLongArray(-1, byteOrder)); |
| 56 |
} else { |
| 57 |
return new JBBPFieldArrayLong(nullableNamedFieldInfo, |
| 58 |
inStream.readLongArray(arraySize, byteOrder)); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
@Override |
| 63 |
public void run() { |
| 64 |
} |
| 65 |
|
| 66 |
@Override |
| 67 |
public void writeVarField(Object sourceStruct, JBBPAbstractField value, |
| 68 |
JBBPBitOutputStream outStream, JBBPByteOrder byteOrder, |
| 69 |
JBBPNamedFieldInfo nullableNamedFieldInfo, int extraValue) |
| 70 |
throws IOException { |
| 71 |
outStream.writeLong(((JBBPFieldLong) value).getAsLong(), byteOrder); |
| 72 |
} |
| 73 |
|
| 74 |
@Override |
| 75 |
public void writeVarArray(Object sourceStruct, |
| 76 |
JBBPAbstractArrayField<? extends JBBPAbstractField> array, |
| 77 |
JBBPBitOutputStream outStream, JBBPByteOrder byteOrder, |
| 78 |
JBBPNamedFieldInfo nullableNamedFieldInfo, int extraValue, |
| 79 |
int arraySizeToWrite) throws IOException { |
| 80 |
final JBBPFieldArrayLong a = (JBBPFieldArrayLong) array; |
| 81 |
if (arraySizeToWrite < 0) { |
| 82 |
for (final long l : a.getArray()) { |
| 83 |
outStream.writeLong(l, byteOrder); |
| 84 |
} |
| 85 |
} else { |
| 86 |
final long[] larr = a.getArray(); |
| 87 |
for (int i = 0; i < arraySizeToWrite; i++) { |
| 88 |
outStream.writeLong(larr[i], byteOrder); |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
} |