Package dev.relism.flash.template
Class ByteTemplate
java.lang.Object
dev.relism.flash.template.ByteTemplate
Precompiled, allocation-minimal byte template.
Placeholders of the form {{name}} are detected once at construction.
Each render(java.lang.String...) call makes exactly one allocation: the output byte[]
(plus one byte[] per distinct key-value pair, for its UTF-8 bytes).
Layout: seg[0] slot[0] seg[1] slot[1] … seg[n-1] slot[n-1] seg[n]
A slot name can appear more than once (e.g. {{var}} == {{var}}), so the map built at
construction maps each name to the (usually single-element) array of every slot index using
that name, instead of the nested "scan every slot for every pair" loop this used to do.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Render with alternating key-value String pairs:k1, v1, k2, v2, …Unmatched slots are rendered as empty.intrenderInto(byte[] buffer, int offset, String... kvPairs) Renders intobufferstarting atoffset, making no allocation beyond the per-pair UTF-8 conversion ofkvPairs' values.
-
Constructor Details
-
ByteTemplate
-
-
Method Details
-
render
Render with alternating key-value String pairs:k1, v1, k2, v2, …Unmatched slots are rendered as empty. Allocates the returnedbyte[]; for a caller-supplied buffer seerenderInto(byte[], int, String...). -
renderInto
Renders intobufferstarting atoffset, making no allocation beyond the per-pair UTF-8 conversion ofkvPairs' values. Returns the number of bytes written.- Throws:
IndexOutOfBoundsException- ifbufferdoes not have enough room fromoffset
-