Declaration of a message field.
| 23 | |
| 24 | |
| 25 | class FieldDeclaration(object): |
| 26 | ''' Declaration of a message field. ''' |
| 27 | |
| 28 | def __init__(self, name, conv): |
| 29 | ''' Declares a field. |
| 30 | |
| 31 | @param name: the name of the field - this name is used as property name |
| 32 | of parsed messages |
| 33 | @param conv: the type converter function used to parse the field - the |
| 34 | function must accept a string and return a value |
| 35 | ''' |
| 36 | |
| 37 | self.__name = name |
| 38 | self.__conv = conv |
| 39 | |
| 40 | |
| 41 | @property |
| 42 | def name(self): |
| 43 | ''' Returns the name of the field. ''' |
| 44 | return self.__name |
| 45 | |
| 46 | |
| 47 | def lex(self, value): |
| 48 | ''' Lex the field. ''' |
| 49 | |
| 50 | return self.__conv(value) |
| 51 | |
| 52 | |
| 53 | def format(self, value): |
| 54 | ''' Format the field. ''' |
| 55 | |
| 56 | return str(value) |
| 57 | |
| 58 | |
| 59 |