source: proto/FIX/fix.py

Last change on this file was 1456, checked in by cameron, 8 years ago

Use pablo. in place of bitutil.

File size: 1.8 KB
Line 
1#
2# FIX parsing prototype
3# Robert D. Cameron   Aug. 17, 2011
4# (c)  All rights reserved.
5#
6
7class Basis_bits():     
8        bit_0 = 0
9        bit_1 = 0
10        bit_2 = 0
11        bit_3 = 0
12        bit_4 = 0
13        bit_5 = 0
14        bit_6 = 0
15        bit_7 = 0
16
17class Fix_lex():
18        SOH = 0
19        Equals = 0
20        Digit = 0
21        Zero = 0
22
23class Fix_callout():
24        Header_end = 0
25
26def Classify_bytes(basis_bits, fix_lex): 
27        temp1 = (basis_bits.bit_0 | basis_bits.bit_1)
28        temp2 = (basis_bits.bit_2 | basis_bits.bit_3)
29        temp3 = (temp1 | temp2)
30        temp4 = (basis_bits.bit_4 | basis_bits.bit_5)
31        temp5 = (basis_bits.bit_7 &~ basis_bits.bit_6)
32        temp6 = (temp5 &~ temp4)
33        fix_lex.SOH = (temp6 &~ temp3)
34        temp7 = (basis_bits.bit_2 & basis_bits.bit_3)
35        temp8 = (temp7 &~ temp1)
36        temp9 = (basis_bits.bit_4 & basis_bits.bit_5)
37        temp10 = (temp9 & temp5)
38        fix_lex.Equals = (temp8 & temp10)
39        temp11 = (basis_bits.bit_5 | basis_bits.bit_6)
40        temp12 = (basis_bits.bit_4 & temp11)
41        fix_lex.Digit = (temp8 &~ temp12)
42        temp13 = (basis_bits.bit_6 | basis_bits.bit_7)
43        temp14 = (temp4 | temp13)
44        fix_lex.Zero = (temp8 &~ temp14)
45
46def Parse_fields(fix_lex, fix_callout):
47        # Fields must begin with a nonzero digit.
48        allowed_leading_digit = fix_lex.Digit &~ fix_lex.Zero
49        # Assume for now that all SOHs are field separators, not data.
50        # Use negated SOH stream to shift in a 1 at start-of-file.
51        starts = ~pablo.Advance(~fix_lex.SOH)
52        EOF_pos = pablo.Advance(EOF_mask) &~ EOF_mask
53        msg_starts = starts & EOF_mask
54        error1 = EOF_pos &~ starts
55        error2 = msg_starts &~ allowed_leading_digit
56        field_ends = pablo.ScanThru(msg_starts, fix_lex.Digit)
57        error3 = field_ends &~ fix_lex.Equals
58        error = error1 | error2 | error3
59        if error:
60                error_tracker.NoteError("Potential error in header field", error)
61        fix_callout.Header_end = field_ends
62
63def main(basis_bits, fix_lex):
64        Classify_bytes(basis_bits, fix_lex)
65
66        Parse_fields(fix_lex, fix_callout)
67
68
Note: See TracBrowser for help on using the repository browser.