code: def Serialize(self, writer):
          
          writer.WriteByte(self.Usage)
  
          if isinstance(self.Data, UIntBase):
              self.Data = self.Data.Data
  
          length = len(self.Data)
  
          if length > self.MAX_ATTR_DATA_SIZE:
              raise Exception("Invalid transaction attribute")
  
          if self.Usage == TransactionAttributeUsage.ContractHash or self.Usage == TransactionAttributeUsage.Vote or \
                  (self.Usage >= TransactionAttributeUsage.Hash1 and self.Usage <= TransactionAttributeUsage.Hash15):
              writer.WriteBytes(self.Data)
  
          elif self.Usage == TransactionAttributeUsage.ECDH02 or self.Usage == TransactionAttributeUsage.ECDH03:
              writer.WriteBytes(self.Data[1:33])
  
          elif self.Usage == TransactionAttributeUsage.Script:
              writer.WriteBytes(self.Data)
  
          elif self.Usage == TransactionAttributeUsage.DescriptionUrl:
              writer.WriteVarString(self.Data)
  
          elif self.Usage == TransactionAttributeUsage.Description or self.Usage >= TransactionAttributeUsage.Remark:
              writer.WriteVarString(self.Data)
          else:
              logger.error("format error!!!")
docs: Serialize object.
  
          Args:
              writer (neo.IO.BinaryWriter):
  
          Raises:
              Exception: if the length exceeds the maximum allowed number of attributes in a transaction.