package serializers.colfer.media; // This file was generated by colf(1); DO NOT EDIT import static java.lang.String.format; import java.util.InputMismatchException; import java.nio.BufferOverflowException; import java.nio.BufferUnderflowException; /** * Data bean with built-in serialization support. * @author generated by colf(1) * @see <a href="https://github.com/pascaldekloe/colfer">Colfer's home</a> */ public class MediaContent implements java.io.Serializable { /** The upper limit for serial byte sizes. */ public static int colferSizeMax = 16 * 1024 * 1024; /** The upper limit for the number of elements in a list. */ public static int colferListMax = 64 * 1024; private static final java.nio.charset.Charset _utf8 = java.nio.charset.Charset.forName("UTF-8"); private static final Image[] _zeroImages = new Image[0]; public Image[] images = _zeroImages; public Media media; /** * Serializes the object. * All {@code null} entries in {@link #images} will be replaced with a {@code new} value. * @param buf the data destination. * @param offset the initial index for {@code buf}, inclusive. * @return the final index for {@code buf}, exclusive. * @throws BufferOverflowException when {@code buf} is too small. * @throws IllegalStateException on an upper limit breach defined by either {@link #colferSizeMax} or {@link #colferListMax}. */ public int marshal(byte[] buf, int offset) { int i = offset; try { if (this.images.length != 0) { buf[i++] = (byte) 0; Image[] a = this.images; int x = a.length; if (x > colferListMax) throw new IllegalStateException(format("colfer: field serializers/colfer/media.mediaContent.images length %d exceeds %d elements", x, colferListMax)); while (x > 0x7f) { buf[i++] = (byte) (x | 0x80); x >>>= 7; } buf[i++] = (byte) x; for (int ai = 0; ai < a.length; ai++) { Image o = a[ai]; if (o == null) { o = new Image(); a[ai] = o; } i = o.marshal(buf, i); } } if (this.media != null) { buf[i++] = (byte) 1; i = this.media.marshal(buf, i); } buf[i++] = (byte) 0x7f; return i; } catch (IndexOutOfBoundsException e) { if (i - offset > colferSizeMax) throw new IllegalStateException(format("colfer: serial exceeds %d bytes", colferSizeMax)); if (i >= buf.length) throw new BufferOverflowException(); throw e; } } /** * Deserializes the object. * @param buf the data source. * @param offset the initial index for {@code buf}, inclusive. * @return the final index for {@code buf}, exclusive. * @throws BufferUnderflowException when {@code buf} is incomplete. (EOF) * @throws SecurityException on an upper limit breach defined by either {@link #colferSizeMax} or {@link #colferListMax}. * @throws InputMismatchException when the data does not match this object's schema. */ public int unmarshal(byte[] buf, int offset) { int i = offset; try { byte header = buf[i++]; if (header == (byte) 0) { int length = 0; for (int shift = 0; true; shift += 7) { byte b = buf[i++]; length |= (b & 0x7f) << shift; if (shift == 28 || b >= 0) break; } if (length > colferListMax) throw new SecurityException(format("colfer: field serializers/colfer/media.mediaContent.images length %d exceeds %d elements", length, colferListMax)); Image[] a = new Image[length]; for (int ai = 0; ai < length; ai++) { Image o = new Image(); i = o.unmarshal(buf, i); a[ai] = o; } this.images = a; header = buf[i++]; } if (header == (byte) 1) { this.media = new Media(); i = this.media.unmarshal(buf, i); header = buf[i++]; } if (header != (byte) 0x7f) throw new InputMismatchException(format("colfer: unknown header at byte %d", i - 1)); } catch (IndexOutOfBoundsException e) { if (i - offset > colferSizeMax) throw new SecurityException(format("colfer: serial exceeds %d bytes", colferSizeMax)); if (i >= buf.length) throw new BufferUnderflowException(); throw new RuntimeException("colfer: bug", e); } if (i - offset > colferSizeMax) throw new SecurityException(format("colfer: serial exceeds %d bytes", colferSizeMax)); return i; } public Image[] getImages() { return this.images; } public void setImages(Image[] value) { this.images = value; } public Media getMedia() { return this.media; } public void setMedia(Media value) { this.media = value; } @Override public final int hashCode() { int h = 1; for (Image o : this.images) h = 31 * h + (o == null ? 0 : o.hashCode()); if (this.media != null) h = 31 * h + this.media.hashCode(); return h; } @Override public final boolean equals(Object o) { return o instanceof MediaContent && equals((MediaContent) o); } public final boolean equals(MediaContent o) { return o != null && java.util.Arrays.equals(this.images, o.images) && java.util.Objects.equals(this.media, o.media); } }