TDecoder
Previous  Top  Next

TDecoder(strName, fDecoder, ctChildBlocks)

The Decoder constructor creates a new decoder. You have to specify a unique name, a decoder function, and a container of child blocks generated by the decoder. In order to start the decoder you have to add it to the list of decoders for the block(s) you want to register your decoder for.

ParameterDescription     
strNameThe unique name identifies the decoder. This is the name you will see in the GSEOS Explorer.     
fDecoderYour decoder function. It takes one parameter which is the block that triggers the decoder (if you register the decoder for more than one block you can use this parameter to determine the source block). If this function throws an exception the decoder is terminated.  
ctChildBlocks The data blocks your decoder is going to generated. List all blocks your decoder may generate. Given this information the decoder hierarchy can be examined with the GSEOS Exporer.      

Returns
The new decoder object.

Comments
In order for the decoder to be useful you have to hook it on the arrival of a block. You do this by adding it to the list of decoders for the block you are interested in. See the example below.

Exceptions
TypeErrorThe decoder name has to be a string.     
DecoderErrorThe fDecoder parameter has to be a callable object. The child list contains invalid blocks.     

Example
The following example defines a decoder function that simply converts the input data and generates one output block for every input block. It then sets the arrival hook for the input block.

#
# Simple conversion decoder
#
def fDec(oInputBlock):
  for i in range(len(oInputBlock.Data)):
    OutBlock.Data[i] = oInputBlock.Data[i] * 23
    OutBlock.send()


#
# Hook the decoder to the input block
#
oMyDec = GseosDecoder.TDecoder('Convert', fDec, [OutBlock])
InputBlock.Decoders.append(oMyDec)