/*
 * This class file was automatically generated by ASN1bean v1.12.0 (http://www.beanit.com)
 */

package com.beanit.asn1dsrc.dsrc;

import java.io.IOException;
import java.io.EOFException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.io.Serializable;
import com.beanit.asn1bean.ber.*;
import com.beanit.asn1bean.ber.types.*;
import com.beanit.asn1bean.ber.types.string.*;


public class EventIdentityRoadSide implements BerType, Serializable {

	private static final long serialVersionUID = 1L;

	public static class EvntLocationInformation implements BerType, Serializable {

		private static final long serialVersionUID = 1L;

		public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
		private byte[] code = null;
		private List<LocationInformation> seqOf = null;

		public EvntLocationInformation() {
			seqOf = new ArrayList<LocationInformation>();
		}

		public EvntLocationInformation(byte[] code) {
			this.code = code;
		}

		public List<LocationInformation> getLocationInformation() {
			if (seqOf == null) {
				seqOf = new ArrayList<LocationInformation>();
			}
			return seqOf;
		}

		@Override public int encode(OutputStream reverseOS) throws IOException {
			return encode(reverseOS, true);
		}

		public int encode(OutputStream reverseOS, boolean withTag) throws IOException {

			if (code != null) {
				reverseOS.write(code);
				if (withTag) {
					return tag.encode(reverseOS) + code.length;
				}
				return code.length;
			}

			int codeLength = 0;
			for (int i = (seqOf.size() - 1); i >= 0; i--) {
				codeLength += seqOf.get(i).encode(reverseOS, true);
			}

			codeLength += BerLength.encodeLength(reverseOS, codeLength);

			if (withTag) {
				codeLength += tag.encode(reverseOS);
			}

			return codeLength;
		}

		@Override public int decode(InputStream is) throws IOException {
			return decode(is, true);
		}

		public int decode(InputStream is, boolean withTag) throws IOException {
			int tlByteCount = 0;
			int vByteCount = 0;
			BerTag berTag = new BerTag();
			if (withTag) {
				tlByteCount += tag.decodeAndCheck(is);
			}

			BerLength length = new BerLength();
			tlByteCount += length.decode(is);
			int lengthVal = length.val;

			while (vByteCount < lengthVal || lengthVal < 0) {
				vByteCount += berTag.decode(is);

				if (lengthVal < 0 && berTag.equals(0, 0, 0)) {
					vByteCount += BerLength.readEocByte(is);
					break;
				}

				if (!berTag.equals(LocationInformation.tag)) {
					throw new IOException("Tag does not match mandatory sequence of/set of component.");
				}
				LocationInformation element = new LocationInformation();
				vByteCount += element.decode(is, false);
				seqOf.add(element);
			}
			if (lengthVal >= 0 && vByteCount != lengthVal) {
				throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + lengthVal + " but has " + vByteCount);

			}
			return tlByteCount + vByteCount;
		}

		public void encodeAndSave(int encodingSizeGuess) throws IOException {
			ReverseByteArrayOutputStream reverseOS = new ReverseByteArrayOutputStream(encodingSizeGuess);
			encode(reverseOS, false);
			code = reverseOS.getArray();
		}

		@Override public String toString() {
			StringBuilder sb = new StringBuilder();
			appendAsString(sb, 0);
			return sb.toString();
		}

		public void appendAsString(StringBuilder sb, int indentLevel) {

			sb.append("{\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			if (seqOf == null) {
				sb.append("null");
			}
			else {
				Iterator<LocationInformation> it = seqOf.iterator();
				if (it.hasNext()) {
					it.next().appendAsString(sb, indentLevel + 1);
					while (it.hasNext()) {
						sb.append(",\n");
						for (int i = 0; i < indentLevel + 1; i++) {
							sb.append("\t");
						}
						it.next().appendAsString(sb, indentLevel + 1);
					}
				}
			}

			sb.append("\n");
			for (int i = 0; i < indentLevel; i++) {
				sb.append("\t");
			}
			sb.append("}");
		}

	}

	public static class EvntLanesBlockedOrClosedNumber implements BerType, Serializable {

		private static final long serialVersionUID = 1L;

		public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
		private byte[] code = null;
		private List<BerInteger> seqOf = null;

		public EvntLanesBlockedOrClosedNumber() {
			seqOf = new ArrayList<BerInteger>();
		}

		public EvntLanesBlockedOrClosedNumber(byte[] code) {
			this.code = code;
		}

		public List<BerInteger> getBerInteger() {
			if (seqOf == null) {
				seqOf = new ArrayList<BerInteger>();
			}
			return seqOf;
		}

		@Override public int encode(OutputStream reverseOS) throws IOException {
			return encode(reverseOS, true);
		}

		public int encode(OutputStream reverseOS, boolean withTag) throws IOException {

			if (code != null) {
				reverseOS.write(code);
				if (withTag) {
					return tag.encode(reverseOS) + code.length;
				}
				return code.length;
			}

			int codeLength = 0;
			for (int i = (seqOf.size() - 1); i >= 0; i--) {
				codeLength += seqOf.get(i).encode(reverseOS, true);
			}

			codeLength += BerLength.encodeLength(reverseOS, codeLength);

			if (withTag) {
				codeLength += tag.encode(reverseOS);
			}

			return codeLength;
		}

		@Override public int decode(InputStream is) throws IOException {
			return decode(is, true);
		}

		public int decode(InputStream is, boolean withTag) throws IOException {
			int tlByteCount = 0;
			int vByteCount = 0;
			BerTag berTag = new BerTag();
			if (withTag) {
				tlByteCount += tag.decodeAndCheck(is);
			}

			BerLength length = new BerLength();
			tlByteCount += length.decode(is);
			int lengthVal = length.val;

			while (vByteCount < lengthVal || lengthVal < 0) {
				vByteCount += berTag.decode(is);

				if (lengthVal < 0 && berTag.equals(0, 0, 0)) {
					vByteCount += BerLength.readEocByte(is);
					break;
				}

				if (!berTag.equals(BerInteger.tag)) {
					throw new IOException("Tag does not match mandatory sequence of/set of component.");
				}
				BerInteger element = new BerInteger();
				vByteCount += element.decode(is, false);
				seqOf.add(element);
			}
			if (lengthVal >= 0 && vByteCount != lengthVal) {
				throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + lengthVal + " but has " + vByteCount);

			}
			return tlByteCount + vByteCount;
		}

		public void encodeAndSave(int encodingSizeGuess) throws IOException {
			ReverseByteArrayOutputStream reverseOS = new ReverseByteArrayOutputStream(encodingSizeGuess);
			encode(reverseOS, false);
			code = reverseOS.getArray();
		}

		@Override public String toString() {
			StringBuilder sb = new StringBuilder();
			appendAsString(sb, 0);
			return sb.toString();
		}

		public void appendAsString(StringBuilder sb, int indentLevel) {

			sb.append("{\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			if (seqOf == null) {
				sb.append("null");
			}
			else {
				Iterator<BerInteger> it = seqOf.iterator();
				if (it.hasNext()) {
					sb.append(it.next());
					while (it.hasNext()) {
						sb.append(",\n");
						for (int i = 0; i < indentLevel + 1; i++) {
							sb.append("\t");
						}
						sb.append(it.next());
					}
				}
			}

			sb.append("\n");
			for (int i = 0; i < indentLevel; i++) {
				sb.append("\t");
			}
			sb.append("}");
		}

	}

	public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);

	private byte[] code = null;
	private BerVisibleString trntMessageCreativeGeneralizedTime = null;
	private EvntLocationInformation evntLocationInformation = null;
	private BerEnum evntLocationTypeCode = null;
	private BerEnum evntLanesBlockedOrClosedCode = null;
	private EvntLanesBlockedOrClosedNumber evntLanesBlockedOrClosedNumber = null;
	private BerUTF8String evntLocationBeginNodeIdNumber = null;
	private BerInteger evntLocationLinearDistanceOffsetBeginNumber = null;
	private BerUTF8String evntLocationEndNodeIdNumber = null;
	private BerInteger evntLocationLinearDistanceOffsetEndNumber = null;
	private BerUTF8String evntLocationAdditionalInfoText = null;
	private BerEnum evntDescriptionTypeEventCode = null;
	private BerEnum evntDescriptionTypeSpecialEventCode = null;
	private BerUTF8String evntDescriptionDetourInformationText = null;
	private BerUTF8String evntDescriptionTypeEventOtherText = null;
	private BerUTF8String evntResponseAlternateRouteText = null;
	private BerEnum evntLanesShouldersBlockedCode = null;
	private BerVisibleString evntTimelinestarGeneralizedTime = null;
	private BerVisibleString evntTimelineEndGeneralizedTime = null;
	private BerInteger evntTimelineDurationTime = null;
	
	public EventIdentityRoadSide() {
	}

	public EventIdentityRoadSide(byte[] code) {
		this.code = code;
	}

	public void setTrntMessageCreativeGeneralizedTime(BerVisibleString trntMessageCreativeGeneralizedTime) {
		this.trntMessageCreativeGeneralizedTime = trntMessageCreativeGeneralizedTime;
	}

	public BerVisibleString getTrntMessageCreativeGeneralizedTime() {
		return trntMessageCreativeGeneralizedTime;
	}

	public void setEvntLocationInformation(EvntLocationInformation evntLocationInformation) {
		this.evntLocationInformation = evntLocationInformation;
	}

	public EvntLocationInformation getEvntLocationInformation() {
		return evntLocationInformation;
	}

	public void setEvntLocationTypeCode(BerEnum evntLocationTypeCode) {
		this.evntLocationTypeCode = evntLocationTypeCode;
	}

	public BerEnum getEvntLocationTypeCode() {
		return evntLocationTypeCode;
	}

	public void setEvntLanesBlockedOrClosedCode(BerEnum evntLanesBlockedOrClosedCode) {
		this.evntLanesBlockedOrClosedCode = evntLanesBlockedOrClosedCode;
	}

	public BerEnum getEvntLanesBlockedOrClosedCode() {
		return evntLanesBlockedOrClosedCode;
	}

	public void setEvntLanesBlockedOrClosedNumber(EvntLanesBlockedOrClosedNumber evntLanesBlockedOrClosedNumber) {
		this.evntLanesBlockedOrClosedNumber = evntLanesBlockedOrClosedNumber;
	}

	public EvntLanesBlockedOrClosedNumber getEvntLanesBlockedOrClosedNumber() {
		return evntLanesBlockedOrClosedNumber;
	}

	public void setEvntLocationBeginNodeIdNumber(BerUTF8String evntLocationBeginNodeIdNumber) {
		this.evntLocationBeginNodeIdNumber = evntLocationBeginNodeIdNumber;
	}

	public BerUTF8String getEvntLocationBeginNodeIdNumber() {
		return evntLocationBeginNodeIdNumber;
	}

	public void setEvntLocationLinearDistanceOffsetBeginNumber(BerInteger evntLocationLinearDistanceOffsetBeginNumber) {
		this.evntLocationLinearDistanceOffsetBeginNumber = evntLocationLinearDistanceOffsetBeginNumber;
	}

	public BerInteger getEvntLocationLinearDistanceOffsetBeginNumber() {
		return evntLocationLinearDistanceOffsetBeginNumber;
	}

	public void setEvntLocationEndNodeIdNumber(BerUTF8String evntLocationEndNodeIdNumber) {
		this.evntLocationEndNodeIdNumber = evntLocationEndNodeIdNumber;
	}

	public BerUTF8String getEvntLocationEndNodeIdNumber() {
		return evntLocationEndNodeIdNumber;
	}

	public void setEvntLocationLinearDistanceOffsetEndNumber(BerInteger evntLocationLinearDistanceOffsetEndNumber) {
		this.evntLocationLinearDistanceOffsetEndNumber = evntLocationLinearDistanceOffsetEndNumber;
	}

	public BerInteger getEvntLocationLinearDistanceOffsetEndNumber() {
		return evntLocationLinearDistanceOffsetEndNumber;
	}

	public void setEvntLocationAdditionalInfoText(BerUTF8String evntLocationAdditionalInfoText) {
		this.evntLocationAdditionalInfoText = evntLocationAdditionalInfoText;
	}

	public BerUTF8String getEvntLocationAdditionalInfoText() {
		return evntLocationAdditionalInfoText;
	}

	public void setEvntDescriptionTypeEventCode(BerEnum evntDescriptionTypeEventCode) {
		this.evntDescriptionTypeEventCode = evntDescriptionTypeEventCode;
	}

	public BerEnum getEvntDescriptionTypeEventCode() {
		return evntDescriptionTypeEventCode;
	}

	public void setEvntDescriptionTypeSpecialEventCode(BerEnum evntDescriptionTypeSpecialEventCode) {
		this.evntDescriptionTypeSpecialEventCode = evntDescriptionTypeSpecialEventCode;
	}

	public BerEnum getEvntDescriptionTypeSpecialEventCode() {
		return evntDescriptionTypeSpecialEventCode;
	}

	public void setEvntDescriptionDetourInformationText(BerUTF8String evntDescriptionDetourInformationText) {
		this.evntDescriptionDetourInformationText = evntDescriptionDetourInformationText;
	}

	public BerUTF8String getEvntDescriptionDetourInformationText() {
		return evntDescriptionDetourInformationText;
	}

	public void setEvntDescriptionTypeEventOtherText(BerUTF8String evntDescriptionTypeEventOtherText) {
		this.evntDescriptionTypeEventOtherText = evntDescriptionTypeEventOtherText;
	}

	public BerUTF8String getEvntDescriptionTypeEventOtherText() {
		return evntDescriptionTypeEventOtherText;
	}

	public void setEvntResponseAlternateRouteText(BerUTF8String evntResponseAlternateRouteText) {
		this.evntResponseAlternateRouteText = evntResponseAlternateRouteText;
	}

	public BerUTF8String getEvntResponseAlternateRouteText() {
		return evntResponseAlternateRouteText;
	}

	public void setEvntLanesShouldersBlockedCode(BerEnum evntLanesShouldersBlockedCode) {
		this.evntLanesShouldersBlockedCode = evntLanesShouldersBlockedCode;
	}

	public BerEnum getEvntLanesShouldersBlockedCode() {
		return evntLanesShouldersBlockedCode;
	}

	public void setEvntTimelinestarGeneralizedTime(BerVisibleString evntTimelinestarGeneralizedTime) {
		this.evntTimelinestarGeneralizedTime = evntTimelinestarGeneralizedTime;
	}

	public BerVisibleString getEvntTimelinestarGeneralizedTime() {
		return evntTimelinestarGeneralizedTime;
	}

	public void setEvntTimelineEndGeneralizedTime(BerVisibleString evntTimelineEndGeneralizedTime) {
		this.evntTimelineEndGeneralizedTime = evntTimelineEndGeneralizedTime;
	}

	public BerVisibleString getEvntTimelineEndGeneralizedTime() {
		return evntTimelineEndGeneralizedTime;
	}

	public void setEvntTimelineDurationTime(BerInteger evntTimelineDurationTime) {
		this.evntTimelineDurationTime = evntTimelineDurationTime;
	}

	public BerInteger getEvntTimelineDurationTime() {
		return evntTimelineDurationTime;
	}

	@Override public int encode(OutputStream reverseOS) throws IOException {
		return encode(reverseOS, true);
	}

	public int encode(OutputStream reverseOS, boolean withTag) throws IOException {

		if (code != null) {
			reverseOS.write(code);
			if (withTag) {
				return tag.encode(reverseOS) + code.length;
			}
			return code.length;
		}

		int codeLength = 0;
		if (evntTimelineDurationTime != null) {
			codeLength += evntTimelineDurationTime.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 18
			reverseOS.write(0x92);
			codeLength += 1;
		}
		
		if (evntTimelineEndGeneralizedTime != null) {
			codeLength += evntTimelineEndGeneralizedTime.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 17
			reverseOS.write(0x91);
			codeLength += 1;
		}
		
		if (evntTimelinestarGeneralizedTime != null) {
			codeLength += evntTimelinestarGeneralizedTime.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 16
			reverseOS.write(0x90);
			codeLength += 1;
		}
		
		if (evntLanesShouldersBlockedCode != null) {
			codeLength += evntLanesShouldersBlockedCode.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 15
			reverseOS.write(0x8F);
			codeLength += 1;
		}
		
		codeLength += evntResponseAlternateRouteText.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 14
		reverseOS.write(0x8E);
		codeLength += 1;
		
		if (evntDescriptionTypeEventOtherText != null) {
			codeLength += evntDescriptionTypeEventOtherText.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 13
			reverseOS.write(0x8D);
			codeLength += 1;
		}
		
		if (evntDescriptionDetourInformationText != null) {
			codeLength += evntDescriptionDetourInformationText.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 12
			reverseOS.write(0x8C);
			codeLength += 1;
		}
		
		if (evntDescriptionTypeSpecialEventCode != null) {
			codeLength += evntDescriptionTypeSpecialEventCode.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 11
			reverseOS.write(0x8B);
			codeLength += 1;
		}
		
		if (evntDescriptionTypeEventCode != null) {
			codeLength += evntDescriptionTypeEventCode.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 10
			reverseOS.write(0x8A);
			codeLength += 1;
		}
		
		if (evntLocationAdditionalInfoText != null) {
			codeLength += evntLocationAdditionalInfoText.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 9
			reverseOS.write(0x89);
			codeLength += 1;
		}
		
		if (evntLocationLinearDistanceOffsetEndNumber != null) {
			codeLength += evntLocationLinearDistanceOffsetEndNumber.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 8
			reverseOS.write(0x88);
			codeLength += 1;
		}
		
		if (evntLocationEndNodeIdNumber != null) {
			codeLength += evntLocationEndNodeIdNumber.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 7
			reverseOS.write(0x87);
			codeLength += 1;
		}
		
		if (evntLocationLinearDistanceOffsetBeginNumber != null) {
			codeLength += evntLocationLinearDistanceOffsetBeginNumber.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 6
			reverseOS.write(0x86);
			codeLength += 1;
		}
		
		if (evntLocationBeginNodeIdNumber != null) {
			codeLength += evntLocationBeginNodeIdNumber.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 5
			reverseOS.write(0x85);
			codeLength += 1;
		}
		
		if (evntLanesBlockedOrClosedNumber != null) {
			codeLength += evntLanesBlockedOrClosedNumber.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, CONSTRUCTED, 4
			reverseOS.write(0xA4);
			codeLength += 1;
		}
		
		codeLength += evntLanesBlockedOrClosedCode.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 3
		reverseOS.write(0x83);
		codeLength += 1;
		
		if (evntLocationTypeCode != null) {
			codeLength += evntLocationTypeCode.encode(reverseOS, false);
			// write tag: CONTEXT_CLASS, PRIMITIVE, 2
			reverseOS.write(0x82);
			codeLength += 1;
		}
		
		codeLength += evntLocationInformation.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, CONSTRUCTED, 1
		reverseOS.write(0xA1);
		codeLength += 1;
		
		codeLength += trntMessageCreativeGeneralizedTime.encode(reverseOS, false);
		// write tag: CONTEXT_CLASS, PRIMITIVE, 0
		reverseOS.write(0x80);
		codeLength += 1;
		
		codeLength += BerLength.encodeLength(reverseOS, codeLength);

		if (withTag) {
			codeLength += tag.encode(reverseOS);
		}

		return codeLength;

	}

	@Override public int decode(InputStream is) throws IOException {
		return decode(is, true);
	}

	public int decode(InputStream is, boolean withTag) throws IOException {
		int tlByteCount = 0;
		int vByteCount = 0;
		BerTag berTag = new BerTag();

		if (withTag) {
			tlByteCount += tag.decodeAndCheck(is);
		}

		BerLength length = new BerLength();
		tlByteCount += length.decode(is);
		int lengthVal = length.val;
		vByteCount += berTag.decode(is);

		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
			trntMessageCreativeGeneralizedTime = new BerVisibleString();
			vByteCount += trntMessageCreativeGeneralizedTime.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		else {
			throw new IOException("Tag does not match mandatory sequence component.");
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
			evntLocationInformation = new EvntLocationInformation();
			vByteCount += evntLocationInformation.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		else {
			throw new IOException("Tag does not match mandatory sequence component.");
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) {
			evntLocationTypeCode = new BerEnum();
			vByteCount += evntLocationTypeCode.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 3)) {
			evntLanesBlockedOrClosedCode = new BerEnum();
			vByteCount += evntLanesBlockedOrClosedCode.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		else {
			throw new IOException("Tag does not match mandatory sequence component.");
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) {
			evntLanesBlockedOrClosedNumber = new EvntLanesBlockedOrClosedNumber();
			vByteCount += evntLanesBlockedOrClosedNumber.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 5)) {
			evntLocationBeginNodeIdNumber = new BerUTF8String();
			vByteCount += evntLocationBeginNodeIdNumber.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 6)) {
			evntLocationLinearDistanceOffsetBeginNumber = new BerInteger();
			vByteCount += evntLocationLinearDistanceOffsetBeginNumber.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 7)) {
			evntLocationEndNodeIdNumber = new BerUTF8String();
			vByteCount += evntLocationEndNodeIdNumber.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 8)) {
			evntLocationLinearDistanceOffsetEndNumber = new BerInteger();
			vByteCount += evntLocationLinearDistanceOffsetEndNumber.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 9)) {
			evntLocationAdditionalInfoText = new BerUTF8String();
			vByteCount += evntLocationAdditionalInfoText.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 10)) {
			evntDescriptionTypeEventCode = new BerEnum();
			vByteCount += evntDescriptionTypeEventCode.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 11)) {
			evntDescriptionTypeSpecialEventCode = new BerEnum();
			vByteCount += evntDescriptionTypeSpecialEventCode.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 12)) {
			evntDescriptionDetourInformationText = new BerUTF8String();
			vByteCount += evntDescriptionDetourInformationText.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 13)) {
			evntDescriptionTypeEventOtherText = new BerUTF8String();
			vByteCount += evntDescriptionTypeEventOtherText.decode(is, false);
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 14)) {
			evntResponseAlternateRouteText = new BerUTF8String();
			vByteCount += evntResponseAlternateRouteText.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		else {
			throw new IOException("Tag does not match mandatory sequence component.");
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 15)) {
			evntLanesShouldersBlockedCode = new BerEnum();
			vByteCount += evntLanesShouldersBlockedCode.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 16)) {
			evntTimelinestarGeneralizedTime = new BerVisibleString();
			vByteCount += evntTimelinestarGeneralizedTime.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 17)) {
			evntTimelineEndGeneralizedTime = new BerVisibleString();
			vByteCount += evntTimelineEndGeneralizedTime.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 18)) {
			evntTimelineDurationTime = new BerInteger();
			vByteCount += evntTimelineDurationTime.decode(is, false);
			if (lengthVal >= 0 && vByteCount == lengthVal) {
				return tlByteCount + vByteCount;
			}
			vByteCount += berTag.decode(is);
		}
		
		if (lengthVal < 0) {
			if (!berTag.equals(0, 0, 0)) {
				throw new IOException("Decoded sequence has wrong end of contents octets");
			}
			vByteCount += BerLength.readEocByte(is);
			return tlByteCount + vByteCount;
		}

		throw new IOException("Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount);

	}

	public void encodeAndSave(int encodingSizeGuess) throws IOException {
		ReverseByteArrayOutputStream reverseOS = new ReverseByteArrayOutputStream(encodingSizeGuess);
		encode(reverseOS, false);
		code = reverseOS.getArray();
	}

	@Override public String toString() {
		StringBuilder sb = new StringBuilder();
		appendAsString(sb, 0);
		return sb.toString();
	}

	public void appendAsString(StringBuilder sb, int indentLevel) {

		sb.append("{");
		sb.append("\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (trntMessageCreativeGeneralizedTime != null) {
			sb.append("trntMessageCreativeGeneralizedTime: ").append(trntMessageCreativeGeneralizedTime);
		}
		else {
			sb.append("trntMessageCreativeGeneralizedTime: <empty-required-field>");
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (evntLocationInformation != null) {
			sb.append("evntLocationInformation: ");
			evntLocationInformation.appendAsString(sb, indentLevel + 1);
		}
		else {
			sb.append("evntLocationInformation: <empty-required-field>");
		}
		
		if (evntLocationTypeCode != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntLocationTypeCode: ").append(evntLocationTypeCode);
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (evntLanesBlockedOrClosedCode != null) {
			sb.append("evntLanesBlockedOrClosedCode: ").append(evntLanesBlockedOrClosedCode);
		}
		else {
			sb.append("evntLanesBlockedOrClosedCode: <empty-required-field>");
		}
		
		if (evntLanesBlockedOrClosedNumber != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntLanesBlockedOrClosedNumber: ");
			evntLanesBlockedOrClosedNumber.appendAsString(sb, indentLevel + 1);
		}
		
		if (evntLocationBeginNodeIdNumber != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntLocationBeginNodeIdNumber: ").append(evntLocationBeginNodeIdNumber);
		}
		
		if (evntLocationLinearDistanceOffsetBeginNumber != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntLocationLinearDistanceOffsetBeginNumber: ").append(evntLocationLinearDistanceOffsetBeginNumber);
		}
		
		if (evntLocationEndNodeIdNumber != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntLocationEndNodeIdNumber: ").append(evntLocationEndNodeIdNumber);
		}
		
		if (evntLocationLinearDistanceOffsetEndNumber != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntLocationLinearDistanceOffsetEndNumber: ").append(evntLocationLinearDistanceOffsetEndNumber);
		}
		
		if (evntLocationAdditionalInfoText != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntLocationAdditionalInfoText: ").append(evntLocationAdditionalInfoText);
		}
		
		if (evntDescriptionTypeEventCode != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntDescriptionTypeEventCode: ").append(evntDescriptionTypeEventCode);
		}
		
		if (evntDescriptionTypeSpecialEventCode != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntDescriptionTypeSpecialEventCode: ").append(evntDescriptionTypeSpecialEventCode);
		}
		
		if (evntDescriptionDetourInformationText != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntDescriptionDetourInformationText: ").append(evntDescriptionDetourInformationText);
		}
		
		if (evntDescriptionTypeEventOtherText != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntDescriptionTypeEventOtherText: ").append(evntDescriptionTypeEventOtherText);
		}
		
		sb.append(",\n");
		for (int i = 0; i < indentLevel + 1; i++) {
			sb.append("\t");
		}
		if (evntResponseAlternateRouteText != null) {
			sb.append("evntResponseAlternateRouteText: ").append(evntResponseAlternateRouteText);
		}
		else {
			sb.append("evntResponseAlternateRouteText: <empty-required-field>");
		}
		
		if (evntLanesShouldersBlockedCode != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntLanesShouldersBlockedCode: ").append(evntLanesShouldersBlockedCode);
		}
		
		if (evntTimelinestarGeneralizedTime != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntTimelinestarGeneralizedTime: ").append(evntTimelinestarGeneralizedTime);
		}
		
		if (evntTimelineEndGeneralizedTime != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntTimelineEndGeneralizedTime: ").append(evntTimelineEndGeneralizedTime);
		}
		
		if (evntTimelineDurationTime != null) {
			sb.append(",\n");
			for (int i = 0; i < indentLevel + 1; i++) {
				sb.append("\t");
			}
			sb.append("evntTimelineDurationTime: ").append(evntTimelineDurationTime);
		}
		
		sb.append("\n");
		for (int i = 0; i < indentLevel; i++) {
			sb.append("\t");
		}
		sb.append("}");
	}

}

