code: def encode(self, pdu):
          
          # check for special encoding
          if (self.tagClass == Tag.contextTagClass):
              data = 0x08
          elif (self.tagClass == Tag.openingTagClass):
              data = 0x0E
          elif (self.tagClass == Tag.closingTagClass):
              data = 0x0F
          else:
              data = 0x00
  
          # encode the tag number part
          if (self.tagNumber < 15):
              data += (self.tagNumber << 4)
          else:
              data += 0xF0
  
          # encode the length/value/type part
          if (self.tagLVT < 5):
              data += self.tagLVT
          else:
              data += 0x05
  
          # save this and the extended tag value
          pdu.put( data )
          if (self.tagNumber >= 15):
              pdu.put(self.tagNumber)
  
          # really short lengths are already done
          if (self.tagLVT >= 5):
              if (self.tagLVT <= 253):
                  pdu.put( self.tagLVT )
              elif (self.tagLVT <= 65535):
                  pdu.put( 254 )
                  pdu.put_short( self.tagLVT )
              else:
                  pdu.put( 255 )
                  pdu.put_long( self.tagLVT )
  
          # now put the data
          pdu.put_data(self.tagData)
docs: Encode a tag on the end of the PDU.