java对象序列化格式

stream:

     magic version contents

magic:

     STREAM_MAGIC

version:

     STREAM_VERSION

contents:

      content
      contents content

content:

     object
     blockdata

object:

     newObject
     newClass
     newArray
     newString
     newClassDesc
     prevObject
     nullReference
     exception
     reset

newClass:

     TC_CLASS classDesc newHandle

classDesc:

     newClassDesc
     nullReference
     (ClassDesc)prevObject // an object required to be of type ClassDesc

newClassDesc:

     TC_CLASSDESC className serialVersionUID newHandle classDescInfo

     TC_PROXYCLASSDESC newHandle proxyClassDescInfo

className:

     (utf)

serialVersionUID:

    (long)

newHandle: //The next number in sequence is assigned to the object being serialized or deserialized

classDescInfo:

      classDescFlags fields classAnnotation superClassDesc

proxyClassDescInfo:
     (int)<count>proxyInterfaceName[count] classAnnotation
     superClassDesc

proxyInterfaceName:
     (utf)

classDescFlags:

     (byte) // Defined in Terminal Symbols and Constants

fields:

     (short)<count> fieldDesc[count]

fieldDesc:

     primitiveDesc
     objectDesc

primitiveDesc:

     prim_typecode fieldName

objectDesc:

     obj_typecode fieldName className1

fieldName:

     (utf)

className1:

     (String)object // String containing the field’s type

superClassDesc:

     classDesc

classAnnotation:

     endBlockData
     contents endBlockData // contents written by annotateClass

prim_typecode:

     `B' // byte
     `C' // char
     `D' // double
     `F' // float
     `I' // int
     `J' // long
     `S' // short
     `Z' // boolean

obj_typecode:

     `[` // array
     `L' // object

newArray:

     TC_ARRAY classDesc newHandle (int)<size> values[size]

values: //The size and types are described by the classDesc for the current object

newObject:

     TC_OBJECT classDesc newHandle classdata[] // data for each class

classdata:

     nowrclass // SC_SERIALIZABLE & classDescFlag && !(SC_WRITE_METHOD & classDescFlags)
     wrclass objectAnnotation // SC_SERIALIZABLE & classDescFlag && SC_WRITE_METHOD &
classDescFlags
     externalContents // SC_EXTERNALIZABLE & classDescFlag && !(SC_BLOCKDATA &
classDescFlags
     objectAnnotation // SC_EXTERNALIZABLE & classDescFlag&& SC_BLOCKDATA & classDescFlags

nowrclass:

     values // fields in order of class descriptor

wrclass:

     nowrclass

objectAnnotation:

     endBlockData
     contents endBlockData // contents written by writeObject or writeExternal PROTOCOL_VERSION_2

externalContents: // externalContent written by

     externalContent // writeExternal in PROTOCOL_VERSION_1
     externalContents externalContent

externalContent: // Only parseable by readExternal

     (bytes)object

blockdata:

    blockdatashort
    blockdatalong

blockdatashort:

     TC_BLOCKDATA (unsigned byte)<size> (byte)[size]

blockdatalong:

     TC_BLOCKDATALONG (int)<size> (byte)[size]

endBlockData:

     TC_ENDBLOCKDATA

newString:

     TC_STRING newHandle (utf)

prevObject:

     TC_REFERENCE (int)handle

nullReference:

     TC_NULL

exception:

     TC_EXCEPTION reset(Throwable) object reset

reset: // The set of known objects is discarded so the objects of the exception do not overlap with the previously sent objects or with objects that may be sent after the exception

你可能感兴趣的:(java对象序列化)