code: def writeReference(self, o):
          
          idx = self.context.getObjectReference(o)
  
          if idx == -1 or idx > 65535:
              return -1
  
          self.writeType(TYPE_REFERENCE)
          self.stream.write_ushort(idx)
  
          return idx
docs: Write reference to the data stream.
  
          @param o: The reference data to be encoded to the AMF0 datastream.