Module bzProtocol :: Class bzProtocol
[frames] | no frames]

Class bzProtocol

source code


This class provides BZoo applications with message packing and unpacking services.

Exemple:
   import bzMessage
   
   def myHandlerFct(values):
       messages = values
       print "I've just received message(s): ", messages
               
            
   # initialisation of protocol and message list
   aProtocol = bzProtocol()   
   message_queue = []
   message_queue.append(bzMessage.SayMessage("Hello World"))
   
   # setup a handler on reception of message
   self.aProtocol(bzMessage.CLIENTS_MESSAGES_MESSAGE,myHandlerFct)

   # prepare raw data to send from current list of message
   data2send = aProtocol.getNextDataMessage(message_queue, 1024)
                 
   SendData (data2send)

   # process incoming message
   data = ReceiveData ()
   if (data is not None):
       aProtocol.processDataMessage(data)


Instance Methods
 
__init__(self) source code
 
__repr__(self) source code
 
addHandler(self, msgType, fct)
Add a handler on reception of a peculiar message
source code
byte array.
getNextDataMessage(self, msg_list, max_size)
Build a packed data block
source code
 
processDataMessage(self, data)
Unpack received data into messages and call associated handler.
source code
Instance Variables
list of list of handler function HandlerTable
gives the functions to
  MessageTable
Method Details

addHandler(self, msgType, fct)

source code 
Add a handler on reception of a peculiar message
Parameters:
  • msgType (integer.) - the type of the message to attach the handler to
  • fct (function.) - the handler function.

getNextDataMessage(self, msg_list, max_size)

source code 
Build a packed data block
Parameters:
  • msg_list (String.) - The server hostname or IP adress
  • max_size (Integer) - the maximum size of the data packet to produce
Returns: byte array.
the next packed data block to send.

processDataMessage(self, data)

source code 
Unpack received data into messages and call associated handler.
Parameters:
  • data (byte array.) - A packed data block