Search in sources :

Example 6 with TrieParser

use of com.ociweb.pronghorn.util.TrieParser in project FogLight-Examples by oci-pronghorn.

the class ValveDataParserStage method buildParser.

// Manifold serial number: u32
// Station number: u8
// Valve serial number: u32
// Part number: string
// Life cycle count: u32
// Valve fault: u8
// Pressure fault: 1-character string
// Leak fault: u8
// Supply pressure: u16
// Duration of last 1-4 signal: u32
// Duration of last 1-2 signal: u32
// 
// Equalization average pressure: u16
// Equalization pressure rate: i16
// Residual of dynamic analysis: u16
// package protected for testing
static TrieParser buildParser() {
    TrieParser tp = new TrieParser(256, 1, false, true);
    // ///////////////////////
    // these are needed to "capture" error cases early, the tighter we make them the sooner we find the issues.
    tp.setMaxNumericLengthCapturable(16);
    tp.setMaxBytesCapturable(36);
    // ///////////////////////
    tp.setUTF8Value("[st%u", DATA_START);
    tp.setUTF8Value("sn%i", ValveSchema.MSG_VALVESERIALNUMBER_311);
    tp.setUTF8Value("pn\"%b\"", ValveSchema.MSG_PARTNUMBER_330);
    tp.setUTF8Value("cc%i", ValveSchema.MSG_LIFECYCLECOUNT_312);
    tp.setUTF8Value("sp%i", ValveSchema.MSG_SUPPLYPRESSURE_313);
    tp.setUTF8Value("pp%i", ValveSchema.MSG_PRESSUREPOINT_319);
    tp.setUTF8Value("da%i", ValveSchema.MSG_DURATIONOFLAST1_4SIGNAL_314);
    tp.setUTF8Value("db%i", ValveSchema.MSG_DURATIONOFLAST1_2SIGNAL_315);
    tp.setUTF8Value("ap%i", ValveSchema.MSG_EQUALIZATIONAVERAGEPRESSURE_316);
    tp.setUTF8Value("ep%i", ValveSchema.MSG_EQUALIZATIONPRESSURERATE_317);
    tp.setUTF8Value("lr%i", ValveSchema.MSG_RESIDUALOFDYNAMICANALYSIS_318);
    tp.setUTF8Value("vf%i", ValveSchema.MSG_VALVEFAULT_340);
    tp.setUTF8Value("pf\"%b\"", ValveSchema.MSG_PRESSUREFAULT_350);
    tp.setUTF8Value("lf%i", ValveSchema.MSG_LEAKFAULT_360);
    tp.setUTF8Value("]", DATA_END);
    tp.setUTF8Value("\n", DATA_IGNORE);
    tp.setUTF8Value("\r", DATA_IGNORE);
    return tp;
}
Also used : TrieParser(com.ociweb.pronghorn.util.TrieParser)

Example 7 with TrieParser

use of com.ociweb.pronghorn.util.TrieParser in project FogLight-Examples by oci-pronghorn.

the class UARTDataParserTest method coreParserTest.

@Test
public void coreParserTest() {
    TrieParser trie = ValveDataParserStage.buildParser();
    // System.out.println(trie);
    String example = "[st1sn100100pn\"NX-DCV-SM-BLU-1-1-VO-L1-SO-OO\"lr-100cc184587lf0pf\"L\"vf0sp80]";
    byte[] exampleBytes = example.getBytes();
    TrieParserReader reader = new TrieParserReader(10);
    TrieParserReader.parseSetup(reader, exampleBytes, 0, exampleBytes.length, Integer.MAX_VALUE);
    int actualStartId = (int) TrieParserReader.parseNext(reader, trie);
    assertEquals(DATA_START, actualStartId);
    assertEquals(1, TrieParserReader.capturedLongField(reader, 0));
    assertEquals(ValveSchema.MSG_VALVESERIALNUMBER_311, (int) TrieParserReader.parseNext(reader, trie));
    assertEquals(100100, TrieParserReader.capturedLongField(reader, 0));
    assertEquals(ValveSchema.MSG_PARTNUMBER_330, (int) TrieParserReader.parseNext(reader, trie));
    StringBuilder target = new StringBuilder();
    TrieParserReader.capturedFieldBytesAsUTF8(reader, 0, target);
    assertEquals("NX-DCV-SM-BLU-1-1-VO-L1-SO-OO", target.toString());
    assertEquals(ValveSchema.MSG_RESIDUALOFDYNAMICANALYSIS_318, (int) TrieParserReader.parseNext(reader, trie));
    assertEquals(-100, TrieParserReader.capturedLongField(reader, 0));
    assertEquals(ValveSchema.MSG_LIFECYCLECOUNT_312, (int) TrieParserReader.parseNext(reader, trie));
    assertEquals(184587, TrieParserReader.capturedLongField(reader, 0));
    assertEquals(ValveSchema.MSG_LEAKFAULT_360, (int) TrieParserReader.parseNext(reader, trie));
    assertEquals(ValveSchema.MSG_PRESSUREFAULT_350, (int) TrieParserReader.parseNext(reader, trie));
    assertEquals(ValveSchema.MSG_VALVEFAULT_340, (int) TrieParserReader.parseNext(reader, trie));
    assertEquals(ValveSchema.MSG_SUPPLYPRESSURE_313, (int) TrieParserReader.parseNext(reader, trie));
    assertEquals(80, TrieParserReader.capturedLongField(reader, 0));
    assertEquals(DATA_END, (int) TrieParserReader.parseNext(reader, trie));
    assertEquals(-1, (int) TrieParserReader.parseNext(reader, trie));
}
Also used : TrieParser(com.ociweb.pronghorn.util.TrieParser) TrieParserReader(com.ociweb.pronghorn.util.TrieParserReader) Test(org.junit.Test)

Example 8 with TrieParser

use of com.ociweb.pronghorn.util.TrieParser in project PronghornPipes by oci-pronghorn.

the class DataInputBlobReader method textToNumberTrieParser.

// //////
// parsing methods
// /////
public static TrieParser textToNumberTrieParser() {
    if (textToNumberParser == null) {
        // supports streaming, so false
        TrieParser p = new TrieParser(8, false);
        p.setUTF8Value("%i%.", 1);
        // p.setUTF8Value("%i%.%/%.", 1);
        // the above pattern can parse  234 and 234.34 and 23/45 and 23.4/56.7
        // it also supports the normal capture methods for ints and decimals with no change
        // TrieParserReader.capturedLongField(parserReader, 0)
        textToNumberParser = p;
    }
    return textToNumberParser;
}
Also used : TrieParser(com.ociweb.pronghorn.util.TrieParser)

Example 9 with TrieParser

use of com.ociweb.pronghorn.util.TrieParser in project GreenLightning by oci-pronghorn.

the class ReactiveListenerStage method addSubscription.

public final <T extends Behavior> ListenerFilter addSubscription(CharSequence topic, CallableStaticMethod<T> method) {
    if (null == methods) {
        methodLookup = new TrieParser(16, 1, false, false, false);
        methodReader = new TrieParserReader(0, true);
        methods = new CallableStaticMethod[0];
    }
    if (!startupCompleted && listener instanceof PubSubMethodListenerBase) {
        builder.addStartupSubscription(topic, System.identityHashCode(listener), parallelInstance);
        toStringDetails = toStringDetails + "sub:'" + topic + "'\n";
    } else {
        if (startupCompleted) {
            throw new UnsupportedOperationException("Method dispatch subscritpions may not be modified at runtime.");
        }
    }
    int id = methods.length;
    methodLookup.setUTF8Value(topic, id);
    // grow the array of methods to be called
    CallableStaticMethod[] newArray = new CallableStaticMethod[id + 1];
    System.arraycopy(methods, 0, newArray, 0, id);
    newArray[id] = method;
    methods = newArray;
    // 
    return this;
}
Also used : PubSubMethodListenerBase(com.ociweb.gl.impl.PubSubMethodListenerBase) TrieParser(com.ociweb.pronghorn.util.TrieParser) TrieParserReader(com.ociweb.pronghorn.util.TrieParserReader)

Example 10 with TrieParser

use of com.ociweb.pronghorn.util.TrieParser in project PronghornPipes by oci-pronghorn.

the class StructRegistry method addStruct.

/**
 * Add new Structure to the schema
 * @param fieldNames - name for each field
 * @param fieldTypes - type for each field
 * @param fieldDim - dominations for this field, should be 0 for most cases of simple data
 * @return the array of field identifiers in the same order as defined
 */
public int addStruct(byte[][] fieldNames, // all fields are precede by array count byte
StructTypes[] fieldTypes, // Dimensionality, should be 0 for simple objects.
int[] fieldDim, Object[] fieldAssoc) {
    assert (fieldNames.length == fieldTypes.length);
    if (null != fieldDim) {
        assert (fieldNames.length == fieldDim.length);
        maxDims(fieldDim);
    }
    int structIdx = structCount++;
    grow(structCount);
    int n = fieldNames.length;
    boolean skipDeepChecks = false;
    boolean supportsExtraction = false;
    boolean ignoreCase = true;
    TrieParser fieldParser = new TrieParser(n * 20, 4, skipDeepChecks, supportsExtraction, ignoreCase);
    long base = ((long) (IS_STRUCT_BIT | (STRUCT_MASK & structIdx))) << STRUCT_OFFSET;
    while (--n >= 0) {
        assert (isNotAlreadyDefined(fieldParser, fieldNames[n]));
        // bad value..
        fieldParser.setValue(fieldNames[n], base | n);
    }
    this.fields[structIdx] = fieldParser;
    this.fieldNames[structIdx] = fieldNames;
    this.fieldTypes[structIdx] = fieldTypes;
    this.fieldDims[structIdx] = null == fieldDim ? new int[fieldTypes.length] : fieldDim;
    this.fieldLocals[structIdx] = new Object[fieldNames.length];
    this.fieldAttachedIndex[structIdx] = new IntHashTable(IntHashTable.computeBits(Math.max(fieldNames.length, 8) * 3));
    if (null != fieldAssoc) {
        int j = fieldAssoc.length;
        while (--j >= 0) {
            if (null != fieldAssoc[j]) {
                setAssoc(fieldAssoc[j], structIdx, j);
            }
        }
    }
    return structIdx | IS_STRUCT_BIT;
}
Also used : IntHashTable(com.ociweb.pronghorn.pipe.util.hash.IntHashTable) TrieParser(com.ociweb.pronghorn.util.TrieParser)

Aggregations

TrieParser (com.ociweb.pronghorn.util.TrieParser)17 TrieParserReader (com.ociweb.pronghorn.util.TrieParserReader)3 IntHashTable (com.ociweb.pronghorn.pipe.util.hash.IntHashTable)2 PubSubMethodListenerBase (com.ociweb.gl.impl.PubSubMethodListenerBase)1 Test (org.junit.Test)1