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 Media 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 String[] _zeroPersons = new String[0];
public String uri = "";
public String title = "";
public int width;
public int height;
public String format = "";
public long duration;
public long size;
public String[] persons = _zeroPersons;
public String copyright = "";
public int bitrate;
public boolean hasBitrate;
public boolean flashPlay;
public boolean javaPlay;
/**
* Serializes the object.
* All {@code null} entries in {@link #persons} will be replaced with a "" 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.uri.isEmpty()) {
buf[i++] = (byte) 0;
int start = ++i;
String s = this.uri;
for (int sIndex = 0, sLength = s.length(); sIndex < sLength; sIndex++) {
char c = s.charAt(sIndex);
if (c < '\u0080') {
buf[i++] = (byte) c;
} else if (c < '\u0800') {
buf[i++] = (byte) (192 | c >>> 6);
buf[i++] = (byte) (128 | c & 63);
} else if (c < '\ud800' || c > '\udfff') {
buf[i++] = (byte) (224 | c >>> 12);
buf[i++] = (byte) (128 | c >>> 6 & 63);
buf[i++] = (byte) (128 | c & 63);
} else {
int cp = 0;
if (++sIndex < sLength) cp = Character.toCodePoint(c, s.charAt(sIndex));
if ((cp >= 1 << 16) && (cp < 1 << 21)) {
buf[i++] = (byte) (240 | cp >>> 18);
buf[i++] = (byte) (128 | cp >>> 12 & 63);
buf[i++] = (byte) (128 | cp >>> 6 & 63);
buf[i++] = (byte) (128 | cp & 63);
} else
buf[i++] = (byte) '?';
}
}
int size = i - start;
if (size > colferSizeMax)
throw new IllegalStateException(format("colfer: field serializers/colfer/media.media.uri size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
int ii = start - 1;
if (size > 0x7f) {
i++;
for (int x = size; x >= 1 << 14; x >>>= 7) i++;
System.arraycopy(buf, start, buf, i - size, size);
do {
buf[ii++] = (byte) (size | 0x80);
size >>>= 7;
} while (size > 0x7f);
}
buf[ii] = (byte) size;
}
if (! this.title.isEmpty()) {
buf[i++] = (byte) 1;
int start = ++i;
String s = this.title;
for (int sIndex = 0, sLength = s.length(); sIndex < sLength; sIndex++) {
char c = s.charAt(sIndex);
if (c < '\u0080') {
buf[i++] = (byte) c;
} else if (c < '\u0800') {
buf[i++] = (byte) (192 | c >>> 6);
buf[i++] = (byte) (128 | c & 63);
} else if (c < '\ud800' || c > '\udfff') {
buf[i++] = (byte) (224 | c >>> 12);
buf[i++] = (byte) (128 | c >>> 6 & 63);
buf[i++] = (byte) (128 | c & 63);
} else {
int cp = 0;
if (++sIndex < sLength) cp = Character.toCodePoint(c, s.charAt(sIndex));
if ((cp >= 1 << 16) && (cp < 1 << 21)) {
buf[i++] = (byte) (240 | cp >>> 18);
buf[i++] = (byte) (128 | cp >>> 12 & 63);
buf[i++] = (byte) (128 | cp >>> 6 & 63);
buf[i++] = (byte) (128 | cp & 63);
} else
buf[i++] = (byte) '?';
}
}
int size = i - start;
if (size > colferSizeMax)
throw new IllegalStateException(format("colfer: field serializers/colfer/media.media.title size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
int ii = start - 1;
if (size > 0x7f) {
i++;
for (int x = size; x >= 1 << 14; x >>>= 7) i++;
System.arraycopy(buf, start, buf, i - size, size);
do {
buf[ii++] = (byte) (size | 0x80);
size >>>= 7;
} while (size > 0x7f);
}
buf[ii] = (byte) size;
}
if (this.width != 0) {
int x = this.width;
if (x < 0) {
x = -x;
buf[i++] = (byte) (2 | 0x80);
} else
buf[i++] = (byte) 2;
while ((x & ~0x7f) != 0) {
buf[i++] = (byte) (x | 0x80);
x >>>= 7;
}
buf[i++] = (byte) x;
}
if (this.height != 0) {
int x = this.height;
if (x < 0) {
x = -x;
buf[i++] = (byte) (3 | 0x80);
} else
buf[i++] = (byte) 3;
while ((x & ~0x7f) != 0) {
buf[i++] = (byte) (x | 0x80);
x >>>= 7;
}
buf[i++] = (byte) x;
}
if (! this.format.isEmpty()) {
buf[i++] = (byte) 4;
int start = ++i;
String s = this.format;
for (int sIndex = 0, sLength = s.length(); sIndex < sLength; sIndex++) {
char c = s.charAt(sIndex);
if (c < '\u0080') {
buf[i++] = (byte) c;
} else if (c < '\u0800') {
buf[i++] = (byte) (192 | c >>> 6);
buf[i++] = (byte) (128 | c & 63);
} else if (c < '\ud800' || c > '\udfff') {
buf[i++] = (byte) (224 | c >>> 12);
buf[i++] = (byte) (128 | c >>> 6 & 63);
buf[i++] = (byte) (128 | c & 63);
} else {
int cp = 0;
if (++sIndex < sLength) cp = Character.toCodePoint(c, s.charAt(sIndex));
if ((cp >= 1 << 16) && (cp < 1 << 21)) {
buf[i++] = (byte) (240 | cp >>> 18);
buf[i++] = (byte) (128 | cp >>> 12 & 63);
buf[i++] = (byte) (128 | cp >>> 6 & 63);
buf[i++] = (byte) (128 | cp & 63);
} else
buf[i++] = (byte) '?';
}
}
int size = i - start;
if (size > colferSizeMax)
throw new IllegalStateException(format("colfer: field serializers/colfer/media.media.format size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
int ii = start - 1;
if (size > 0x7f) {
i++;
for (int x = size; x >= 1 << 14; x >>>= 7) i++;
System.arraycopy(buf, start, buf, i - size, size);
do {
buf[ii++] = (byte) (size | 0x80);
size >>>= 7;
} while (size > 0x7f);
}
buf[ii] = (byte) size;
}
if (this.duration != 0) {
long x = this.duration;
if (x < 0) {
x = -x;
buf[i++] = (byte) (5 | 0x80);
} else
buf[i++] = (byte) 5;
for (int n = 0; n < 8 && (x & ~0x7fL) != 0; n++) {
buf[i++] = (byte) (x | 0x80);
x >>>= 7;
}
buf[i++] = (byte) x;
}
if (this.size != 0) {
long x = this.size;
if (x < 0) {
x = -x;
buf[i++] = (byte) (6 | 0x80);
} else
buf[i++] = (byte) 6;
for (int n = 0; n < 8 && (x & ~0x7fL) != 0; n++) {
buf[i++] = (byte) (x | 0x80);
x >>>= 7;
}
buf[i++] = (byte) x;
}
if (this.persons.length != 0) {
buf[i++] = (byte) 7;
String[] a = this.persons;
int x = a.length;
if (x > colferListMax)
throw new IllegalStateException(format("colfer: field serializers/colfer/media.media.persons 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++) {
String s = a[ai];
if (s == null) {
s = "";
a[ai] = s;
}
int start = ++i;
for (int sIndex = 0, sLength = s.length(); sIndex < sLength; sIndex++) {
char c = s.charAt(sIndex);
if (c < '\u0080') {
buf[i++] = (byte) c;
} else if (c < '\u0800') {
buf[i++] = (byte) (192 | c >>> 6);
buf[i++] = (byte) (128 | c & 63);
} else if (c < '\ud800' || c > '\udfff') {
buf[i++] = (byte) (224 | c >>> 12);
buf[i++] = (byte) (128 | c >>> 6 & 63);
buf[i++] = (byte) (128 | c & 63);
} else {
int cp = 0;
if (++sIndex < sLength) cp = Character.toCodePoint(c, s.charAt(sIndex));
if ((cp >= 1 << 16) && (cp < 1 << 21)) {
buf[i++] = (byte) (240 | cp >>> 18);
buf[i++] = (byte) (128 | cp >>> 12 & 63);
buf[i++] = (byte) (128 | cp >>> 6 & 63);
buf[i++] = (byte) (128 | cp & 63);
} else
buf[i++] = (byte) '?';
}
}
int size = i - start;
if (size > colferSizeMax)
throw new IllegalStateException(format("colfer: field serializers/colfer/media.media.persons size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
int ii = start - 1;
if (size > 0x7f) {
i++;
for (int y = size; y >= 1 << 14; y >>>= 7) i++;
System.arraycopy(buf, start, buf, i - size, size);
do {
buf[ii++] = (byte) (size | 0x80);
size >>>= 7;
} while (size > 0x7f);
}
buf[ii] = (byte) size;
}
}
if (! this.copyright.isEmpty()) {
buf[i++] = (byte) 8;
int start = ++i;
String s = this.copyright;
for (int sIndex = 0, sLength = s.length(); sIndex < sLength; sIndex++) {
char c = s.charAt(sIndex);
if (c < '\u0080') {
buf[i++] = (byte) c;
} else if (c < '\u0800') {
buf[i++] = (byte) (192 | c >>> 6);
buf[i++] = (byte) (128 | c & 63);
} else if (c < '\ud800' || c > '\udfff') {
buf[i++] = (byte) (224 | c >>> 12);
buf[i++] = (byte) (128 | c >>> 6 & 63);
buf[i++] = (byte) (128 | c & 63);
} else {
int cp = 0;
if (++sIndex < sLength) cp = Character.toCodePoint(c, s.charAt(sIndex));
if ((cp >= 1 << 16) && (cp < 1 << 21)) {
buf[i++] = (byte) (240 | cp >>> 18);
buf[i++] = (byte) (128 | cp >>> 12 & 63);
buf[i++] = (byte) (128 | cp >>> 6 & 63);
buf[i++] = (byte) (128 | cp & 63);
} else
buf[i++] = (byte) '?';
}
}
int size = i - start;
if (size > colferSizeMax)
throw new IllegalStateException(format("colfer: field serializers/colfer/media.media.copyright size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
int ii = start - 1;
if (size > 0x7f) {
i++;
for (int x = size; x >= 1 << 14; x >>>= 7) i++;
System.arraycopy(buf, start, buf, i - size, size);
do {
buf[ii++] = (byte) (size | 0x80);
size >>>= 7;
} while (size > 0x7f);
}
buf[ii] = (byte) size;
}
if (this.bitrate != 0) {
int x = this.bitrate;
if (x < 0) {
x = -x;
buf[i++] = (byte) (9 | 0x80);
} else
buf[i++] = (byte) 9;
while ((x & ~0x7f) != 0) {
buf[i++] = (byte) (x | 0x80);
x >>>= 7;
}
buf[i++] = (byte) x;
}
if (this.hasBitrate) {
buf[i++] = (byte) 10;
}
if (this.flashPlay) {
buf[i++] = (byte) 11;
}
if (this.javaPlay) {
buf[i++] = (byte) 12;
}
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 size = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
size |= (b & 0x7f) << shift;
if (shift == 28 || b >= 0) break;
}
if (size > colferSizeMax)
throw new SecurityException(format("colfer: field serializers/colfer/media.media.uri size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
int start = i;
i += size;
this.uri = new String(buf, start, size, this._utf8);
header = buf[i++];
}
if (header == (byte) 1) {
int size = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
size |= (b & 0x7f) << shift;
if (shift == 28 || b >= 0) break;
}
if (size > colferSizeMax)
throw new SecurityException(format("colfer: field serializers/colfer/media.media.title size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
int start = i;
i += size;
this.title = new String(buf, start, size, this._utf8);
header = buf[i++];
}
if (header == (byte) 2) {
int x = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
x |= (b & 0x7f) << shift;
if (shift == 28 || b >= 0) break;
}
this.width = x;
header = buf[i++];
} else if (header == (byte) (2 | 0x80)) {
int x = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
x |= (b & 0x7f) << shift;
if (shift == 28 || b >= 0) break;
}
this.width = -x;
header = buf[i++];
}
if (header == (byte) 3) {
int x = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
x |= (b & 0x7f) << shift;
if (shift == 28 || b >= 0) break;
}
this.height = x;
header = buf[i++];
} else if (header == (byte) (3 | 0x80)) {
int x = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
x |= (b & 0x7f) << shift;
if (shift == 28 || b >= 0) break;
}
this.height = -x;
header = buf[i++];
}
if (header == (byte) 4) {
int size = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
size |= (b & 0x7f) << shift;
if (shift == 28 || b >= 0) break;
}
if (size > colferSizeMax)
throw new SecurityException(format("colfer: field serializers/colfer/media.media.format size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
int start = i;
i += size;
this.format = new String(buf, start, size, this._utf8);
header = buf[i++];
}
if (header == (byte) 5) {
long x = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
if (shift == 56 || b >= 0) {
x |= (b & 0xffL) << shift;
break;
}
x |= (b & 0x7fL) << shift;
}
this.duration = x;
header = buf[i++];
} else if (header == (byte) (5 | 0x80)) {
long x = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
if (shift == 56 || b >= 0) {
x |= (b & 0xffL) << shift;
break;
}
x |= (b & 0x7fL) << shift;
}
this.duration = -x;
header = buf[i++];
}
if (header == (byte) 6) {
long x = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
if (shift == 56 || b >= 0) {
x |= (b & 0xffL) << shift;
break;
}
x |= (b & 0x7fL) << shift;
}
this.size = x;
header = buf[i++];
} else if (header == (byte) (6 | 0x80)) {
long x = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
if (shift == 56 || b >= 0) {
x |= (b & 0xffL) << shift;
break;
}
x |= (b & 0x7fL) << shift;
}
this.size = -x;
header = buf[i++];
}
if (header == (byte) 7) {
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.media.persons length %d exceeds %d elements", length, colferListMax));
String[] a = new String[length];
for (int ai = 0; ai < length; ai++) {
int size = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
size |= (b & 0x7f) << shift;
if (shift == 28 || b >= 0) break;
}
if (size > colferSizeMax)
throw new SecurityException(format("colfer: field serializers/colfer/media.media.persons size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
int start = i;
i += size;
a[ai] = new String(buf, start, size, this._utf8);
}
this.persons = a;
header = buf[i++];
}
if (header == (byte) 8) {
int size = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
size |= (b & 0x7f) << shift;
if (shift == 28 || b >= 0) break;
}
if (size > colferSizeMax)
throw new SecurityException(format("colfer: field serializers/colfer/media.media.copyright size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
int start = i;
i += size;
this.copyright = new String(buf, start, size, this._utf8);
header = buf[i++];
}
if (header == (byte) 9) {
int x = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
x |= (b & 0x7f) << shift;
if (shift == 28 || b >= 0) break;
}
this.bitrate = x;
header = buf[i++];
} else if (header == (byte) (9 | 0x80)) {
int x = 0;
for (int shift = 0; true; shift += 7) {
byte b = buf[i++];
x |= (b & 0x7f) << shift;
if (shift == 28 || b >= 0) break;
}
this.bitrate = -x;
header = buf[i++];
}
if (header == (byte) 10) {
this.hasBitrate = true;
header = buf[i++];
}
if (header == (byte) 11) {
this.flashPlay = true;
header = buf[i++];
}
if (header == (byte) 12) {
this.javaPlay = true;
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 String getUri() {
return this.uri;
}
public void setUri(String value) {
this.uri = value;
}
public String getTitle() {
return this.title;
}
public void setTitle(String value) {
this.title = value;
}
public int getWidth() {
return this.width;
}
public void setWidth(int value) {
this.width = value;
}
public int getHeight() {
return this.height;
}
public void setHeight(int value) {
this.height = value;
}
public String getFormat() {
return this.format;
}
public void setFormat(String value) {
this.format = value;
}
public long getDuration() {
return this.duration;
}
public void setDuration(long value) {
this.duration = value;
}
public long getSize() {
return this.size;
}
public void setSize(long value) {
this.size = value;
}
public String[] getPersons() {
return this.persons;
}
public void setPersons(String[] value) {
this.persons = value;
}
public String getCopyright() {
return this.copyright;
}
public void setCopyright(String value) {
this.copyright = value;
}
public int getBitrate() {
return this.bitrate;
}
public void setBitrate(int value) {
this.bitrate = value;
}
public boolean getHasBitrate() {
return this.hasBitrate;
}
public void setHasBitrate(boolean value) {
this.hasBitrate = value;
}
public boolean getFlashPlay() {
return this.flashPlay;
}
public void setFlashPlay(boolean value) {
this.flashPlay = value;
}
public boolean getJavaPlay() {
return this.javaPlay;
}
public void setJavaPlay(boolean value) {
this.javaPlay = value;
}
@Override
public final int hashCode() {
int h = 1;
if (this.uri != null) h = 31 * h + this.uri.hashCode();
if (this.title != null) h = 31 * h + this.title.hashCode();
h = 31 * h + this.width;
h = 31 * h + this.height;
if (this.format != null) h = 31 * h + this.format.hashCode();
h = 31 * h + (int)(this.duration ^ this.duration >>> 32);
h = 31 * h + (int)(this.size ^ this.size >>> 32);
for (String o : this.persons) h = 31 * h + (o == null ? 0 : o.hashCode());
if (this.copyright != null) h = 31 * h + this.copyright.hashCode();
h = 31 * h + this.bitrate;
h = 31 * h + (this.hasBitrate ? 1231 : 1237);
h = 31 * h + (this.flashPlay ? 1231 : 1237);
h = 31 * h + (this.javaPlay ? 1231 : 1237);
return h;
}
@Override
public final boolean equals(Object o) {
return o instanceof Media && equals((Media) o);
}
public final boolean equals(Media o) {
return o != null
&& java.util.Objects.equals(this.uri, o.uri)
&& java.util.Objects.equals(this.title, o.title)
&& this.width == o.width
&& this.height == o.height
&& java.util.Objects.equals(this.format, o.format)
&& this.duration == o.duration
&& this.size == o.size
&& java.util.Arrays.equals(this.persons, o.persons)
&& java.util.Objects.equals(this.copyright, o.copyright)
&& this.bitrate == o.bitrate
&& this.hasBitrate == o.hasBitrate
&& this.flashPlay == o.flashPlay
&& this.javaPlay == o.javaPlay;
}
}