BrushFamilyExtensions

Added in 1.0.0

public final class BrushFamilyExtensions


Summary

Public methods

static final @NonNull BrushFamily
@Throws(exceptionClasses = [IOException])
decode(
    @NonNull BrushFamily.Companion receiver,
    @NonNull byte[] input,
    @NonNull Version maxVersion,
    OnDecodeTexturePngBytes onDecodeTexture
)

Read a serialized BrushFamily from the given ByteArray and parse it into a BrushFamily, throwing an exception if parsing or validation was not successful.

static final @NonNull BrushFamily
decode(
    @NonNull BrushFamily.Companion receiver,
    @NonNull InputStream input,
    @NonNull Version maxVersion,
    OnDecodeTexturePngBytes onDecodeTexture
)

Read a serialized BrushFamily from the given InputStream and parse it into a BrushFamily, throwing an exception if parsing or validation was not successful.

static final @NonNull List<@NonNull BrushFamily>
@ExperimentalInkBrushCompatibilityApi
@Throws(exceptionClasses = [IOException])
decodeMultiple(
    @NonNull BrushFamily.Companion receiver,
    @NonNull byte[] input,
    @NonNull Version maxVersion,
    OnDecodeTexturePngBytes onDecodeTexture
)

Read a serialized BrushFamily from the given ByteArray and parse it into a List of BrushFamilys, throwing an exception if parsing or validation was not successful.

static final @NonNull List<@NonNull BrushFamily>
@ExperimentalInkBrushCompatibilityApi
decodeMultiple(
    @NonNull BrushFamily.Companion receiver,
    @NonNull InputStream input,
    @NonNull Version maxVersion,
    OnDecodeTexturePngBytes onDecodeTexture
)

Read a serialized BrushFamily from the given InputStream and parse it into a List of BrushFamilys, throwing an exception if parsing or validation was not successful.

static final @NonNull byte[]
encode(
    @NonNull BrushFamily receiver,
    TexturePngBytesLookup textureIdToPngBytes
)

Write a gzip-compressed ink.proto.BrushFamily binary proto message representing the BrushFamily to the given ByteArray using the provided callback to retrieve texture PNG bytes.

static final void
encode(
    @NonNull BrushFamily receiver,
    @NonNull OutputStream output,
    TexturePngBytesLookup textureIdToPngBytes
)

Write a gzip-compressed serialized ink.proto.BrushFamily proto message representing the BrushFamily to the given OutputStream.

static final @NonNull byte[]

Write a gzip-compressed serialized ink.proto.BrushFamily proto message representing the List of BrushFamilys to the given ByteArray.

static final void

Write a gzip-compressed serialized ink.proto.BrushFamily proto message representing the List of BrushFamilys to the given OutputStream.

Public methods

@Throws(exceptionClasses = [IOException])
public static final @NonNull BrushFamily decode(
    @NonNull BrushFamily.Companion receiver,
    @NonNull byte[] input,
    @NonNull Version maxVersion,
    OnDecodeTexturePngBytes onDecodeTexture
)

Read a serialized BrushFamily from the given ByteArray and parse it into a BrushFamily, throwing an exception if parsing or validation was not successful.

Parameters
@NonNull byte[] input

ByteArray providing gzip-compressed ink.proto.BrushFamily binary proto messages, the same as written by encode.

@NonNull Version maxVersion

The maximum Version supported by the deserializer. Proto objects with a min_version of greater than maxVersion will be rejected.

OnDecodeTexturePngBytes onDecodeTexture

A callback to store any decoded texture image, if any were encoded inside the serialized BrushFamily. This is called synchronously as part of this function call, on the same thread, once for each texture image.

Returns
@NonNull BrushFamily

The BrushFamily parsed from the ByteArray.

Throws
IllegalArgumentException

input does not provide a valid ink.proto.BrushFamily proto message, or the corresponding BrushFamily is invalid.

IOException

if gzip-format bytes cannot be read from input.

public static final @NonNull BrushFamily decode(
    @NonNull BrushFamily.Companion receiver,
    @NonNull InputStream input,
    @NonNull Version maxVersion,
    OnDecodeTexturePngBytes onDecodeTexture
)

Read a serialized BrushFamily from the given InputStream and parse it into a BrushFamily, throwing an exception if parsing or validation was not successful. Java callers should use BrushFamilySerialization.decode instead.

Parameters
@NonNull InputStream input

InputStream providing gzip-compressed ink.proto.BrushFamily binary proto messages, the same as written by encode.

@NonNull Version maxVersion

The maximum Version supported by the deserializer. Proto objects with a min_version of greater than maxVersion will be rejected.

OnDecodeTexturePngBytes onDecodeTexture

A callback to store any decoded texture image, if any were encoded inside the serialized BrushFamily. This is called synchronously as part of this function call, on the same thread, once for each texture image.

Returns
@NonNull BrushFamily

The BrushFamily parsed from the InputStream.

Throws
java.io.IOException

if gzip-format bytes cannot be read from input.

IllegalArgumentException

input does not provide a valid ink.proto.BrushFamily proto message, or the corresponding BrushFamily is invalid.

decodeMultiple

@ExperimentalInkBrushCompatibilityApi
@Throws(exceptionClasses = [IOException])
public static final @NonNull List<@NonNull BrushFamily> decodeMultiple(
    @NonNull BrushFamily.Companion receiver,
    @NonNull byte[] input,
    @NonNull Version maxVersion,
    OnDecodeTexturePngBytes onDecodeTexture
)

Read a serialized BrushFamily from the given ByteArray and parse it into a List of BrushFamilys, throwing an exception if parsing or validation was not successful.

Parameters
@NonNull byte[] input

ByteArray providing gzip-compressed ink.proto.BrushFamily binary proto messages, the same as written by encodeMultiple.

@NonNull Version maxVersion

The maximum Version supported by the deserializer. If any of the serialized BrushFamilys have a min_version of greater than maxVersion, deserialization will fail.

OnDecodeTexturePngBytes onDecodeTexture

A callback to store any decoded texture image, if any were encoded inside the serialized BrushFamily. This is called synchronously as part of this function call, on the same thread, once for each texture image. If null (the default), then any encoded texture images will be ignored, and the texture IDs will be decoded as-is.

Returns
@NonNull List<@NonNull BrushFamily>

The List of BrushFamilys parsed from the ByteArray.

Throws
IllegalArgumentException

input does not provide a valid ink.proto.BrushFamily proto message, or any of the corresponding BrushFamilys are invalid.

IOException

if gzip-format bytes cannot be read from input.

decodeMultiple

@ExperimentalInkBrushCompatibilityApi
public static final @NonNull List<@NonNull BrushFamily> decodeMultiple(
    @NonNull BrushFamily.Companion receiver,
    @NonNull InputStream input,
    @NonNull Version maxVersion,
    OnDecodeTexturePngBytes onDecodeTexture
)

Read a serialized BrushFamily from the given InputStream and parse it into a List of BrushFamilys, throwing an exception if parsing or validation was not successful. Java callers should use BrushFamilySerialization.decodeMultiple instead.

Parameters
@NonNull InputStream input

InputStream providing gzip-compressed ink.proto.BrushFamily binary proto messages, the same as written by encodeMultiple.

@NonNull Version maxVersion

The maximum Version supported by the deserializer. If any of the serialized BrushFamilys have a min_version of greater than maxVersion, deserialization will fail.

OnDecodeTexturePngBytes onDecodeTexture

A callback to store any decoded texture image, if any were encoded inside the serialized BrushFamily. This is called synchronously as part of this function call, on the same thread, once for each texture image. If null (the default), then any encoded texture images will be ignored, and the texture IDs will be decoded as-is.

Returns
@NonNull List<@NonNull BrushFamily>

The List of BrushFamilys parsed from the InputStream.

Throws
java.io.IOException

if gzip-format bytes cannot be read from input.

IllegalArgumentException

input does not provide a valid ink.proto.BrushFamily proto message, or any of the corresponding BrushFamilys are invalid.

public static final @NonNull byte[] encode(
    @NonNull BrushFamily receiver,
    TexturePngBytesLookup textureIdToPngBytes
)

Write a gzip-compressed ink.proto.BrushFamily binary proto message representing the BrushFamily to the given ByteArray using the provided callback to retrieve texture PNG bytes. If BrushFamily.hasFallbacks is true, then the stored proto message including fallbacks for this BrushFamily will be used instead of recomputing the proto from the BrushFamily object.

Parameters
TexturePngBytesLookup textureIdToPngBytes

A callback to retrieve the PNG bytes of the texture bitmap for a given client texture ID, and the texture ID to write in its place (see TexturePngBytesLookup.getEncodedTextureId).

public static final void encode(
    @NonNull BrushFamily receiver,
    @NonNull OutputStream output,
    TexturePngBytesLookup textureIdToPngBytes
)

Write a gzip-compressed serialized ink.proto.BrushFamily proto message representing the BrushFamily to the given OutputStream. If BrushFamily.hasFallbacks is true, then the stored proto message including fallbacks for this BrushFamily will be used instead of recomputing the proto from the BrushFamily object.

encodeMultiple

@ExperimentalInkBrushCompatibilityApi
public static final @NonNull byte[] encodeMultiple(
    @NonNull List<@NonNull BrushFamily> receiver,
    TexturePngBytesLookup textureIdToPngBytes
)

Write a gzip-compressed serialized ink.proto.BrushFamily proto message representing the List of BrushFamilys to the given ByteArray.

All BrushFamily objects in this List are encoded into a single BrushFamily proto object. The order of the BrushFamilys in the List passed is irrelevant, as they will be sorted by version compatibility prior to encoding. The proto is encoded such that the top-level is the lowest-version compatible BrushFamily, making the proto backwards compatible with older versions of Ink which have no concept of nested brush families. Creates new fallbacks from the BrushFamily objects passed in, overriding any existing fallbacks on any individual BrushFamily.

Parameters
TexturePngBytesLookup textureIdToPngBytes

An optional interface for providing both a mapping from texture IDs to PNG bytes, and a callback to rename texture IDs when encoding (see TexturePngBytesLookup.getEncodedTextureId). If null (the default), then no textures will be encoded, and the texture IDs will be encoded as-is.

encodeMultiple

@ExperimentalInkBrushCompatibilityApi
public static final void encodeMultiple(
    @NonNull List<@NonNull BrushFamily> receiver,
    @NonNull OutputStream output,
    TexturePngBytesLookup textureIdToPngBytes
)

Write a gzip-compressed serialized ink.proto.BrushFamily proto message representing the List of BrushFamilys to the given OutputStream.

All BrushFamily objects in this List are encoded into a single BrushFamily proto object. The order of the BrushFamilys in the List passed is irrelevant, as they will be sorted by version compatibility prior to encoding. The proto is encoded such that the top-level is the lowest-version compatible BrushFamily, making the proto backwards compatible with older versions of Ink which have no concept of nested brush families. Creates new fallbacks from the BrushFamily objects passed in, overriding any existing fallbacks on any individual BrushFamily.

Parameters
@NonNull OutputStream output

OutputStream to write the encoded BrushFamilys to.

TexturePngBytesLookup textureIdToPngBytes

An optional interface for providing both a mapping from texture IDs to PNG bytes, and a callback to rename texture IDs when encoding (see TexturePngBytesLookup.getEncodedTextureId). If null (the default), then no textures will be encoded, and the texture IDs will be encoded as-is.