From 91575b8db60ca4fc6df9f44fa720929d8c3868ac Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Mon, 25 Feb 2019 00:21:40 +0100 Subject: use TagSet as the implementation for Context tags --- .../generated/binary/context/BooleanTag.java | 412 +++++++++++++++++ .../context/generated/binary/context/Context.java | 107 +---- .../context/generated/binary/context/Entry.java | 76 +-- .../context/generated/binary/context/LongTag.java | 443 ++++++++++++++++++ .../generated/binary/context/StringTag.java | 466 +++++++++++++++++++ .../context/generated/binary/context/Tags.java | 513 +++++++++++++++++++++ 6 files changed, 1882 insertions(+), 135 deletions(-) create mode 100644 kamon-core/src/main/java/kamon/context/generated/binary/context/BooleanTag.java create mode 100644 kamon-core/src/main/java/kamon/context/generated/binary/context/LongTag.java create mode 100644 kamon-core/src/main/java/kamon/context/generated/binary/context/StringTag.java create mode 100644 kamon-core/src/main/java/kamon/context/generated/binary/context/Tags.java (limited to 'kamon-core/src/main/java/kamon') diff --git a/kamon-core/src/main/java/kamon/context/generated/binary/context/BooleanTag.java b/kamon-core/src/main/java/kamon/context/generated/binary/context/BooleanTag.java new file mode 100644 index 00000000..d8caad09 --- /dev/null +++ b/kamon-core/src/main/java/kamon/context/generated/binary/context/BooleanTag.java @@ -0,0 +1,412 @@ +package kamon.context.generated.binary.context; + + +// Code generated by colf(1); DO NOT EDIT. + + +import static java.lang.String.format; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamException; +import java.io.OutputStream; +import java.io.Serializable; +import java.nio.charset.StandardCharsets; +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 Colfer's home + */ +@javax.annotation.Generated(value="colf(1)", comments="Colfer from schema file Context.colf") +public class BooleanTag implements Serializable { + + /** The upper limit for serial byte sizes. */ + public static int colferSizeMax = 16 * 1024 * 1024; + + + + + public String key; + + public boolean value; + + + /** Default constructor */ + public BooleanTag() { + init(); + } + + + /** Colfer zero values. */ + private void init() { + key = ""; + } + + /** + * {@link #reset(InputStream) Reusable} deserialization of Colfer streams. + */ + public static class Unmarshaller { + + /** The data source. */ + protected InputStream in; + + /** The read buffer. */ + public byte[] buf; + + /** The {@link #buf buffer}'s data start index, inclusive. */ + protected int offset; + + /** The {@link #buf buffer}'s data end index, exclusive. */ + protected int i; + + + /** + * @param in the data source or {@code null}. + * @param buf the initial buffer or {@code null}. + */ + public Unmarshaller(InputStream in, byte[] buf) { + // TODO: better size estimation + if (buf == null || buf.length == 0) + buf = new byte[Math.min(BooleanTag.colferSizeMax, 2048)]; + this.buf = buf; + reset(in); + } + + /** + * Reuses the marshaller. + * @param in the data source or {@code null}. + * @throws IllegalStateException on pending data. + */ + public void reset(InputStream in) { + if (this.i != this.offset) throw new IllegalStateException("colfer: pending data"); + this.in = in; + this.offset = 0; + this.i = 0; + } + + /** + * Deserializes the following object. + * @return the result or {@code null} when EOF. + * @throws IOException from the input stream. + * @throws SecurityException on an upper limit breach defined by {@link #colferSizeMax}. + * @throws InputMismatchException when the data does not match this object's schema. + */ + public BooleanTag next() throws IOException { + if (in == null) return null; + + while (true) { + if (this.i > this.offset) { + try { + BooleanTag o = new BooleanTag(); + this.offset = o.unmarshal(this.buf, this.offset, this.i); + return o; + } catch (BufferUnderflowException e) { + } + } + // not enough data + + if (this.i <= this.offset) { + this.offset = 0; + this.i = 0; + } else if (i == buf.length) { + byte[] src = this.buf; + // TODO: better size estimation + if (offset == 0) this.buf = new byte[Math.min(BooleanTag.colferSizeMax, this.buf.length * 4)]; + System.arraycopy(src, this.offset, this.buf, 0, this.i - this.offset); + this.i -= this.offset; + this.offset = 0; + } + assert this.i < this.buf.length; + + int n = in.read(buf, i, buf.length - i); + if (n < 0) { + if (this.i > this.offset) + throw new InputMismatchException("colfer: pending data with EOF"); + return null; + } + assert n > 0; + i += n; + } + } + + } + + + /** + * Serializes the object. + * @param out the data destination. + * @param buf the initial buffer or {@code null}. + * @return the final buffer. When the serial fits into {@code buf} then the return is {@code buf}. + * Otherwise the return is a new buffer, large enough to hold the whole serial. + * @throws IOException from {@code out}. + * @throws IllegalStateException on an upper limit breach defined by {@link #colferSizeMax}. + */ + public byte[] marshal(OutputStream out, byte[] buf) throws IOException { + // TODO: better size estimation + if (buf == null || buf.length == 0) + buf = new byte[Math.min(BooleanTag.colferSizeMax, 2048)]; + + while (true) { + int i; + try { + i = marshal(buf, 0); + } catch (BufferOverflowException e) { + buf = new byte[Math.min(BooleanTag.colferSizeMax, buf.length * 4)]; + continue; + } + + out.write(buf, 0, i); + return buf; + } + } + + /** + * Serializes the object. + * @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 {@link #colferSizeMax}. + */ + public int marshal(byte[] buf, int offset) { + int i = offset; + + try { + if (! this.key.isEmpty()) { + buf[i++] = (byte) 0; + int start = ++i; + + String s = this.key; + 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 > BooleanTag.colferSizeMax) + throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.BooleanTag.key size %d exceeds %d UTF-8 bytes", size, BooleanTag.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.value) { + buf[i++] = (byte) 1; + } + + buf[i++] = (byte) 0x7f; + return i; + } catch (ArrayIndexOutOfBoundsException e) { + if (i - offset > BooleanTag.colferSizeMax) + throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.BooleanTag exceeds %d bytes", BooleanTag.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 {@link #colferSizeMax}. + * @throws InputMismatchException when the data does not match this object's schema. + */ + public int unmarshal(byte[] buf, int offset) { + return unmarshal(buf, offset, buf.length); + } + + /** + * Deserializes the object. + * @param buf the data source. + * @param offset the initial index for {@code buf}, inclusive. + * @param end the index limit for {@code buf}, exclusive. + * @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 {@link #colferSizeMax}. + * @throws InputMismatchException when the data does not match this object's schema. + */ + public int unmarshal(byte[] buf, int offset, int end) { + if (end > buf.length) end = buf.length; + 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 < 0 || size > BooleanTag.colferSizeMax) + throw new SecurityException(format("colfer: kamon/context/generated/binary/context.BooleanTag.key size %d exceeds %d UTF-8 bytes", size, BooleanTag.colferSizeMax)); + + int start = i; + i += size; + this.key = new String(buf, start, size, StandardCharsets.UTF_8); + header = buf[i++]; + } + + if (header == (byte) 1) { + this.value = true; + header = buf[i++]; + } + + if (header != (byte) 0x7f) + throw new InputMismatchException(format("colfer: unknown header at byte %d", i - 1)); + } finally { + if (i > end && end - offset < BooleanTag.colferSizeMax) throw new BufferUnderflowException(); + if (i < 0 || i - offset > BooleanTag.colferSizeMax) + throw new SecurityException(format("colfer: kamon/context/generated/binary/context.BooleanTag exceeds %d bytes", BooleanTag.colferSizeMax)); + if (i > end) throw new BufferUnderflowException(); + } + + return i; + } + + // {@link Serializable} version number. + private static final long serialVersionUID = 2L; + + // {@link Serializable} Colfer extension. + private void writeObject(ObjectOutputStream out) throws IOException { + // TODO: better size estimation + byte[] buf = new byte[1024]; + int n; + while (true) try { + n = marshal(buf, 0); + break; + } catch (BufferUnderflowException e) { + buf = new byte[4 * buf.length]; + } + + out.writeInt(n); + out.write(buf, 0, n); + } + + // {@link Serializable} Colfer extension. + private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { + init(); + + int n = in.readInt(); + byte[] buf = new byte[n]; + in.readFully(buf); + unmarshal(buf, 0); + } + + // {@link Serializable} Colfer extension. + private void readObjectNoData() throws ObjectStreamException { + init(); + } + + /** + * Gets kamon/context/generated/binary/context.BooleanTag.key. + * @return the value. + */ + public String getKey() { + return this.key; + } + + /** + * Sets kamon/context/generated/binary/context.BooleanTag.key. + * @param value the replacement. + */ + public void setKey(String value) { + this.key = value; + } + + /** + * Sets kamon/context/generated/binary/context.BooleanTag.key. + * @param value the replacement. + * @return {link this}. + */ + public BooleanTag withKey(String value) { + this.key = value; + return this; + } + + /** + * Gets kamon/context/generated/binary/context.BooleanTag.value. + * @return the value. + */ + public boolean getValue() { + return this.value; + } + + /** + * Sets kamon/context/generated/binary/context.BooleanTag.value. + * @param value the replacement. + */ + public void setValue(boolean value) { + this.value = value; + } + + /** + * Sets kamon/context/generated/binary/context.BooleanTag.value. + * @param value the replacement. + * @return {link this}. + */ + public BooleanTag withValue(boolean value) { + this.value = value; + return this; + } + + @Override + public final int hashCode() { + int h = 1; + if (this.key != null) h = 31 * h + this.key.hashCode(); + h = 31 * h + (this.value ? 1231 : 1237); + return h; + } + + @Override + public final boolean equals(Object o) { + return o instanceof BooleanTag && equals((BooleanTag) o); + } + + public final boolean equals(BooleanTag o) { + if (o == null) return false; + if (o == this) return true; + return o.getClass() == BooleanTag.class + && (this.key == null ? o.key == null : this.key.equals(o.key)) + && this.value == o.value; + } + +} diff --git a/kamon-core/src/main/java/kamon/context/generated/binary/context/Context.java b/kamon-core/src/main/java/kamon/context/generated/binary/context/Context.java index 4be6d630..3582bfa2 100644 --- a/kamon-core/src/main/java/kamon/context/generated/binary/context/Context.java +++ b/kamon-core/src/main/java/kamon/context/generated/binary/context/Context.java @@ -12,7 +12,6 @@ import java.io.ObjectOutputStream; import java.io.ObjectStreamException; import java.io.OutputStream; import java.io.Serializable; -import java.nio.charset.StandardCharsets; import java.util.InputMismatchException; import java.nio.BufferOverflowException; import java.nio.BufferUnderflowException; @@ -36,7 +35,7 @@ public class Context implements Serializable { - public String[] tags; + public Tags tags; public Entry[] entries; @@ -46,12 +45,10 @@ public class Context implements Serializable { init(); } - private static final String[] _zeroTags = new String[0]; private static final Entry[] _zeroEntries = new Entry[0]; /** Colfer zero values. */ private void init() { - tags = _zeroTags; entries = _zeroEntries; } @@ -147,7 +144,6 @@ public class Context implements Serializable { /** * Serializes the object. - * All {@code null} elements in {@link #tags} will be replaced with {@code ""}. * All {@code null} elements in {@link #entries} will be replaced with a {@code new} value. * @param out the data destination. * @param buf the initial buffer or {@code null}. @@ -177,7 +173,6 @@ public class Context implements Serializable { /** * Serializes the object. - * All {@code null} elements in {@link #tags} will be replaced with {@code ""}. * All {@code null} elements in {@link #entries} will be replaced with a {@code new} value. * @param buf the data destination. * @param offset the initial index for {@code buf}, inclusive. @@ -189,68 +184,9 @@ public class Context implements Serializable { int i = offset; try { - if (this.tags.length != 0) { + if (this.tags != null) { buf[i++] = (byte) 0; - String[] a = this.tags; - - int x = a.length; - if (x > Context.colferListMax) - throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.Context.tags length %d exceeds %d elements", x, Context.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 > Context.colferSizeMax) - throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.Context.tags[%d] size %d exceeds %d UTF-8 bytes", ai, size, Context.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; - } + i = this.tags.marshal(buf, i); } if (this.entries.length != 0) { @@ -317,31 +253,8 @@ public class Context implements Serializable { 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 < 0 || length > Context.colferListMax) - throw new SecurityException(format("colfer: kamon/context/generated/binary/context.Context.tags length %d exceeds %d elements", length, Context.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 < 0 || size > Context.colferSizeMax) - throw new SecurityException(format("colfer: kamon/context/generated/binary/context.Context.tags[%d] size %d exceeds %d UTF-8 bytes", ai, size, Context.colferSizeMax)); - - int start = i; - i += size; - a[ai] = new String(buf, start, size, StandardCharsets.UTF_8); - } - this.tags = a; + this.tags = new Tags(); + i = this.tags.unmarshal(buf, i, end); header = buf[i++]; } @@ -415,7 +328,7 @@ public class Context implements Serializable { * Gets kamon/context/generated/binary/context.Context.tags. * @return the value. */ - public String[] getTags() { + public Tags getTags() { return this.tags; } @@ -423,7 +336,7 @@ public class Context implements Serializable { * Sets kamon/context/generated/binary/context.Context.tags. * @param value the replacement. */ - public void setTags(String[] value) { + public void setTags(Tags value) { this.tags = value; } @@ -432,7 +345,7 @@ public class Context implements Serializable { * @param value the replacement. * @return {link this}. */ - public Context withTags(String[] value) { + public Context withTags(Tags value) { this.tags = value; return this; } @@ -466,7 +379,7 @@ public class Context implements Serializable { @Override public final int hashCode() { int h = 1; - for (String o : this.tags) h = 31 * h + (o == null ? 0 : o.hashCode()); + if (this.tags != null) h = 31 * h + this.tags.hashCode(); for (Entry o : this.entries) h = 31 * h + (o == null ? 0 : o.hashCode()); return h; } @@ -480,7 +393,7 @@ public class Context implements Serializable { if (o == null) return false; if (o == this) return true; return o.getClass() == Context.class - && java.util.Arrays.equals(this.tags, o.tags) + && (this.tags == null ? o.tags == null : this.tags.equals(o.tags)) && java.util.Arrays.equals(this.entries, o.entries); } diff --git a/kamon-core/src/main/java/kamon/context/generated/binary/context/Entry.java b/kamon-core/src/main/java/kamon/context/generated/binary/context/Entry.java index dc75b10d..32213c79 100644 --- a/kamon-core/src/main/java/kamon/context/generated/binary/context/Entry.java +++ b/kamon-core/src/main/java/kamon/context/generated/binary/context/Entry.java @@ -33,9 +33,9 @@ public class Entry implements Serializable { - public String name; + public String key; - public byte[] content; + public byte[] value; /** Default constructor */ @@ -47,8 +47,8 @@ public class Entry implements Serializable { /** Colfer zero values. */ private void init() { - name = ""; - content = _zeroBytes; + key = ""; + value = _zeroBytes; } /** @@ -181,11 +181,11 @@ public class Entry implements Serializable { int i = offset; try { - if (! this.name.isEmpty()) { + if (! this.key.isEmpty()) { buf[i++] = (byte) 0; int start = ++i; - String s = this.name; + String s = this.key; for (int sIndex = 0, sLength = s.length(); sIndex < sLength; sIndex++) { char c = s.charAt(sIndex); if (c < '\u0080') { @@ -211,7 +211,7 @@ public class Entry implements Serializable { } int size = i - start; if (size > Entry.colferSizeMax) - throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.Entry.name size %d exceeds %d UTF-8 bytes", size, Entry.colferSizeMax)); + throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.Entry.key size %d exceeds %d UTF-8 bytes", size, Entry.colferSizeMax)); int ii = start - 1; if (size > 0x7f) { @@ -227,12 +227,12 @@ public class Entry implements Serializable { buf[ii] = (byte) size; } - if (this.content.length != 0) { + if (this.value.length != 0) { buf[i++] = (byte) 1; - int size = this.content.length; + int size = this.value.length; if (size > Entry.colferSizeMax) - throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.Entry.content size %d exceeds %d bytes", size, Entry.colferSizeMax)); + throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.Entry.value size %d exceeds %d bytes", size, Entry.colferSizeMax)); int x = size; while (x > 0x7f) { @@ -243,7 +243,7 @@ public class Entry implements Serializable { int start = i; i += size; - System.arraycopy(this.content, 0, buf, start, size); + System.arraycopy(this.value, 0, buf, start, size); } buf[i++] = (byte) 0x7f; @@ -294,11 +294,11 @@ public class Entry implements Serializable { if (shift == 28 || b >= 0) break; } if (size < 0 || size > Entry.colferSizeMax) - throw new SecurityException(format("colfer: kamon/context/generated/binary/context.Entry.name size %d exceeds %d UTF-8 bytes", size, Entry.colferSizeMax)); + throw new SecurityException(format("colfer: kamon/context/generated/binary/context.Entry.key size %d exceeds %d UTF-8 bytes", size, Entry.colferSizeMax)); int start = i; i += size; - this.name = new String(buf, start, size, StandardCharsets.UTF_8); + this.key = new String(buf, start, size, StandardCharsets.UTF_8); header = buf[i++]; } @@ -310,12 +310,12 @@ public class Entry implements Serializable { if (shift == 28 || b >= 0) break; } if (size < 0 || size > Entry.colferSizeMax) - throw new SecurityException(format("colfer: kamon/context/generated/binary/context.Entry.content size %d exceeds %d bytes", size, Entry.colferSizeMax)); + throw new SecurityException(format("colfer: kamon/context/generated/binary/context.Entry.value size %d exceeds %d bytes", size, Entry.colferSizeMax)); - this.content = new byte[size]; + this.value = new byte[size]; int start = i; i += size; - System.arraycopy(buf, start, this.content, 0, size); + System.arraycopy(buf, start, this.value, 0, size); header = buf[i++]; } @@ -367,62 +367,62 @@ public class Entry implements Serializable { } /** - * Gets kamon/context/generated/binary/context.Entry.name. + * Gets kamon/context/generated/binary/context.Entry.key. * @return the value. */ - public String getName() { - return this.name; + public String getKey() { + return this.key; } /** - * Sets kamon/context/generated/binary/context.Entry.name. + * Sets kamon/context/generated/binary/context.Entry.key. * @param value the replacement. */ - public void setName(String value) { - this.name = value; + public void setKey(String value) { + this.key = value; } /** - * Sets kamon/context/generated/binary/context.Entry.name. + * Sets kamon/context/generated/binary/context.Entry.key. * @param value the replacement. * @return {link this}. */ - public Entry withName(String value) { - this.name = value; + public Entry withKey(String value) { + this.key = value; return this; } /** - * Gets kamon/context/generated/binary/context.Entry.content. + * Gets kamon/context/generated/binary/context.Entry.value. * @return the value. */ - public byte[] getContent() { - return this.content; + public byte[] getValue() { + return this.value; } /** - * Sets kamon/context/generated/binary/context.Entry.content. + * Sets kamon/context/generated/binary/context.Entry.value. * @param value the replacement. */ - public void setContent(byte[] value) { - this.content = value; + public void setValue(byte[] value) { + this.value = value; } /** - * Sets kamon/context/generated/binary/context.Entry.content. + * Sets kamon/context/generated/binary/context.Entry.value. * @param value the replacement. * @return {link this}. */ - public Entry withContent(byte[] value) { - this.content = value; + public Entry withValue(byte[] value) { + this.value = value; return this; } @Override public final int hashCode() { int h = 1; - if (this.name != null) h = 31 * h + this.name.hashCode(); - for (byte b : this.content) h = 31 * h + b; + if (this.key != null) h = 31 * h + this.key.hashCode(); + for (byte b : this.value) h = 31 * h + b; return h; } @@ -435,8 +435,8 @@ public class Entry implements Serializable { if (o == null) return false; if (o == this) return true; return o.getClass() == Entry.class - && (this.name == null ? o.name == null : this.name.equals(o.name)) - && java.util.Arrays.equals(this.content, o.content); + && (this.key == null ? o.key == null : this.key.equals(o.key)) + && java.util.Arrays.equals(this.value, o.value); } } diff --git a/kamon-core/src/main/java/kamon/context/generated/binary/context/LongTag.java b/kamon-core/src/main/java/kamon/context/generated/binary/context/LongTag.java new file mode 100644 index 00000000..505ba2f0 --- /dev/null +++ b/kamon-core/src/main/java/kamon/context/generated/binary/context/LongTag.java @@ -0,0 +1,443 @@ +package kamon.context.generated.binary.context; + + +// Code generated by colf(1); DO NOT EDIT. + + +import static java.lang.String.format; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamException; +import java.io.OutputStream; +import java.io.Serializable; +import java.nio.charset.StandardCharsets; +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 Colfer's home + */ +@javax.annotation.Generated(value="colf(1)", comments="Colfer from schema file Context.colf") +public class LongTag implements Serializable { + + /** The upper limit for serial byte sizes. */ + public static int colferSizeMax = 16 * 1024 * 1024; + + + + + public String key; + + public long value; + + + /** Default constructor */ + public LongTag() { + init(); + } + + + /** Colfer zero values. */ + private void init() { + key = ""; + } + + /** + * {@link #reset(InputStream) Reusable} deserialization of Colfer streams. + */ + public static class Unmarshaller { + + /** The data source. */ + protected InputStream in; + + /** The read buffer. */ + public byte[] buf; + + /** The {@link #buf buffer}'s data start index, inclusive. */ + protected int offset; + + /** The {@link #buf buffer}'s data end index, exclusive. */ + protected int i; + + + /** + * @param in the data source or {@code null}. + * @param buf the initial buffer or {@code null}. + */ + public Unmarshaller(InputStream in, byte[] buf) { + // TODO: better size estimation + if (buf == null || buf.length == 0) + buf = new byte[Math.min(LongTag.colferSizeMax, 2048)]; + this.buf = buf; + reset(in); + } + + /** + * Reuses the marshaller. + * @param in the data source or {@code null}. + * @throws IllegalStateException on pending data. + */ + public void reset(InputStream in) { + if (this.i != this.offset) throw new IllegalStateException("colfer: pending data"); + this.in = in; + this.offset = 0; + this.i = 0; + } + + /** + * Deserializes the following object. + * @return the result or {@code null} when EOF. + * @throws IOException from the input stream. + * @throws SecurityException on an upper limit breach defined by {@link #colferSizeMax}. + * @throws InputMismatchException when the data does not match this object's schema. + */ + public LongTag next() throws IOException { + if (in == null) return null; + + while (true) { + if (this.i > this.offset) { + try { + LongTag o = new LongTag(); + this.offset = o.unmarshal(this.buf, this.offset, this.i); + return o; + } catch (BufferUnderflowException e) { + } + } + // not enough data + + if (this.i <= this.offset) { + this.offset = 0; + this.i = 0; + } else if (i == buf.length) { + byte[] src = this.buf; + // TODO: better size estimation + if (offset == 0) this.buf = new byte[Math.min(LongTag.colferSizeMax, this.buf.length * 4)]; + System.arraycopy(src, this.offset, this.buf, 0, this.i - this.offset); + this.i -= this.offset; + this.offset = 0; + } + assert this.i < this.buf.length; + + int n = in.read(buf, i, buf.length - i); + if (n < 0) { + if (this.i > this.offset) + throw new InputMismatchException("colfer: pending data with EOF"); + return null; + } + assert n > 0; + i += n; + } + } + + } + + + /** + * Serializes the object. + * @param out the data destination. + * @param buf the initial buffer or {@code null}. + * @return the final buffer. When the serial fits into {@code buf} then the return is {@code buf}. + * Otherwise the return is a new buffer, large enough to hold the whole serial. + * @throws IOException from {@code out}. + * @throws IllegalStateException on an upper limit breach defined by {@link #colferSizeMax}. + */ + public byte[] marshal(OutputStream out, byte[] buf) throws IOException { + // TODO: better size estimation + if (buf == null || buf.length == 0) + buf = new byte[Math.min(LongTag.colferSizeMax, 2048)]; + + while (true) { + int i; + try { + i = marshal(buf, 0); + } catch (BufferOverflowException e) { + buf = new byte[Math.min(LongTag.colferSizeMax, buf.length * 4)]; + continue; + } + + out.write(buf, 0, i); + return buf; + } + } + + /** + * Serializes the object. + * @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 {@link #colferSizeMax}. + */ + public int marshal(byte[] buf, int offset) { + int i = offset; + + try { + if (! this.key.isEmpty()) { + buf[i++] = (byte) 0; + int start = ++i; + + String s = this.key; + 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 > LongTag.colferSizeMax) + throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.LongTag.key size %d exceeds %d UTF-8 bytes", size, LongTag.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.value != 0) { + long x = this.value; + if (x < 0) { + x = -x; + buf[i++] = (byte) (1 | 0x80); + } else + buf[i++] = (byte) 1; + for (int n = 0; n < 8 && (x & ~0x7fL) != 0; n++) { + buf[i++] = (byte) (x | 0x80); + x >>>= 7; + } + buf[i++] = (byte) x; + } + + buf[i++] = (byte) 0x7f; + return i; + } catch (ArrayIndexOutOfBoundsException e) { + if (i - offset > LongTag.colferSizeMax) + throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.LongTag exceeds %d bytes", LongTag.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 {@link #colferSizeMax}. + * @throws InputMismatchException when the data does not match this object's schema. + */ + public int unmarshal(byte[] buf, int offset) { + return unmarshal(buf, offset, buf.length); + } + + /** + * Deserializes the object. + * @param buf the data source. + * @param offset the initial index for {@code buf}, inclusive. + * @param end the index limit for {@code buf}, exclusive. + * @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 {@link #colferSizeMax}. + * @throws InputMismatchException when the data does not match this object's schema. + */ + public int unmarshal(byte[] buf, int offset, int end) { + if (end > buf.length) end = buf.length; + 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 < 0 || size > LongTag.colferSizeMax) + throw new SecurityException(format("colfer: kamon/context/generated/binary/context.LongTag.key size %d exceeds %d UTF-8 bytes", size, LongTag.colferSizeMax)); + + int start = i; + i += size; + this.key = new String(buf, start, size, StandardCharsets.UTF_8); + header = buf[i++]; + } + + if (header == (byte) 1) { + 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.value = x; + header = buf[i++]; + } else if (header == (byte) (1 | 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.value = -x; + header = buf[i++]; + } + + if (header != (byte) 0x7f) + throw new InputMismatchException(format("colfer: unknown header at byte %d", i - 1)); + } finally { + if (i > end && end - offset < LongTag.colferSizeMax) throw new BufferUnderflowException(); + if (i < 0 || i - offset > LongTag.colferSizeMax) + throw new SecurityException(format("colfer: kamon/context/generated/binary/context.LongTag exceeds %d bytes", LongTag.colferSizeMax)); + if (i > end) throw new BufferUnderflowException(); + } + + return i; + } + + // {@link Serializable} version number. + private static final long serialVersionUID = 2L; + + // {@link Serializable} Colfer extension. + private void writeObject(ObjectOutputStream out) throws IOException { + // TODO: better size estimation + byte[] buf = new byte[1024]; + int n; + while (true) try { + n = marshal(buf, 0); + break; + } catch (BufferUnderflowException e) { + buf = new byte[4 * buf.length]; + } + + out.writeInt(n); + out.write(buf, 0, n); + } + + // {@link Serializable} Colfer extension. + private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { + init(); + + int n = in.readInt(); + byte[] buf = new byte[n]; + in.readFully(buf); + unmarshal(buf, 0); + } + + // {@link Serializable} Colfer extension. + private void readObjectNoData() throws ObjectStreamException { + init(); + } + + /** + * Gets kamon/context/generated/binary/context.LongTag.key. + * @return the value. + */ + public String getKey() { + return this.key; + } + + /** + * Sets kamon/context/generated/binary/context.LongTag.key. + * @param value the replacement. + */ + public void setKey(String value) { + this.key = value; + } + + /** + * Sets kamon/context/generated/binary/context.LongTag.key. + * @param value the replacement. + * @return {link this}. + */ + public LongTag withKey(String value) { + this.key = value; + return this; + } + + /** + * Gets kamon/context/generated/binary/context.LongTag.value. + * @return the value. + */ + public long getValue() { + return this.value; + } + + /** + * Sets kamon/context/generated/binary/context.LongTag.value. + * @param value the replacement. + */ + public void setValue(long value) { + this.value = value; + } + + /** + * Sets kamon/context/generated/binary/context.LongTag.value. + * @param value the replacement. + * @return {link this}. + */ + public LongTag withValue(long value) { + this.value = value; + return this; + } + + @Override + public final int hashCode() { + int h = 1; + if (this.key != null) h = 31 * h + this.key.hashCode(); + h = 31 * h + (int)(this.value ^ this.value >>> 32); + return h; + } + + @Override + public final boolean equals(Object o) { + return o instanceof LongTag && equals((LongTag) o); + } + + public final boolean equals(LongTag o) { + if (o == null) return false; + if (o == this) return true; + return o.getClass() == LongTag.class + && (this.key == null ? o.key == null : this.key.equals(o.key)) + && this.value == o.value; + } + +} diff --git a/kamon-core/src/main/java/kamon/context/generated/binary/context/StringTag.java b/kamon-core/src/main/java/kamon/context/generated/binary/context/StringTag.java new file mode 100644 index 00000000..366744b4 --- /dev/null +++ b/kamon-core/src/main/java/kamon/context/generated/binary/context/StringTag.java @@ -0,0 +1,466 @@ +package kamon.context.generated.binary.context; + + +// Code generated by colf(1); DO NOT EDIT. + + +import static java.lang.String.format; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamException; +import java.io.OutputStream; +import java.io.Serializable; +import java.nio.charset.StandardCharsets; +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 Colfer's home + */ +@javax.annotation.Generated(value="colf(1)", comments="Colfer from schema file Context.colf") +public class StringTag implements Serializable { + + /** The upper limit for serial byte sizes. */ + public static int colferSizeMax = 16 * 1024 * 1024; + + + + + public String key; + + public String value; + + + /** Default constructor */ + public StringTag() { + init(); + } + + + /** Colfer zero values. */ + private void init() { + key = ""; + value = ""; + } + + /** + * {@link #reset(InputStream) Reusable} deserialization of Colfer streams. + */ + public static class Unmarshaller { + + /** The data source. */ + protected InputStream in; + + /** The read buffer. */ + public byte[] buf; + + /** The {@link #buf buffer}'s data start index, inclusive. */ + protected int offset; + + /** The {@link #buf buffer}'s data end index, exclusive. */ + protected int i; + + + /** + * @param in the data source or {@code null}. + * @param buf the initial buffer or {@code null}. + */ + public Unmarshaller(InputStream in, byte[] buf) { + // TODO: better size estimation + if (buf == null || buf.length == 0) + buf = new byte[Math.min(StringTag.colferSizeMax, 2048)]; + this.buf = buf; + reset(in); + } + + /** + * Reuses the marshaller. + * @param in the data source or {@code null}. + * @throws IllegalStateException on pending data. + */ + public void reset(InputStream in) { + if (this.i != this.offset) throw new IllegalStateException("colfer: pending data"); + this.in = in; + this.offset = 0; + this.i = 0; + } + + /** + * Deserializes the following object. + * @return the result or {@code null} when EOF. + * @throws IOException from the input stream. + * @throws SecurityException on an upper limit breach defined by {@link #colferSizeMax}. + * @throws InputMismatchException when the data does not match this object's schema. + */ + public StringTag next() throws IOException { + if (in == null) return null; + + while (true) { + if (this.i > this.offset) { + try { + StringTag o = new StringTag(); + this.offset = o.unmarshal(this.buf, this.offset, this.i); + return o; + } catch (BufferUnderflowException e) { + } + } + // not enough data + + if (this.i <= this.offset) { + this.offset = 0; + this.i = 0; + } else if (i == buf.length) { + byte[] src = this.buf; + // TODO: better size estimation + if (offset == 0) this.buf = new byte[Math.min(StringTag.colferSizeMax, this.buf.length * 4)]; + System.arraycopy(src, this.offset, this.buf, 0, this.i - this.offset); + this.i -= this.offset; + this.offset = 0; + } + assert this.i < this.buf.length; + + int n = in.read(buf, i, buf.length - i); + if (n < 0) { + if (this.i > this.offset) + throw new InputMismatchException("colfer: pending data with EOF"); + return null; + } + assert n > 0; + i += n; + } + } + + } + + + /** + * Serializes the object. + * @param out the data destination. + * @param buf the initial buffer or {@code null}. + * @return the final buffer. When the serial fits into {@code buf} then the return is {@code buf}. + * Otherwise the return is a new buffer, large enough to hold the whole serial. + * @throws IOException from {@code out}. + * @throws IllegalStateException on an upper limit breach defined by {@link #colferSizeMax}. + */ + public byte[] marshal(OutputStream out, byte[] buf) throws IOException { + // TODO: better size estimation + if (buf == null || buf.length == 0) + buf = new byte[Math.min(StringTag.colferSizeMax, 2048)]; + + while (true) { + int i; + try { + i = marshal(buf, 0); + } catch (BufferOverflowException e) { + buf = new byte[Math.min(StringTag.colferSizeMax, buf.length * 4)]; + continue; + } + + out.write(buf, 0, i); + return buf; + } + } + + /** + * Serializes the object. + * @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 {@link #colferSizeMax}. + */ + public int marshal(byte[] buf, int offset) { + int i = offset; + + try { + if (! this.key.isEmpty()) { + buf[i++] = (byte) 0; + int start = ++i; + + String s = this.key; + 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 > StringTag.colferSizeMax) + throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.StringTag.key size %d exceeds %d UTF-8 bytes", size, StringTag.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.value.isEmpty()) { + buf[i++] = (byte) 1; + int start = ++i; + + String s = this.value; + 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 > StringTag.colferSizeMax) + throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.StringTag.value size %d exceeds %d UTF-8 bytes", size, StringTag.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; + } + + buf[i++] = (byte) 0x7f; + return i; + } catch (ArrayIndexOutOfBoundsException e) { + if (i - offset > StringTag.colferSizeMax) + throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.StringTag exceeds %d bytes", StringTag.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 {@link #colferSizeMax}. + * @throws InputMismatchException when the data does not match this object's schema. + */ + public int unmarshal(byte[] buf, int offset) { + return unmarshal(buf, offset, buf.length); + } + + /** + * Deserializes the object. + * @param buf the data source. + * @param offset the initial index for {@code buf}, inclusive. + * @param end the index limit for {@code buf}, exclusive. + * @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 {@link #colferSizeMax}. + * @throws InputMismatchException when the data does not match this object's schema. + */ + public int unmarshal(byte[] buf, int offset, int end) { + if (end > buf.length) end = buf.length; + 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 < 0 || size > StringTag.colferSizeMax) + throw new SecurityException(format("colfer: kamon/context/generated/binary/context.StringTag.key size %d exceeds %d UTF-8 bytes", size, StringTag.colferSizeMax)); + + int start = i; + i += size; + this.key = new String(buf, start, size, StandardCharsets.UTF_8); + 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 < 0 || size > StringTag.colferSizeMax) + throw new SecurityException(format("colfer: kamon/context/generated/binary/context.StringTag.value size %d exceeds %d UTF-8 bytes", size, StringTag.colferSizeMax)); + + int start = i; + i += size; + this.value = new String(buf, start, size, StandardCharsets.UTF_8); + header = buf[i++]; + } + + if (header != (byte) 0x7f) + throw new InputMismatchException(format("colfer: unknown header at byte %d", i - 1)); + } finally { + if (i > end && end - offset < StringTag.colferSizeMax) throw new BufferUnderflowException(); + if (i < 0 || i - offset > StringTag.colferSizeMax) + throw new SecurityException(format("colfer: kamon/context/generated/binary/context.StringTag exceeds %d bytes", StringTag.colferSizeMax)); + if (i > end) throw new BufferUnderflowException(); + } + + return i; + } + + // {@link Serializable} version number. + private static final long serialVersionUID = 2L; + + // {@link Serializable} Colfer extension. + private void writeObject(ObjectOutputStream out) throws IOException { + // TODO: better size estimation + byte[] buf = new byte[1024]; + int n; + while (true) try { + n = marshal(buf, 0); + break; + } catch (BufferUnderflowException e) { + buf = new byte[4 * buf.length]; + } + + out.writeInt(n); + out.write(buf, 0, n); + } + + // {@link Serializable} Colfer extension. + private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { + init(); + + int n = in.readInt(); + byte[] buf = new byte[n]; + in.readFully(buf); + unmarshal(buf, 0); + } + + // {@link Serializable} Colfer extension. + private void readObjectNoData() throws ObjectStreamException { + init(); + } + + /** + * Gets kamon/context/generated/binary/context.StringTag.key. + * @return the value. + */ + public String getKey() { + return this.key; + } + + /** + * Sets kamon/context/generated/binary/context.StringTag.key. + * @param value the replacement. + */ + public void setKey(String value) { + this.key = value; + } + + /** + * Sets kamon/context/generated/binary/context.StringTag.key. + * @param value the replacement. + * @return {link this}. + */ + public StringTag withKey(String value) { + this.key = value; + return this; + } + + /** + * Gets kamon/context/generated/binary/context.StringTag.value. + * @return the value. + */ + public String getValue() { + return this.value; + } + + /** + * Sets kamon/context/generated/binary/context.StringTag.value. + * @param value the replacement. + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Sets kamon/context/generated/binary/context.StringTag.value. + * @param value the replacement. + * @return {link this}. + */ + public StringTag withValue(String value) { + this.value = value; + return this; + } + + @Override + public final int hashCode() { + int h = 1; + if (this.key != null) h = 31 * h + this.key.hashCode(); + if (this.value != null) h = 31 * h + this.value.hashCode(); + return h; + } + + @Override + public final boolean equals(Object o) { + return o instanceof StringTag && equals((StringTag) o); + } + + public final boolean equals(StringTag o) { + if (o == null) return false; + if (o == this) return true; + return o.getClass() == StringTag.class + && (this.key == null ? o.key == null : this.key.equals(o.key)) + && (this.value == null ? o.value == null : this.value.equals(o.value)); + } + +} diff --git a/kamon-core/src/main/java/kamon/context/generated/binary/context/Tags.java b/kamon-core/src/main/java/kamon/context/generated/binary/context/Tags.java new file mode 100644 index 00000000..ce4d66db --- /dev/null +++ b/kamon-core/src/main/java/kamon/context/generated/binary/context/Tags.java @@ -0,0 +1,513 @@ +package kamon.context.generated.binary.context; + + +// Code generated by colf(1); DO NOT EDIT. + + +import static java.lang.String.format; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamException; +import java.io.OutputStream; +import java.io.Serializable; +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 Colfer's home + */ +@javax.annotation.Generated(value="colf(1)", comments="Colfer from schema file Context.colf") +public class Tags implements 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; + + + + + public StringTag[] strings; + + public LongTag[] longs; + + public BooleanTag[] booleans; + + + /** Default constructor */ + public Tags() { + init(); + } + + private static final StringTag[] _zeroStrings = new StringTag[0]; + private static final LongTag[] _zeroLongs = new LongTag[0]; + private static final BooleanTag[] _zeroBooleans = new BooleanTag[0]; + + /** Colfer zero values. */ + private void init() { + strings = _zeroStrings; + longs = _zeroLongs; + booleans = _zeroBooleans; + } + + /** + * {@link #reset(InputStream) Reusable} deserialization of Colfer streams. + */ + public static class Unmarshaller { + + /** The data source. */ + protected InputStream in; + + /** The read buffer. */ + public byte[] buf; + + /** The {@link #buf buffer}'s data start index, inclusive. */ + protected int offset; + + /** The {@link #buf buffer}'s data end index, exclusive. */ + protected int i; + + + /** + * @param in the data source or {@code null}. + * @param buf the initial buffer or {@code null}. + */ + public Unmarshaller(InputStream in, byte[] buf) { + // TODO: better size estimation + if (buf == null || buf.length == 0) + buf = new byte[Math.min(Tags.colferSizeMax, 2048)]; + this.buf = buf; + reset(in); + } + + /** + * Reuses the marshaller. + * @param in the data source or {@code null}. + * @throws IllegalStateException on pending data. + */ + public void reset(InputStream in) { + if (this.i != this.offset) throw new IllegalStateException("colfer: pending data"); + this.in = in; + this.offset = 0; + this.i = 0; + } + + /** + * Deserializes the following object. + * @return the result or {@code null} when EOF. + * @throws IOException from the input stream. + * @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 Tags next() throws IOException { + if (in == null) return null; + + while (true) { + if (this.i > this.offset) { + try { + Tags o = new Tags(); + this.offset = o.unmarshal(this.buf, this.offset, this.i); + return o; + } catch (BufferUnderflowException e) { + } + } + // not enough data + + if (this.i <= this.offset) { + this.offset = 0; + this.i = 0; + } else if (i == buf.length) { + byte[] src = this.buf; + // TODO: better size estimation + if (offset == 0) this.buf = new byte[Math.min(Tags.colferSizeMax, this.buf.length * 4)]; + System.arraycopy(src, this.offset, this.buf, 0, this.i - this.offset); + this.i -= this.offset; + this.offset = 0; + } + assert this.i < this.buf.length; + + int n = in.read(buf, i, buf.length - i); + if (n < 0) { + if (this.i > this.offset) + throw new InputMismatchException("colfer: pending data with EOF"); + return null; + } + assert n > 0; + i += n; + } + } + + } + + + /** + * Serializes the object. + * All {@code null} elements in {@link #strings} will be replaced with a {@code new} value. + * All {@code null} elements in {@link #longs} will be replaced with a {@code new} value. + * All {@code null} elements in {@link #booleans} will be replaced with a {@code new} value. + * @param out the data destination. + * @param buf the initial buffer or {@code null}. + * @return the final buffer. When the serial fits into {@code buf} then the return is {@code buf}. + * Otherwise the return is a new buffer, large enough to hold the whole serial. + * @throws IOException from {@code out}. + * @throws IllegalStateException on an upper limit breach defined by either {@link #colferSizeMax} or {@link #colferListMax}. + */ + public byte[] marshal(OutputStream out, byte[] buf) throws IOException { + // TODO: better size estimation + if (buf == null || buf.length == 0) + buf = new byte[Math.min(Tags.colferSizeMax, 2048)]; + + while (true) { + int i; + try { + i = marshal(buf, 0); + } catch (BufferOverflowException e) { + buf = new byte[Math.min(Tags.colferSizeMax, buf.length * 4)]; + continue; + } + + out.write(buf, 0, i); + return buf; + } + } + + /** + * Serializes the object. + * All {@code null} elements in {@link #strings} will be replaced with a {@code new} value. + * All {@code null} elements in {@link #longs} will be replaced with a {@code new} value. + * All {@code null} elements in {@link #booleans} 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.strings.length != 0) { + buf[i++] = (byte) 0; + StringTag[] a = this.strings; + + int x = a.length; + if (x > Tags.colferListMax) + throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.Tags.strings length %d exceeds %d elements", x, Tags.colferListMax)); + while (x > 0x7f) { + buf[i++] = (byte) (x | 0x80); + x >>>= 7; + } + buf[i++] = (byte) x; + + for (int ai = 0; ai < a.length; ai++) { + StringTag o = a[ai]; + if (o == null) { + o = new StringTag(); + a[ai] = o; + } + i = o.marshal(buf, i); + } + } + + if (this.longs.length != 0) { + buf[i++] = (byte) 1; + LongTag[] a = this.longs; + + int x = a.length; + if (x > Tags.colferListMax) + throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.Tags.longs length %d exceeds %d elements", x, Tags.colferListMax)); + while (x > 0x7f) { + buf[i++] = (byte) (x | 0x80); + x >>>= 7; + } + buf[i++] = (byte) x; + + for (int ai = 0; ai < a.length; ai++) { + LongTag o = a[ai]; + if (o == null) { + o = new LongTag(); + a[ai] = o; + } + i = o.marshal(buf, i); + } + } + + if (this.booleans.length != 0) { + buf[i++] = (byte) 2; + BooleanTag[] a = this.booleans; + + int x = a.length; + if (x > Tags.colferListMax) + throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.Tags.booleans length %d exceeds %d elements", x, Tags.colferListMax)); + while (x > 0x7f) { + buf[i++] = (byte) (x | 0x80); + x >>>= 7; + } + buf[i++] = (byte) x; + + for (int ai = 0; ai < a.length; ai++) { + BooleanTag o = a[ai]; + if (o == null) { + o = new BooleanTag(); + a[ai] = o; + } + i = o.marshal(buf, i); + } + } + + buf[i++] = (byte) 0x7f; + return i; + } catch (ArrayIndexOutOfBoundsException e) { + if (i - offset > Tags.colferSizeMax) + throw new IllegalStateException(format("colfer: kamon/context/generated/binary/context.Tags exceeds %d bytes", Tags.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) { + return unmarshal(buf, offset, buf.length); + } + + /** + * Deserializes the object. + * @param buf the data source. + * @param offset the initial index for {@code buf}, inclusive. + * @param end the index limit for {@code buf}, exclusive. + * @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 end) { + if (end > buf.length) end = buf.length; + 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 < 0 || length > Tags.colferListMax) + throw new SecurityException(format("colfer: kamon/context/generated/binary/context.Tags.strings length %d exceeds %d elements", length, Tags.colferListMax)); + + StringTag[] a = new StringTag[length]; + for (int ai = 0; ai < length; ai++) { + StringTag o = new StringTag(); + i = o.unmarshal(buf, i, end); + a[ai] = o; + } + this.strings = a; + header = buf[i++]; + } + + if (header == (byte) 1) { + 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 < 0 || length > Tags.colferListMax) + throw new SecurityException(format("colfer: kamon/context/generated/binary/context.Tags.longs length %d exceeds %d elements", length, Tags.colferListMax)); + + LongTag[] a = new LongTag[length]; + for (int ai = 0; ai < length; ai++) { + LongTag o = new LongTag(); + i = o.unmarshal(buf, i, end); + a[ai] = o; + } + this.longs = a; + header = buf[i++]; + } + + if (header == (byte) 2) { + 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 < 0 || length > Tags.colferListMax) + throw new SecurityException(format("colfer: kamon/context/generated/binary/context.Tags.booleans length %d exceeds %d elements", length, Tags.colferListMax)); + + BooleanTag[] a = new BooleanTag[length]; + for (int ai = 0; ai < length; ai++) { + BooleanTag o = new BooleanTag(); + i = o.unmarshal(buf, i, end); + a[ai] = o; + } + this.booleans = a; + header = buf[i++]; + } + + if (header != (byte) 0x7f) + throw new InputMismatchException(format("colfer: unknown header at byte %d", i - 1)); + } finally { + if (i > end && end - offset < Tags.colferSizeMax) throw new BufferUnderflowException(); + if (i < 0 || i - offset > Tags.colferSizeMax) + throw new SecurityException(format("colfer: kamon/context/generated/binary/context.Tags exceeds %d bytes", Tags.colferSizeMax)); + if (i > end) throw new BufferUnderflowException(); + } + + return i; + } + + // {@link Serializable} version number. + private static final long serialVersionUID = 3L; + + // {@link Serializable} Colfer extension. + private void writeObject(ObjectOutputStream out) throws IOException { + // TODO: better size estimation + byte[] buf = new byte[1024]; + int n; + while (true) try { + n = marshal(buf, 0); + break; + } catch (BufferUnderflowException e) { + buf = new byte[4 * buf.length]; + } + + out.writeInt(n); + out.write(buf, 0, n); + } + + // {@link Serializable} Colfer extension. + private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { + init(); + + int n = in.readInt(); + byte[] buf = new byte[n]; + in.readFully(buf); + unmarshal(buf, 0); + } + + // {@link Serializable} Colfer extension. + private void readObjectNoData() throws ObjectStreamException { + init(); + } + + /** + * Gets kamon/context/generated/binary/context.Tags.strings. + * @return the value. + */ + public StringTag[] getStrings() { + return this.strings; + } + + /** + * Sets kamon/context/generated/binary/context.Tags.strings. + * @param value the replacement. + */ + public void setStrings(StringTag[] value) { + this.strings = value; + } + + /** + * Sets kamon/context/generated/binary/context.Tags.strings. + * @param value the replacement. + * @return {link this}. + */ + public Tags withStrings(StringTag[] value) { + this.strings = value; + return this; + } + + /** + * Gets kamon/context/generated/binary/context.Tags.longs. + * @return the value. + */ + public LongTag[] getLongs() { + return this.longs; + } + + /** + * Sets kamon/context/generated/binary/context.Tags.longs. + * @param value the replacement. + */ + public void setLongs(LongTag[] value) { + this.longs = value; + } + + /** + * Sets kamon/context/generated/binary/context.Tags.longs. + * @param value the replacement. + * @return {link this}. + */ + public Tags withLongs(LongTag[] value) { + this.longs = value; + return this; + } + + /** + * Gets kamon/context/generated/binary/context.Tags.booleans. + * @return the value. + */ + public BooleanTag[] getBooleans() { + return this.booleans; + } + + /** + * Sets kamon/context/generated/binary/context.Tags.booleans. + * @param value the replacement. + */ + public void setBooleans(BooleanTag[] value) { + this.booleans = value; + } + + /** + * Sets kamon/context/generated/binary/context.Tags.booleans. + * @param value the replacement. + * @return {link this}. + */ + public Tags withBooleans(BooleanTag[] value) { + this.booleans = value; + return this; + } + + @Override + public final int hashCode() { + int h = 1; + for (StringTag o : this.strings) h = 31 * h + (o == null ? 0 : o.hashCode()); + for (LongTag o : this.longs) h = 31 * h + (o == null ? 0 : o.hashCode()); + for (BooleanTag o : this.booleans) h = 31 * h + (o == null ? 0 : o.hashCode()); + return h; + } + + @Override + public final boolean equals(Object o) { + return o instanceof Tags && equals((Tags) o); + } + + public final boolean equals(Tags o) { + if (o == null) return false; + if (o == this) return true; + return o.getClass() == Tags.class + && java.util.Arrays.equals(this.strings, o.strings) + && java.util.Arrays.equals(this.longs, o.longs) + && java.util.Arrays.equals(this.booleans, o.booleans); + } + +} -- cgit v1.2.3