netmsgs  1.2.2
RoadNarrows Robotics Network Messaging Package
NetMsgsLibFlat.py
Go to the documentation of this file.
1 ###############################################################################
2 #
3 # Package: NetMsgs
4 #
5 # File: NetMsgsLibFlat.py
6 #
7 
8 """
9 NetMsgs Run-Time Library Packing and Unpacking Flat Encoding Module.
10 """
11 
12 ## \file
13 ## \package NetMsgs.NetMsgsLibFlat
14 ##
15 ## $LastChangedDate: 2010-08-04 15:07:55 -0600 (Wed, 04 Aug 2010) $
16 ## $Rev: 550 $
17 ##
18 ## \brief NetMsgs Run-Time Library Packing and Unpacking Flat Encoding Module.
19 ##
20 ## The NetMsgsLibFlat module defines the NetMsgsStreamBuf derived run-time
21 ## class. The NetMsgsFlat class provides all of the functionality to pack,
22 ## unpack, and trace messages encoded as flat fixed-length fields with no
23 ## message or field headers.
24 ##
25 ## \sa
26 ## \htmlonly
27 ## <a href="../pydoc/NetMsgs.NetMsgsLibFlat.html">PyDoc Generated Documentation</a>
28 ## \endhtmlonly
29 ##
30 ## \author Robin Knight (robin.knight@roadnarrows.com)
31 ##
32 ## \copyright
33 ## \h_copy 2010-2017. RoadNarrows LLC.\n
34 ## http://www.roadnarrows.com\n
35 ## All Rights Reserved
36 ##
37 
38 # Permission is hereby granted, without written agreement and without
39 # license or royalty fees, to use, copy, modify, and distribute this
40 # software and its documentation for any purpose, provided that
41 # (1) The above copyright notice and the following two paragraphs
42 # appear in all copies of the source code and (2) redistributions
43 # including binaries reproduces these notices in the supporting
44 # documentation. Substantial modifications to this software may be
45 # copyrighted by their authors and need not follow the licensing terms
46 # described here, provided that the new terms are clearly indicated in
47 # all files where they apply.
48 #
49 # IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
50 # OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
51 # PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
52 # DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
53 # EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
54 # THE POSSIBILITY OF SUCH DAMAGE.
55 #
56 # THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
57 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
58 # FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
59 # "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
60 # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
61 #
62 ###############################################################################
63 
64 import sys
65 import warnings
66 
67 import NetMsgsBase as nmBase
68 from NetMsgsLib import *
69 import NetMsgsLibStreamBuf as nmStream
70 
71 ## space over
72 space = lambda indent: "%*s" % (indent, '')
73 
74 #-----------------------------------------------------------------------------
75 # CLASS: NetMsgs
76 #-----------------------------------------------------------------------------
77 
78 class NetMsgsFlat(nmStream.NetMsgsStreamBuf):
79  """ RoadNarrows Flat Fixed-Field encode Net Messages Class.
80 
81  Flat message encoding for fixed-sized, flat messages with no message or
82  field header information.
83  """
84 
85  #--
86  def __init__(self, msgdefset, **kwargs):
87  """ Initialize NetMsgsFlat instance.
88 
89  Parameters:
90  msgdefset - Set of message definitions.
91  kwargs - Optional keyword arguments. See NetMsgsStreamBuf.
92  """
93  kwargs['encoding'] = 'flat'
94  nmStream.NetMsgsStreamBuf.__init__(self, msgdefset, **kwargs)
95  ##
96 
97 
98  # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
99  # Virtual Packing Functions
100  # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
101 
102  #--
103  def nmPackFieldHdr(self, fielddef, val, stateId):
104  """ Pack field header.
105 
106  No header is packed.
107 
108  Parameters:
109  fielddef - Field definition.
110  val - Field value(s).
111  stateId - Packing state id.
112 
113  Return:
114  Packed buffer.
115  """
116  self.StateFieldSet(stateId, fhdr={'fhdr_size': 0})
117  return ''
118  ##
119 
120  #--
121  def nmPackMsgHdr(self, msgid, msgdef, stateId):
122  """ Pack message header.
123 
124  No header is packed.
125 
126  Parameters:
127  msgid - Message identifier.
128  msgdef - Message definition.
129  stateId - Packing state id.
130 
131  Return:
132  Packed buffer.
133  """
134  self.StateSet(stateId, msghdr={'msghdr_size': 0})
135  return ''
136  ##
137 
138  # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
139  # Virtual Unpacking Functions
140  # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
141 
142  #--
143  def nmUnpackFieldHdr(self, buf, offset, stateId):
144  """ Unpack field header.
145 
146  No header is unpacked.
147 
148  Parameters:
149  buf - Buffer to unpack.
150  offset - Buffer offset where unpacking begins.
151  stateId - Unpacking state id.
152 
153  Return:
154  New buffer offset.
155  """
156  fhdr = self.StateFieldSet(stateId, fhdr={'fhdr_size': 0})
157  return offset
158  ##
159 
160  #--
161  def nmUnpackMsgHdr(self, msgid, msgdef, buf, offset, fvals, stateId):
162  """ Unpack message header.
163 
164  No header is unpacked.
165 
166  Parameters:
167  msgid - Message identifier.
168  msgdef - Message definition.
169  buf - Buffer to unpack.
170  offset - Buffer offset where unpacking begins.
171  fvals - Dictionary to hold unpacked field values.
172  stateId - Unpacking state id.
173 
174  Return:
175  New buffer offset.
176  """
177  self.StateSet(stateId, msghdr={'msghdr_size': 0})
178  return offset
179  ##
180 
181 ##
182 
def nmUnpackFieldHdr(self, buf, offset, stateId)
def nmPackMsgHdr(self, msgid, msgdef, stateId)
def __init__(self, msgdefset, kwargs)
def nmUnpackMsgHdr(self, msgid, msgdef, buf, offset, fvals, stateId)
def nmPackFieldHdr(self, fielddef, val, stateId)