Encode the given object into a series of statements and expressions.
<p>
The implementation simply finds the <code>PersistenceDelegate</code> responsible for the object's class, and delegate the call to it.
</p>

@param o
the object to encode
843
protected void writeObject(Object o)
	{
		if (o == null)
		{
			return;
		}
		getPersistenceDelegate(o.getClass()).writeObject(o, this);
	}
1104835
@Override
    public void encode(IoSession session, Object message,
            ProtocolEncoderOutput out) throws Exception {
        out.write(message);
    }
71388
public static byte[] save(Object o) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        save(o, baos);
        return baos.toByteArray();
    }
843530
@Override
    public void encodeTo(FLEncoder enc) {
        final Encoder encoder = new Encoder(enc);
        internalDict.encodeTo(encoder);
        encoder.release();
    }
1025843
public void writeObject (Object object)
        throws IOException
    {
        // if the object to be written is null, simply write a zero
        if (object == null) {
            writeShort(0);
            return;
        }

        // otherwise, write the class mapping, then the bare object
        Class<?> sclass = Streamer.getStreamerClass(object);
        ClassMapping cmap = writeClassMapping(sclass);
        writeBareObject(object, cmap.streamer, true);
    }
1280293
@Override
  public byte[] encode(final NSMessage<T> obj) {
    if (isStreamingCodec) {
      final StreamingCodec<T> streamingCodec = (StreamingCodec<T>) codec;
      try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        try (DataOutputStream daos = new DataOutputStream(baos)) {
          daos.writeUTF(obj.getSrcId().toString());
          daos.writeUTF(obj.getDestId().toString());
          daos.writeInt(obj.getData().size());
          for (final T rec : obj.getData()) {
            streamingCodec.encodeToStream(rec, daos);
          }
        }
        return baos.toByteArray();
      } catch (final IOException e) {
        throw new RuntimeException("IOException", e);
      }
    } else {
      final NSMessagePBuf.Builder pbuf = NSMessagePBuf.newBuilder();
      pbuf.setSrcid(obj.getSrcId().toString());
      pbuf.setDestid(obj.getDestId().toString());
      for (final T rec : obj.getData()) {
        final NSRecordPBuf.Builder rbuf = NSRecordPBuf.newBuilder();
        rbuf.setData(ByteString.copyFrom(codec.encode(rec)));
        pbuf.addMsgs(rbuf);
      }
      return pbuf.build().toByteArray();
    }
  }
126445
@Override
    public void writeObject(DataOutputStream dataOutputStream) throws ObjectManagerException, IOException
    {
        super.writeObject(dataOutputStream);

        // Write out our serialVersionUID
        dataOutputStream.writeLong(serialVersionUID);

        dataOutputStream.writeLong(_uniqueID);
        dataOutputStream.writeLong(_streamID);
        dataOutputStream.writeLong(_lockID);
        dataOutputStream.writeLong(_referredID);
        dataOutputStream.writeLong(_sequence);
        dataOutputStream.writeLong(_expiryTime);
        dataOutputStream.writeInt(_redeliveredCount);
        dataOutputStream.writeInt(_storageStrategy);
        dataOutputStream.writeInt(_priority);
        dataOutputStream.writeInt(_persistentSize);
        dataOutputStream.writeInt(_maxDepth);

        dataOutputStream.writeBoolean(_canExpireSilently);
        dataOutputStream.writeBoolean(_containsExpirables);

        // If the string variables aren't null then
        // write the flag and then write them to the
        // stream.
        if (_type != null)
        {
            dataOutputStream.writeBoolean(true);
            dataOutputStream.writeUTF(_type);
        }
        else
        {
            dataOutputStream.writeBoolean(false);
        }
        if (_className != null)
        {
            dataOutputStream.writeBoolean(true);
            dataOutputStream.writeUTF(_className);
        }
        else
        {
            dataOutputStream.writeBoolean(false);
        }

        // We need to write out the length of the tran ID
        // before we write the bytes so that we can read
        // it back in successfully
        if (_transactionId != null)
        {
            dataOutputStream.writeInt(_transactionId.length);
            dataOutputStream.write(_transactionId, 0, _transactionId.length);
        }
        else
        {
            dataOutputStream.writeInt(-1);
        }

        // Call the Tokens to write themselves out but
        // only if they exist. If the don't then we need
        // to write a boolean to the stream so that we
        // don't try and read back in non-existent tokens.
        if (_streamListToken != null)
        {
            dataOutputStream.writeBoolean(true);
            _streamListToken.writeObject(dataOutputStream);
        }
        else
        {
            dataOutputStream.writeBoolean(false);
        }

        if (_itemListToken != null)
        {
            dataOutputStream.writeBoolean(true);
            _itemListToken.writeObject(dataOutputStream);
        }
        else
        {
            dataOutputStream.writeBoolean(false);
        }

        if (_rawDataToken != null)
        {
            dataOutputStream.writeBoolean(true);
            _rawDataToken.writeObject(dataOutputStream);
        }
        else
        {
            dataOutputStream.writeBoolean(false);
        }

        if (_streamListEntryToken != null)
        {
            dataOutputStream.writeBoolean(true);
            _streamListEntryToken.writeObject(dataOutputStream);
        }
        else
        {
            dataOutputStream.writeBoolean(false);
        }

        if (_itemListEntryToken != null)
        {
            dataOutputStream.writeBoolean(true);
            _itemListEntryToken.writeObject(dataOutputStream);
        }
        else
        {
            dataOutputStream.writeBoolean(false);
        }

        // write the _deliveryDelayTime
        dataOutputStream.writeLong(_deliveryDelayTime);

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            SibTr.debug(this, tc, "bytes written==" + dataOutputStream.size());
    }
676510
public void writeObject(Object oldInstance, Encoder out)
    {
        // Override the default FieldPersistence algorithm for the encoder, so private fields
        // can also be encoded
        out.setPersistenceDelegate(Field.class, new FieldPersistenceDelegate());
        super.writeObject(oldInstance, out);
    }
849084
public void encode(AsnOutputStream aos) throws EncodeException {

        if (this.nationalOperationCode == null && this.privateOperationCode == null)
            throw new EncodeException("Operation code: No Operation code set!");

        try {
            if (this.type == OperationCodeType.National && this.nationalOperationCode != null) {
                aos.writeInteger(Tag.CLASS_PRIVATE, OperationCode._TAG_NATIONAL, this.nationalOperationCode);
            } else if (this.type == OperationCodeType.Private && this.privateOperationCode != null) {
                aos.writeInteger(Tag.CLASS_PRIVATE, OperationCode._TAG_PRIVATE, this.privateOperationCode);
            } else {
                throw new EncodeException("Operation code: No Operation code set!");
            }

        } catch (IOException e) {
            throw new EncodeException("IOException while encoding OperationCode: " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new EncodeException("AsnException while encoding OperationCode: " + e.getMessage(), e);
        }
    }
579945
public static byte[] serialize(final Object o, final boolean zip) throws IOException {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OutputStream os = baos;
        ObjectOutputStream oos = null;
        try {
            if (zip) {
                os = new GZIPOutputStream(os);
            }
            oos = new ObjectOutputStream(os);
            oos.writeObject(o);
            oos.flush();
        } finally {
            if (oos != null) {
                oos.close();
            }
            os.close();
        }

        return baos.toByteArray();
    }
65325
public void encode(AsnOutputStream aos) throws EncodeException {

        // commented code is the whole case encoding implementation
        // now only one version is supported - we use for optimization purpose simple encoding
        // aos.writeBitString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_PROTOCOL_VERSION, _VALUE);
        aos.write(128);
        aos.write(2);
        aos.write(7);
        aos.write(128);

        // BitSetStrictLength bs = new BitSetStrictLength(1);
        // bs.set(0);
        // try {
        // aos.writeBitString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_PROTOCOL_VERSION, bs);
        // } catch (AsnException e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
        // } catch (IOException e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
        // }
    }
1067024
void encodeProperty(ByteArrayOutputStream baos, Object value) throws JMSException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "encodeProperty", new Object[]{baos, value});

    // The value should be a non-null String
    if (value instanceof String) {
      super.encodeProperty(baos, STAR_STRING + (String)value);     // The value has to have '*' preprended
    }

    // If it is not a String, something has gone horribly wrong
    else {
      throw (JMSException)JmsErrorUtils.newThrowable(JMSException.class
                                                    ,"INTERNAL_ERROR_CWSIA0362"
                                                    ,new Object[] {"StringPropertyCoder.encodeProperty#1", longName, value}
                                                    ,null
                                                    ,"StringPropertyCoder.encodeProperty#1"
                                                    ,null
                                                    ,tc);
    }
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "encodeProperty");
  }
87265
@SuppressWarnings("unchecked")
    public static <E> void serialize(E object, OutputStream os) throws IOException {
        mapperFor((Class<E>)object.getClass()).serialize(object, os);
    }
961730
public void writeObject(Object o) throws IOException {
        ObjectOutputStream oos = AnonymousClassWarnings.checkingObjectOutputStream(out);
        oos.writeObject(o);
        // don't close oss, which will close the underlying stream
        // no need to flush either, given the way oos is implemented
    }
93242
public static void writeObject(CodedOutputStream out, int order, FieldType type, Object o, boolean list,
            boolean withTag) throws IOException {
        if (o == null) {
            return;
        }

        if (type == FieldType.OBJECT) {

            Class cls = o.getClass();
            Codec target = ProtobufProxy.create(cls);

            if (withTag) {
                out.writeRawVarint32(makeTag(order, WireFormat.WIRETYPE_LENGTH_DELIMITED));
            }
            out.writeRawVarint32(target.size(o));

            target.writeTo(o, out);
            return;
        }

        if (type == FieldType.BOOL) {
            if (withTag) {
                out.writeBool(order, (Boolean) o);
            } else {
                out.writeBoolNoTag((Boolean) o);
            }
        } else if (type == FieldType.BYTES) {
            byte[] bb = (byte[]) o;
            if (withTag) {
                out.writeBytes(order, ByteString.copyFrom(bb));
            } else {
                out.writeBytesNoTag(ByteString.copyFrom(bb));
            }
        } else if (type == FieldType.DOUBLE) {
            if (withTag) {
                out.writeDouble(order, (Double) o);
            } else {
                out.writeDoubleNoTag((Double) o);
            }
        } else if (type == FieldType.FIXED32) {
            if (withTag) {
                out.writeFixed32(order, (Integer) o);
            } else {
                out.writeFixed32NoTag((Integer) o);
            }
        } else if (type == FieldType.FIXED64) {
            if (withTag) {
                out.writeFixed64(order, (Long) o);
            } else {
                out.writeFixed64NoTag((Long) o);
            }
        } else if (type == FieldType.FLOAT) {
            if (withTag) {
                out.writeFloat(order, (Float) o);
            } else {
                out.writeFloatNoTag((Float) o);
            }
        } else if (type == FieldType.INT32) {
            if (withTag) {
                out.writeInt32(order, (Integer) o);
            } else {
                out.writeInt32NoTag((Integer) o);
            }
        } else if (type == FieldType.INT64) {
            if (withTag) {
                out.writeInt64(order, (Long) o);
            } else {
                out.writeInt64NoTag((Long) o);
            }
        } else if (type == FieldType.SFIXED32) {
            if (withTag) {
                out.writeSFixed32(order, (Integer) o);
            } else {
                out.writeSFixed32NoTag((Integer) o);
            }
        } else if (type == FieldType.SFIXED64) {
            if (withTag) {
                out.writeSFixed64(order, (Long) o);
            } else {
                out.writeSFixed64NoTag((Long) o);
            }
        } else if (type == FieldType.SINT32) {
            if (withTag) {
                out.writeSInt32(order, (Integer) o);
            } else {
                out.writeSInt32NoTag((Integer) o);
            }
        } else if (type == FieldType.SINT64) {
            if (withTag) {
                out.writeSInt64(order, (Long) o);
            } else {
                out.writeSInt64NoTag((Long) o);
            }
        } else if (type == FieldType.STRING) {
            if (withTag) {
                out.writeBytes(order, ByteString.copyFromUtf8(String.valueOf(o)));
            } else {
                out.writeBytesNoTag(ByteString.copyFromUtf8(String.valueOf(o)));
            }
        } else if (type == FieldType.UINT32) {
            if (withTag) {
                out.writeUInt32(order, (Integer) o);
            } else {
                out.writeUInt32NoTag((Integer) o);
            }
        } else if (type == FieldType.UINT64) {
            if (withTag) {
                out.writeUInt64(order, (Long) o);
            } else {
                out.writeUInt64NoTag((Long) o);
            }
        } else if (type == FieldType.ENUM) {
            int value = 0;
            if (o instanceof EnumReadable) {
                value = ((EnumReadable) o).value();
            } else if (o instanceof Enum) {
                value = ((Enum) o).ordinal();
            }
            if (withTag) {
                out.writeEnum(order, value);

            } else {
                out.writeEnumNoTag(value);
            }
        }
    }
346189
public void encodeSelf(ObjectOutput buf) throws IOException {
    super.encodeSelf(buf); // encode the opcode and operand
    buf.writeBoolean(escaped);
    if (escaped)
      buf.writeChar(escape);
  }
611888
void encodeProperty(ByteArrayOutputStream baos, Object value) throws JMSException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "encodeProperty", new Object[]{baos, value});

    if (value.equals(ApiJmsConstants.ON)) {
      super.encodeProperty(baos, SHORT_ON);
    }
    else {
      super.encodeProperty(baos, SHORT_OFF);
    }

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "encodeProperty");
  }