source: proto/FIX/fix.py @ 1315

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

Negated SOH for shift-in of 1

File size: 1.6 KB
Line 
1#
2# FIX parsing prototype
3# Robert D. Cameron   Aug. 17, 2011
4#
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        # Assume for now that all SOHs are field separators, not data.
48        # Use negated SOH stream to shift in a 1 at start-of-file.
49        # shift out a 0 at end of file.
50        marker = ~bitutil.Advance(~fix_lex.SOH)
51        header1 = marker
52        header2 = bitutil.ScanThru(marker, fix_lex.Digit)
53        error1 = header1 & fix_lex.Zero
54        error2 = header1 & header2
55        error3 = header2 &~ fix_lex.Equals
56        error = error1 | error2 | error3
57        if error:
58                error_tracker.NoteError("Potential error in header field", error)
59        fix_callout.Header_end = header2
60
61def main(basis_bits, fix_lex):
62        Classify_bytes(basis_bits, fix_lex)
63
64        Parse_fields(fix_lex, fix_callout)
65
66
Note: See TracBrowser for help on using the repository browser.