Class PofBufferWriter.UserTypeWriter

  • All Implemented Interfaces:
    PofConstants, PofWriter
    Enclosing class:
    PofBufferWriter

    public static class PofBufferWriter.UserTypeWriter
    extends PofBufferWriter
    The UserTypeWriter implementation is a contextually-aware PofWriter whose purpose is to write the properties of a value of a specified user type. The "contextual awareness" refers to the fact that the UserTypeWriter maintains state about the type identifier, the PofWriter's property index position within the user type value, and a PofContext that may differ from the PofContext that provided the PofSerializer which is using this UserTypeWriter to serialize a user type.
    • Field Detail

      • m_nTypeId

        protected int m_nTypeId
        The type identifier of the user type that is being written.
      • m_nVersionId

        protected int m_nVersionId
        The version identifier of the user type that is being written.
      • m_iProp

        protected int m_iProp
        The index of the user type being written.
      • m_nId

        protected int m_nId
        The identity of the object to encode, or -1 if the identity shouldn't be encoded in the POF stream
      • m_iPrevProp

        protected int m_iPrevProp
        The index of the last property written to the POF stream or -1 if the first property has yet to be written.
      • m_fUserTypeBegin

        protected boolean m_fUserTypeBegin
        True iff the type and version identifier of the user type was written to the POF stream.
      • m_fUserTypeEnd

        protected boolean m_fUserTypeEnd
        True iff the user type was written to the POF stream.
      • m_complex

        protected WritingPofHandler.Complex m_complex
        The Complex value that corresponds to the user type that is being written.
    • Constructor Detail

      • UserTypeWriter

        public UserTypeWriter​(WriteBuffer.BufferOutput out,
                              PofContext ctx,
                              int nTypeId,
                              int iProp)
        Construct a UserTypeWriter for writing the property values of a user type.
        Parameters:
        out - the BufferOutput object to write to; must not be null
        ctx - the PofContext to use for writing the user type property values within the user type that this writer will be writing
        nTypeId - the type identifier of the user type; must be non-negative
        iProp - the index of the user type being written
      • UserTypeWriter

        public UserTypeWriter​(PofBufferWriter parent,
                              WriteBuffer.BufferOutput out,
                              PofContext ctx,
                              int nTypeId,
                              int iProp)
        Construct a UserTypeWriter for writing the property values of a user type.
        Parameters:
        parent - the containing PofBufferWriter
        out - the BufferOutput object to write to; must not be null
        ctx - the PofContext to use for writing the user type property values within the user type that this writer will be writing
        nTypeId - the type identifier of the user type; must be non-negative
        iProp - the index of the user type being written
      • UserTypeWriter

        public UserTypeWriter​(WritingPofHandler handler,
                              PofContext ctx,
                              int nTypeId,
                              int iProp)
        Construct a UserTypeWriter for writing the property values of a user type.
        Parameters:
        handler - the WritingPofHandler used to write user type data (except for the user type id itself, which is passed as a constructor argument)
        ctx - the PofContext to use for writing the user type property values within the user type that this writer will be writing
        nTypeId - the type identifier of the user type; must be non-negative
        iProp - the index of the user type being written
      • UserTypeWriter

        public UserTypeWriter​(PofBufferWriter parent,
                              WritingPofHandler handler,
                              PofContext ctx,
                              int nTypeId,
                              int iProp)
        Construct a UserTypeWriter for writing the property values of a user type.
        Parameters:
        parent - the containing PofBufferWriter
        handler - the WritingPofHandler used to write user type data (except for the user type id itself, which is passed as a constructor argument)
        ctx - the PofContext to use for writing the user type property values within the user type that this writer will be writing
        nTypeId - the type identifier of the user type; must be non-negative
        iProp - the index of the user type being written
      • UserTypeWriter

        public UserTypeWriter​(PofBufferWriter parent,
                              WritingPofHandler handler,
                              PofContext ctx,
                              int nTypeId,
                              int iProp,
                              int nId)
        Construct a UserTypeWriter for writing the property values of a user type.
        Parameters:
        parent - the containing PofBufferWriter
        handler - the WritingPofHandler used to write user type data (except for the user type id itself, which is passed as a constructor argument)
        ctx - the PofContext to use for writing the user type property values within the user type that this writer will be writing
        nTypeId - the type identifier of the user type; must be non-negative
        iProp - the index of the user type being written
        nId - the identity of the object to encode, or -1 if the identity shouldn't be encoded in the POF stream
    • Method Detail

      • getUserTypeId

        public int getUserTypeId()
        Determine the user type that is currently being written.
        Specified by:
        getUserTypeId in interface PofWriter
        Overrides:
        getUserTypeId in class PofBufferWriter
        Returns:
        the user type identifier, or -1 if the PofWriter is not currently writing a user type
      • getVersionId

        public int getVersionId()
        Determine the version identifier of the user type that is currently being written.
        Specified by:
        getVersionId in interface PofWriter
        Overrides:
        getVersionId in class PofBufferWriter
        Returns:
        the integer version ID of the user type; always non-negative
      • setVersionId

        public void setVersionId​(int nVersionId)
        Set the version identifier of the user type that is currently being written.
        Specified by:
        setVersionId in interface PofWriter
        Overrides:
        setVersionId in class PofBufferWriter
        Parameters:
        nVersionId - the user type identifier; must be non-negative
      • createNestedPofWriter

        public PofWriter createNestedPofWriter​(int iProp)
                                        throws IOException
        Obtain a PofWriter that can be used to write a set of properties into a single property of the current user type. The returned PofWriter is only valid from the time that it is returned until the next call is made to this PofWriter.
        Specified by:
        createNestedPofWriter in interface PofWriter
        Overrides:
        createNestedPofWriter in class PofBufferWriter
        Parameters:
        iProp - the property index
        Returns:
        a PofWriter whose contents are nested into a single property of this PofWriter
        Throws:
        IOException - if an I/O error occurs
      • createNestedPofWriter

        public PofWriter createNestedPofWriter​(int iProp,
                                               int nTypeId)
                                        throws IOException
        Obtain a PofWriter that can be used to write a set of properties into a single property of the current user type. The returned PofWriter is only valid from the time that it is returned until the next call is made to this PofWriter.
        Specified by:
        createNestedPofWriter in interface PofWriter
        Overrides:
        createNestedPofWriter in class PofBufferWriter
        Parameters:
        iProp - the property index
        nTypeId - the type identifier of the nested property
        Returns:
        a PofWriter whose contents are nested into a single property of this PofWriter
        Throws:
        IOException - if an I/O error occurs
      • writeRemainder

        public void writeRemainder​(Binary binProps)
                            throws IOException
        Write the remaining properties to the POF stream, terminating the writing of the current user type. As part of writing out a user type, this method must be called by the PofSerializer that is writing out the user type, or the POF stream will be corrupted.

        Calling this method terminates the current user type by writing a -1 to the POF stream after the last indexed property. Subsequent calls to the various writeXYZ methods of this interface will fail after this method is called.

        Specified by:
        writeRemainder in interface PofWriter
        Overrides:
        writeRemainder in class PofBufferWriter
        Parameters:
        binProps - a Binary object containing zero or more indexed properties in binary POF encoded form; may be null
        Throws:
        IOException - if an I/O error occurs
      • getParentWriter

        protected PofBufferWriter getParentWriter()
        If this writer is contextually within a user type, obtain the writer which created this writer in order to write the user type.
        Overrides:
        getParentWriter in class PofBufferWriter
        Returns:
        the containing writer
      • beginProperty

        protected void beginProperty​(int iProp)
                              throws IOException
        Report that a POF property is about to be written to the POF stream.

        This method call will be followed by one or more separate calls to a "write" method and the property extent will then be terminated by a call to PofBufferWriter.endProperty(int).

        Overrides:
        beginProperty in class PofBufferWriter
        Parameters:
        iProp - the index of the property being written
        Throws:
        IOException - if an I/O error occurs
      • endProperty

        protected void endProperty​(int iProp)
        Signifies the termination of the current POF property.
        Overrides:
        endProperty in class PofBufferWriter
        Parameters:
        iProp - the index of the current property
      • closeNested

        protected void closeNested()
        Notify the UserTypeWriter that it is being "closed". This notification allows the UserTypeWriter to write any remaining data that it has pending to write.
      • onException

        protected void onException​(Exception e)
                            throws IOException
        Called when an unexpected exception is caught while writing to the POF stream.

        If the given exception wraps an IOException, the IOException is unwrapped and rethrown; otherwise the given exception is rethrown.

        Overrides:
        onException in class PofBufferWriter
        Parameters:
        e - the exception
        Throws:
        IOException - the wrapped IOException, if the given exception is a wrapped IOException
      • writeUserTypeInfo

        protected void writeUserTypeInfo()
                                  throws IOException
        Write out the type and version identifiers of the user type to the POF stream, if they haven't already been written.
        Throws:
        IOException - on I/O error
      • enableReference

        public void enableReference()
        Ensure that reference support (necessary for cyclic dependencies) is enabled.
        Overrides:
        enableReference in class PofBufferWriter
      • isEvolvable

        protected boolean isEvolvable()
        Determine if the object to be written is either Evolvable or part of an Evolvable object.
        Overrides:
        isEvolvable in class PofBufferWriter
        Returns:
        true iff the object to be written is Evolvable