Permalink
Browse files

added another shitty project

  • Loading branch information...
1 parent 6e61151 commit 26f3f0db853fc845d4b741bd2a6e1d2278504792 @ksergey committed Feb 17, 2017
@@ -0,0 +1,91 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*,cover
+.hypothesis/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# pyenv
+.python-version
+
+# celery beat schedule file
+celerybeat-schedule
+
+# dotenv
+.env
+
+# virtualenv
+.venv
+venv/
+ENV/
+
+# Spyder project settings
+.spyderproject
+
+# Rope project settings
+.ropeproject
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe"
+ package="baseline"
+ id="1"
+ version="0"
+ semanticVersion="5.2"
+ description="Example schema"
+ byteOrder="littleEndian">
+ <types>
+ <composite name="messageHeader" description="Message identifiers and length of message root">
+ <type name="blockLength" primitiveType="uint16"/>
+ <type name="templateId" primitiveType="uint16"/>
+ <type name="schemaId" primitiveType="uint16"/>
+ <type name="version" primitiveType="uint16"/>
+ </composite>
+ <composite name="groupSizeEncoding" description="Repeating group dimensions">
+ <type name="blockLength" primitiveType="uint16"/>
+ <type name="numInGroup" primitiveType="uint16"/>
+ </composite>
+ <composite name="varDataEncoding">
+ <type name="length" primitiveType="uint32" maxValue="1073741824"/>
+ <type name="varData" primitiveType="uint8" length="0" characterEncoding="UTF-8"/>
+ </composite>
+ </types>
+ <types>
+ <type name="ModelYear" primitiveType="uint16"/>
+ <type name="VehicleCode" primitiveType="char" length="6" characterEncoding="ASCII"/>
+ <type name="Ron" primitiveType="uint8" minValue="90" maxValue="110"/>
+ <type name="someNumbers" primitiveType="uint32" length="5"/>
+ <composite name="Booster">
+ <enum name="BoostType" encodingType="char">
+ <validValue name="TURBO">T</validValue>
+ <validValue name="SUPERCHARGER">S</validValue>
+ <validValue name="NITROUS">N</validValue>
+ <validValue name="KERS">K</validValue>
+ </enum>
+ <type name="horsePower" primitiveType="uint8"/>
+ </composite>
+ <composite name="Engine">
+ <type name="capacity" primitiveType="uint16"/>
+ <type name="numCylinders" primitiveType="uint8"/>
+ <type name="maxRpm" primitiveType="uint16" presence="constant">9000</type>
+ <type name="manufacturerCode" primitiveType="char" length="3"/>
+ <type name="fuel" primitiveType="char" presence="constant">Petrol</type>
+ <ref name="booster" type="Booster"/>
+ </composite>
+ <enum name="BooleanType" encodingType="uint8">
+ <validValue name="F">0</validValue>
+ <validValue name="T">1</validValue>
+ </enum>
+ <enum name="Model" encodingType="char">
+ <validValue name="A">A</validValue>
+ <validValue name="B">B</validValue>
+ <validValue name="C">C</validValue>
+ </enum>
+ <set name="OptionalExtras" encodingType="uint8">
+ <choice name="sunRoof">0</choice>
+ <choice name="sportsPack">1</choice>
+ <choice name="cruiseControl">2</choice>
+ </set>
+ </types>
+ <sbe:message name="Car" id="1" description="Description of a basic Car">
+ <field name="serialNumber" id="1" type="uint64"/>
+ <field name="modelYear" id="2" type="ModelYear"/>
+ <field name="available" id="3" type="BooleanType"/>
+ <field name="code" id="4" type="Model"/>
+ <field name="someNumbers" id="5" type="someNumbers"/>
+ <field name="vehicleCode" id="6" type="VehicleCode"/>
+ <field name="extras" id="7" type="OptionalExtras"/>
+ <field name="discountedModel" id="8" type="Model" presence="constant" valueRef="Model.C"/>
+ <field name="engine" id="9" type="Engine"/>
+ <group name="fuelFigures" id="10" dimensionType="groupSizeEncoding">
+ <field name="speed" id="11" type="uint16"/>
+ <field name="mpg" id="12" type="float"/>
+ <data name="usageDescription" id="200" type="varDataEncoding"/>
+ </group>
+ <group name="performanceFigures" id="13" dimensionType="groupSizeEncoding">
+ <field name="octaneRating" id="14" type="Ron"/>
+ <group name="acceleration" id="15" dimensionType="groupSizeEncoding">
+ <field name="mph" id="16" type="uint16"/>
+ <field name="seconds" id="17" type="float"/>
+ </group>
+ </group>
+ <data name="manufacturer" id="18" type="varDataEncoding"/>
+ <data name="model" id="19" type="varDataEncoding"/>
+ <data name="activationCode" id="20" type="varDataEncoding"/>
+ </sbe:message>
+</sbe:messageSchema>
@@ -0,0 +1,7 @@
+#!/usr/bin/env python3
+
+import sbe
+
+schema0 = sbe.Schema("example-schema.xml")
+#schema1 = sbe.Schema("wire.xml")
+#print(schema.__getType("char"))
@@ -0,0 +1 @@
+from .schema import Schema
@@ -0,0 +1,49 @@
+class Field(object):
+ def __init__(self, node):
+ self.__tag = node.tag
+ self.__name = node.get("name")
+ self.__id = int(node.get("id"))
+ self.__description = node.get("description")
+
+ def tag(self):
+ return self.__tag
+
+ def name(self):
+ return self.__name
+
+ def id(self):
+ return self.__id
+
+ def description(self):
+ return self.__description
+
+class EncodedField(Field):
+ def __init__(self, node):
+ if node.tag != "field":
+ raise
+
+ super().__init__(node)
+
+ self.__type = node.get("type")
+ self.__offset = node.get("offset")
+ self.__semanticType = node.get("semanticType")
+
+ def type(self):
+ return self.__type
+
+ def offset(self):
+ return self.__offset
+
+ def semanticType(self):
+ return self.__semanticType
+
+class GroupField(Field):
+ def __init__(self, node):
+ if node.tag != "group":
+ raise
+
+ super().__init__(node)
+
+ self.__blockLength = node.get("blockLength")
+ self.__dimensionType = node.get("dimensionType")
+
@@ -0,0 +1,49 @@
+class PrimitiveType(object):
+ __types = {}
+
+ def __init__(self, name, size, minValue, maxValue, nullValue):
+ self.__name = name
+ self.__size = size
+ self.__minValue = minValue
+ self.__maxValue = maxValue
+ self.__nullValue = nullValue
+
+ def name(self):
+ return self.__name
+
+ def size(self):
+ return self.__size
+
+ def minValue(self):
+ return self.__minValue
+
+ def maxValue(self):
+ return self.__maxValue
+
+ def nullValue(self):
+ return self.__nullValue
+
+ @staticmethod
+ def add(type):
+ PrimitiveType.__types[type.name()] = type
+
+ @staticmethod
+ def get(name):
+ if not name in PrimitiveType.__types:
+ raise Exception("Primitive type " + name + " not found")
+ return PrimitiveType.__types[name]
+
+# Init primitive types
+PrimitiveType.add(PrimitiveType("char", 1, "SBE_MIN_char", "SBE_MAX_char", "SBE_NULL_char"))
+PrimitiveType.add(PrimitiveType("char", 1, "SBE_MIN_char", "SBE_MAX_char", "SBE_NULL_char"))
+PrimitiveType.add(PrimitiveType("int8", 1, "SBE_MIN_int8", "SBE_MAX_int8", "SBE_NULL_int8"))
+PrimitiveType.add(PrimitiveType("uint8", 1, "SBE_MIN_uint8", "SBE_MAX_uint8", "SBE_NULL_uint8"))
+PrimitiveType.add(PrimitiveType("int16", 2, "SBE_MIN_int16", "SBE_MAX_int16", "SBE_NULL_int16"))
+PrimitiveType.add(PrimitiveType("uint16", 2, "SBE_MIN_uint16", "SBE_MAX_uint16", "SBE_NULL_uint16"))
+PrimitiveType.add(PrimitiveType("int32", 4, "SBE_MIN_int32", "SBE_MAX_int32", "SBE_NULL_int32"))
+PrimitiveType.add(PrimitiveType("uint32", 4, "SBE_MIN_uint32", "SBE_MAX_uint32", "SBE_NULL_uint32"))
+PrimitiveType.add(PrimitiveType("int64", 8, "SBE_MIN_int64", "SBE_MAX_int64", "SBE_NULL_int64"))
+PrimitiveType.add(PrimitiveType("uint64", 8, "SBE_MIN_uint64", "SBE_MAX_uint64", "SBE_NULL_uint64"))
+PrimitiveType.add(PrimitiveType("float", 4, "SBE_MIN_float", "SBE_MAX_float", "SBE_NULL_float"))
+PrimitiveType.add(PrimitiveType("double", 8, "SBE_MIN_double", "SBE_MAX_double", "SBE_NULL_double"))
+
@@ -0,0 +1,32 @@
+from lxml import etree
+from .types import Type, EncodedType, EnumType, SetType, CompositeType
+from .field import Field
+
+def loadSchema(filename):
+ with open(filename, 'r') as f:
+ return etree.fromstring(f.read().encode('utf-8'), etree.XMLParser())
+
+class Schema(object):
+ def __init__(self, xml_file):
+ schema = loadSchema(xml_file)
+ self.package = schema.get("package")
+ self.version = schema.get("version")
+ self.byteOrder = schema.get("byteOrder")
+ if self.byteOrder != "littleEndian":
+ raise
+
+ # First run over "type"
+ for types in schema.findall('{*}types'):
+ for node in types:
+ if node.tag == "type":
+ Type.add(EncodedType(node))
+
+ # Other types
+ for types in schema.findall('{*}types'):
+ for node in types:
+ if node.tag == "enum":
+ Type.add(EnumType(node))
+ elif node.tag == "set":
+ Type.add(SetType(node))
+ elif node.tag == "composite":
+ Type.add(CompositeType(node))
Oops, something went wrong.

0 comments on commit 26f3f0d

Please sign in to comment.