use of com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager in project PronghornPipes by oci-pronghorn.
the class TemplateProcessGeneratorLowLevelReader method defineMembers.
@Override
protected void defineMembers() throws IOException {
final FieldReferenceOffsetManager from = MessageSchema.from(schema);
workspace1 = new StringBuilder();
for (int cursor = 0; cursor < from.tokens.length; cursor++) {
String name = from.fieldNameScript[cursor];
long id = from.fieldIdScript[cursor];
int token = from.tokens[cursor];
int type = TokenBuilder.extractType(token);
if (TypeMask.TextASCII == type | TypeMask.TextASCIIOptional == type | TypeMask.TextUTF8 == type | TypeMask.TextUTF8Optional == type) {
preprocessTextfieldsDef(name, id);
} else if (TypeMask.ByteVector == type | TypeMask.ByteVectorOptional == type) {
preprocessBytefieldsDef(name, id);
}
}
if (!from.hasSimpleMessagesOnly) {
bodyTarget.append("private LowLevelStateManager navState;\n");
}
appendClass(bodyTarget.append("private "), pipeClass, schema.getClass()).append(pipeVarName).append(";\n");
// put schema into code
from.appendConstuctionSource(bodyTarget);
additionalMembers(bodyTarget);
bodyTarget.append("\n");
bodyTarget.append("// GENERATED LOW LEVEL READER \n");
bodyTarget.append("// # Low level API is the fastest way of reading from a pipe in a business semantic way. \n");
bodyTarget.append("// # Do not change the order that fields are read, this is fixed when using low level. \n");
bodyTarget.append("// # Do not remove any field reading, every field must be consumed when using low level. \n");
bodyTarget.append("\n");
bodyTarget.append("// Details to keep in mind when you expect the schema to change over time\n");
bodyTarget.append("// # Low level API is CAN be extensiable in the sense which means ignore unrecognized messages. \n");
bodyTarget.append("// # Low level API is CAN NOT be extensiable in the sense of dealing with mising or extra/new fields. \n");
bodyTarget.append("// # Low level API is CAN NOT be extensiable in the sense of dealing with fields encoded with different types. \n");
from.appendGUID(bodyTarget.append("private static final int[] FROM_GUID = ")).append(";\n");
bodyTarget.append("private static final long BUILD_TIME = ");
Appendables.appendValue(bodyTarget, System.currentTimeMillis()).append("L;\n");
// TODO: fix hexDigits it is out of bounds.
}
use of com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager in project PronghornPipes by oci-pronghorn.
the class TemplateProcessGeneratorLowLevelReader method bodyBuilder.
// override this method !!
protected void bodyBuilder(MessageSchema schema, int cursor, int fragmentParaCount, CharSequence[] fragmentParaTypes, CharSequence[] fragmentParaArgs, CharSequence[] fragmentParaSuff) {
// This is example code only to be tossed.
// The runtime code should call this once, this comment is code to be generated but NOT here.
// int[] intDictionary = from.newIntDefaultsDictionary()
// intp[ prevDictionary = ....
FieldReferenceOffsetManager from = MessageSchema.from(schema);
int curCursor = cursor;
long activePmap = 0;
for (int paramIdx = 0; paramIdx < fragmentParaCount; paramIdx++) {
String varName = new StringBuilder().append(fragmentParaArgs[paramIdx]).append(fragmentParaSuff[paramIdx]).toString();
String varType = new StringBuilder().append(fragmentParaTypes[paramIdx]).toString();
int token = from.tokens[curCursor];
// Good stuff goes here.
// this comment is an example of what should be generated not executed here.
// activePmap = pmapBuilding( activePmap, token. <varName> , initDictionary[curCursor], prev??
// / varName is the name of the variable that holds the cur value.
// Which pmap should be called??? switch on varType.
curCursor += TypeMask.scriptTokenSize[TokenBuilder.extractType(token)];
}
// now THE PMAP IS BUILT.
// NOW GENERATE WRITE IT CODE
}
use of com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager in project PronghornPipes by oci-pronghorn.
the class TemplateProcessGenerator method processSchema.
public void processSchema() throws IOException {
headerConstruction();
defineMembers();
final FieldReferenceOffsetManager from = MessageSchema.from(schema);
// Build top level entry point
processCallerPrep();
for (int cursor = 0; cursor < from.fragScriptSize.length; cursor++) {
boolean isFragmentStart = 0 != from.fragScriptSize[cursor];
if (isFragmentStart) {
processCaller(cursor);
}
}
processCallerPost();
// Build fragment consumption methods
for (int cursor = 0; cursor < from.fragScriptSize.length; cursor++) {
boolean isFragmentStart = 0 != from.fragScriptSize[cursor];
if (isFragmentStart) {
processCalleeOpen(cursor);
boolean isMessageStart = FieldReferenceOffsetManager.isTemplateStart(from, cursor);
if (isMessageStart) {
processFragment(1, cursor, from);
} else {
processFragment(0, cursor, from);
}
processCalleeClose(cursor);
}
}
footerConstruction();
}
use of com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager in project PronghornPipes by oci-pronghorn.
the class TemplateProcessGeneratorTest method testGenerateLowLevelWriterCleanCompile.
@Test
public void testGenerateLowLevelWriterCleanCompile() {
if ("arm".equals(System.getProperty("os.arch"))) {
assertTrue(true);
} else {
try {
FieldReferenceOffsetManager from = TemplateHandler.loadFrom("/template/smallExample.xml");
MessageSchema schema = new MessageSchemaDynamic(from);
String className = "LowLevelWriter";
StringBuilder target = new StringBuilder();
TemplateProcessGeneratorLowLevelWriter simple = new TemplateProcessGeneratorLowLevelWriter(schema, target, true, "com.ociweb.pronghorn.pipe.build");
simple.processSchema();
// System.out.println(target);
validateCleanCompile(className, target);
} catch (ParserConfigurationException e) {
e.printStackTrace();
fail();
} catch (SAXException e) {
e.printStackTrace();
fail();
} catch (IOException e) {
e.printStackTrace();
fail();
}
}
}
Aggregations