Skip to content
@skiffyard/javaser

javaser cheatsheet

Every export of @skiffyard/javaser. Guides are listed in the introduction.

jennifer
import "@skiffyard/javaser/" as javaser;

Every failure is Error{kind: "javaser"}, except a reached cap (Options.maxNodes, Options.maxDepth), which is kind "limit". An s argument is a Stream; an n argument is a node number. Node 0 is null.

Constants

ConstantValueMeaning
DEFAULT_MAX_NODES2000000Options.maxNodes in defaults()
DEFAULT_MAX_DEPTH100000Options.maxDepth in defaults()
DUMP_PREVIEW8array elements and block bytes dump shows
SC_WRITE_METHOD0x01class flag: has writeObject, custom data follows its fields
SC_SERIALIZABLE0x02class flag: Serializable
SC_EXTERNALIZABLE0x04class flag: Externalizable, its data is custom only
SC_BLOCK_DATA0x08class flag: externalizable data in block data (protocol 2)
SC_ENUM0x10class flag: an enum

Decoding

FunctionReturnsDoes
decode(data)Streamdecode a stream starting at the first byte, with defaults()
decodeWith(data, opts)Streamdecode with an offset and caps
defaults()Optionsoffset 0, DEFAULT_MAX_NODES, DEFAULT_MAX_DEPTH
locate(data)intoffset of the first AC ED 00 05, -1 when there is none
FunctionReturnsDoes
contents(s)list of intthe top-level values in write order
nodeCount(s)intthe number of nodes, node 0 included
typeOf(s, n)stringnull object array string enum class classdesc block, or a primitive type name
className(s, n)stringthe Java™ class name; "" for nodes without one
classChain(s, n)list of stringthe serializable classes, superclass first
serialVersionUid(s, n)intthe class's serialVersionUID
interfaces(s, n)list of stringa dynamic proxy's interfaces
fieldNames(s, n)list of stringserializable fields, superclass first; shadowed names repeat
has(s, n, name)boolwhether the object has the field
field(s, n, name)inta field's value; the most derived class's when shadowed
fieldOf(s, n, cls, name)inta field as one class of the chain declares it
custom(s, n)list of intwhat writeObject / writeExternal wrote: blocks and objects
customOf(s, n, cls)list of intthe custom data of one class of the chain
elements(s, n)list of intan object array's elements
objectsOf(s, cls)list of intevery object of a class, in stream order

Values

FunctionReturnsDoes
asInt(s, n)inta byte, short, int, long, or a char's code unit
asFloat(s, n)floata finite float or double
isFinite(s, n)boolwhether a float / double is neither NaN nor infinite
floatBits(s, n)intthe IEEE 754 bits of a float / double
asBool(s, n)boola boolean
asString(s, n)stringa string, an enum constant's name, a char
asBytes(s, n)bytesa block's bytes (big-endian primitives) or a byte[]
length(s, n)intan array's elements, a string's runes, a block's bytes
elementType(s, n)stringan array's element type: a primitive name, object or array
ints(s, n)list of inta byte[] short[] int[] long[] char[] boolean[]
floats(s, n)list of floata float[] / double[] without NaN or infinities
floatArrayBits(s, n)list of intthe IEEE 754 bits of each float[] / double[] element

Dumping

FunctionReturnsDoes
dump(s)stringthe stream as an indented tree, one value per line
dumpWith(s, preview)stringthe same, showing preview array elements and block bytes

Types

Options

FieldMeaning
offset as intwhere the stream starts in the bytes; locate finds it behind a header
maxNodes as intthe most nodes the stream may produce; more is kind "limit"
maxDepth as intthe deepest nesting of objects and arrays; deeper is kind "limit"

Stream

The tables behind the accessors, one entry per node (lists indexed by node number) or per class (indexed by class number). Prefer the accessors; the layout is plain lists so a Stream is not rebuilt when passed to the deck.

FieldMeaning
data as bytesthe bytes decoded
offset as intwhere the stream starts in data
kinds as list of inteach node's kind, an index into the typeOf names
classOf as list of inteach node's class number, -1 for none
ints as list of inta primitive value, a float's bits, an array length, a block's byte count
floats as list of floata finite float / double value, else 0.0
texts as list of stringa string, an enum constant, a char
at as list of inta primitive array's first element in data, -1 otherwise
segments as map of int to list of inta block's pieces in data, offset / length pairs
children as list of list of inteach node's children: fields, custom data, elements
names as list of list of stringeach child's field name, "" for custom data and elements
owners as list of list of inteach child's class number, -1 for array elements
classNames as list of stringeach class's name, $Proxy for a proxy class
classUids as list of inteach class's serialVersionUID
classFlags as list of inteach class's SC_* flags
classSupers as list of inteach class's superclass, -1 for none
classFieldNames as list of list of stringeach class's serializable fields, in stream order
classFieldTypes as list of list of stringeach field's type code: B C D F I J S Z, L object, [ array
classFieldClasses as list of list of stringeach object field's declared type, "" for primitives
classInterfaces as list of list of stringa proxy class's interfaces
top as list of intthe top-level nodes