use of com.ociweb.gl.api.FieldType in project GreenLightning by oci-pronghorn.
the class GreenParserMessageTest method complexStringTest.
@Test
public void complexStringTest() {
NumberFormat formatter = new DecimalFormat("#0.0000");
final GreenReader reader = buildParser().newReader();
ChannelReader testToRead = BlobReaderFactory.generateExtractionDataToTest(new MyConsumer<DataOutputBlobWriter<?>>() {
@Override
public void accept(DataOutputBlobWriter<?> dataOutputBlobWriter) {
complexStreamAppend(dataOutputBlobWriter);
}
});
reader.beginRead(testToRead);
StringBuilder rebuild = new StringBuilder();
while (reader.hasMore()) {
int parsedId = (int) reader.readToken();
if (parsedId == -1) {
reader.skipByte();
} else {
final MsgField msgField = messages[parsedId];
final FieldType fieldType = msgField.type;
final String key = msgField.key;
rebuild.append(key);
switch(fieldType) {
case integer:
{
int value = (int) reader.extractedLong(0);
rebuild.append(value);
break;
}
case int64:
{
long value = reader.extractedLong(0);
rebuild.append(value);
break;
}
case string:
{
StringBuilder value = new StringBuilder();
reader.copyExtractedUTF8ToAppendable(0, value);
rebuild.append("\"");
rebuild.append(value);
rebuild.append("\"");
break;
}
case floatingPoint:
{
double value = reader.extractedDouble(0);
rebuild.append(formatter.format(value));
break;
}
}
}
}
assertEquals(complexData, rebuild.toString());
}
Aggregations