/*
(non-Javadoc)

@see org.restcomm.protocols.ss7.map.api.primitives.MAPAsnPrimitive#encodeData
(org.mobicents.protocols.asn.AsnOutputStream)
482709
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.mlcNumber == null) {
            throw new MAPException("Encoding of " + _PrimitiveName
                    + " failed. Manadatory parameter mlcNumber [0] ISDN-AddressString is not set");
        }

        if (this.targetMS == null) {
            throw new MAPException("Encoding of " + _PrimitiveName
                    + " failed. Manadatory parameter targetMS [1] SubscriberIdentity is not set");
        }

        ((ISDNAddressStringImpl) this.mlcNumber).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_MLC_NUMBER);

        try {
            asnOs.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, _TAG_TARGET_MS);
            int pos = asnOs.StartContentDefiniteLength();
            ((SubscriberIdentityImpl) this.targetMS).encodeAll(asnOs);
            asnOs.FinalizeContent(pos);
        } catch (AsnException e) {
            throw new MAPException("AsnException while encoding parameter targetMS [1] SubscriberIdentity");
        }

        if (this.extensionContainer != null) {
            ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_EXTENSION_CONTAINER);
        }
    }
23826
public void encodeData(AsnOutputStream asnOs) throws MAPException {

        try {
            if (this.choice == null)
                throw new MAPException("Error while encoding the " + _PrimitiveName + ": choice is not defined");

            if ((this.choice == PSSubscriberStateChoice.psPDPActiveNotReachableForPaging || this.choice == PSSubscriberStateChoice.psPDPActiveReachableForPaging)
                    && this.pdpContextInfoList == null)
                throw new MAPException(
                        "Error while encoding the "
                                + _PrimitiveName
                                + ": for choice psPDPActiveNotReachableForPaging or psPDPActiveReachableForPaging - pdpContextInfoList must not be null");

            if ((this.choice == PSSubscriberStateChoice.netDetNotReachable) && this.netDetNotReachable == null)
                throw new MAPException("Error while encoding the " + _PrimitiveName
                        + ": for choice netDetNotReachable - netDetNotReachable must not be null");

            switch (this.choice) {
                case notProvidedFromSGSNorMME:
                case psDetached:
                case psAttachedNotReachableForPaging:
                case psAttachedReachableForPaging:
                    asnOs.writeNullData();
                    break;
                case psPDPActiveNotReachableForPaging:
                case psPDPActiveReachableForPaging:

                    if (this.pdpContextInfoList.size() < 1 || this.pdpContextInfoList.size() > 50)
                        throw new MAPException("Error while encoding " + _PrimitiveName
                                + ": pdpContextInfoList size must be from 1 to 50");

                    for (PDPContextInfo cii : this.pdpContextInfoList) {
                        PDPContextInfoImpl ci = (PDPContextInfoImpl) cii;
                        ci.encodeAll(asnOs);
                    }
                    break;
                case netDetNotReachable:
                    asnOs.writeIntegerData(this.netDetNotReachable.getCode());
                    break;
            }

        } catch (IOException e) {
            throw new MAPException("IOException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        }
    }
290353
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.areaList == null) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + " the mandatory parameter[areaList [0] AreaList] is not defined");
        }
        if (this.areaList.size() < 1 || this.areaList.size() > 10) {
            throw new MAPException("Error while encoding " + _PrimitiveName + " areaList size must be from 1 to 10, found: "
                    + this.areaList.size());
        }

        try {
            asnOs.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, _TAG_areaList);
            int pos = asnOs.StartContentDefiniteLength();
            for (Area ri : this.areaList) {
                if (ri != null) {
                    AreaImpl rii = (AreaImpl) ri;
                    rii.encodeAll(asnOs);
                }
            }
            asnOs.FinalizeContent(pos);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        }
    }
569272
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.lcsClientType == null)
            throw new MAPException("lcsClientType must not be null");

        try {
            asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_CLIENT_TYPE, this.lcsClientType.getType());
        } catch (IOException e) {
            throw new MAPException("IOException when encoding parameter lcsClientType: ", e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding parameter lcsClientType: ", e);
        }

        if (this.lcsClientExternalID != null) {
            // Encode lcsClientExternalID [1] LCSClientExternalID OPTIONAL,
            ((LCSClientExternalIDImpl) this.lcsClientExternalID).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_LCS_CLIENT_EXTERNAL_ID);
        }

        if (this.lcsClientDialedByMS != null) {
            // lcsClientDialedByMS [2] AddressString OPTIONAL,
            ((AddressStringImpl) this.lcsClientDialedByMS).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_LCS_CLIENT_DIALED_BY_MS);
        }

        if (this.lcsClientInternalID != null) {
            // lcsClientInternalID [3] LCSClientInternalID OPTIONAL,
            try {
                asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_CLIENT_INTERNAL_ID, this.lcsClientInternalID.getId());
            } catch (IOException e) {
                throw new MAPException("IOException when encoding parameter lcsClientInternalID: ", e);
            } catch (AsnException e) {
                throw new MAPException("AsnException when encoding parameter lcsClientInternalID: ", e);
            }
        }

        if (this.lcsClientName != null) {
            // lcsClientName [4] LCSClientName
            ((LCSClientNameImpl) this.lcsClientName).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_CLIENT_NAME);
        }

        if (this.lcsAPN != null) {
            // lcsAPN [5] APN OPTIONAL,
            ((APNImpl) this.lcsAPN).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_APN);
        }

        if (this.lcsRequestorID != null) {
            // lcsRequestorID [6] LCSRequestorID
            ((LCSRequestorIDImpl) this.lcsRequestorID).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LCS_REQUESTOR_ID);
        }
    }
1091100
public static String encode(byte[] data) {
        if (data.length == 0) {
            return "";
        }
        final byte[] bytes = copyOfRange(data, 0, data.length);
        // Count leading zeroes.
        int zeroCount = 0;
        while (zeroCount < bytes.length && bytes[zeroCount] == 0) {
            ++zeroCount;
        }
        // The actual encoding.
        byte[] temp = new byte[bytes.length * 2];
        int j = temp.length;

        int startAt = zeroCount;
        while (startAt < bytes.length) {
            byte mod = divmod58(bytes, startAt);
            if (bytes[startAt] == 0) {
                ++startAt;
            }
            temp[--j] = (byte) ALPHABET[mod];
        }

        // Strip extra '1' if there are some after decoding.
        while (j < temp.length && temp[j] == ALPHABET[0]) {
            ++j;
        }
        // Add as many leading '1' as there were leading zeros.
        while (--zeroCount >= 0) {
            temp[--j] = (byte) ALPHABET[0];
        }

        byte[] output = copyOfRange(temp, j, temp.length);
        try {
            return new String(output, "US-ASCII");
        } catch (UnsupportedEncodingException e) {
            throw new ApplicationException(e);  // Cannot happen.
        }
    }
841447
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.responseTimeCategory == null) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + " the mandatory parameter responseTimeCategory is not defined");
        }
        try {
            asnOs.writeInteger(Tag.CLASS_UNIVERSAL, Tag.ENUMERATED, this.responseTimeCategory.getCategory());
        } catch (IOException e) {
            throw new MAPException("IOException when encoding responseTimeCategory: ", e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding responseTimeCategory: ", e);
        }
    }
940639
@Override
    public byte[] asBytes() throws IOException {
        try (ServletInputStream stream = request.getInputStream()) {
            ByteArrayOutputStream array = new ByteArrayOutputStream(stream.available());
            return array.toByteArray();
        }
    }
33248
public void encode(ByteBuf out, CharSequence data) {
        ObjectUtil.checkNotNull(out, "out");
        if (data instanceof AsciiString) {
            AsciiString string = (AsciiString) data;
            try {
                encodeProcessor.out = out;
                string.forEachByte(encodeProcessor);
            } catch (Exception e) {
                PlatformDependent.throwException(e);
            } finally {
                encodeProcessor.end();
            }
        } else {
            encodeSlowPath(out, data);
        }
    }
751040
public static Map<String, Object> parseData(String data) {
		Map<String, Object> ret = new HashMap<String, Object>();
		String[] split = data.split("&");
		for (String s : split) {
			int idx = s.indexOf('=');
			try {
				if (idx != -1) {
					ret.put(URLDecoder.decode(s.substring(0, idx), "UTF-8"), URLDecoder.decode(s.substring(idx + 1), "UTF-8"));
				} else {
					ret.put(URLDecoder.decode(s, "UTF-8"), "true");
				}
			} catch (UnsupportedEncodingException e) {
				// Why.
			}
		}
		return ret;
	}
233838
public void encodeData(AsnOutputStream asnOs) throws MAPException {

        if (this.csgId == null)
            throw new MAPException("Parametr csgId must not be null");

        try {
            ((CSGIdImpl) this.csgId).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_csgId);

            if (this.extensionContainer != null)
                ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _ID_extensionContainer);

            byte[] buf = new byte[1];
            if (this.accessMode != null) {
                buf[0] = (byte) (int) this.accessMode;
                asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _ID_accessMode, buf);
            }

            if (this.cmi != null) {
                buf[0] = (byte) (int) this.cmi;
                asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _ID_cmi, buf);
            }
        } catch (IOException e) {
            throw new MAPException("IOException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        }
    }
186401
func (jt *Type) encodeData(data interface{}) ([]byte, error) {
	// Check the type of data
	dataType := reflect.TypeOf(data)
	if dataType != jt.dataType {
		return nil, fmt.Errorf("jobs: provided data was not of the correct type.\nExpected %s for Type %s, but got %s", jt.dataType, jt, dataType)
	}
	// Encode the data
	encodedData, err := encode(data)
	if err != nil {
		return nil, fmt.Errorf("jobs: error encoding data: %s", err.Error())
	}
	return encodedData, nil
}
189889
public void encodeData(AsnOutputStream asnOs) throws MAPException {

        if (this.interCugRestrictions == null)
            throw new MAPException("Error while encoding " + _PrimitiveName + ": interCugRestrictions required.");

        try {

            if (this.basicService != null)
                ((ExtBasicServiceCodeImpl) this.basicService).encodeAll(asnOs);

            if (this.preferentialCugIndicator != null)
                asnOs.writeInteger(this.preferentialCugIndicator);

            ((InterCUGRestrictionsImpl) this.interCugRestrictions).encodeAll(asnOs);

            if (this.extensionContainer != null)
                ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs);
        } catch (IOException e) {
            throw new MAPException("IOException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        }
    }
804578
static String base64(byte[] data) {
        ByteBuf encodedData = Unpooled.wrappedBuffer(data);
        ByteBuf encoded = Base64.encode(encodedData);
        String encodedString = encoded.toString(CharsetUtil.UTF_8);
        encoded.release();
        return encodedString;
    }
1048581
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.extensionContainer != null) {
            // extensionContainer ExtensionContainer OPTIONAL
            ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs);
        }

        if (this.naEsrk != null) {
            // na-ESRK [0] ISDN-AddressString OPTIONAL
            ((ISDNAddressStringImpl) this.naEsrk).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_NA_ESRK);
        }

        if (this.naEsrd != null) {
            // na-ESRD [1] ISDN-AddressString OPTIONAL ,
            ((ISDNAddressStringImpl) this.naEsrd).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_NA_ESRD);
        }
    }
1343842
public void encodeData(AsnOutputStream asnOs) throws MAPException {

        if (this.ssCode == null)
            throw new MAPException("Error while encoding " + _PrimitiveName + ": ssCode required.");

        if (this.forwardingFeatureList == null)
            throw new MAPException("Error while encoding " + _PrimitiveName + ": forwardingFeatureList required.");

        if (this.forwardingFeatureList.size() < 1 || this.forwardingFeatureList.size() > 32) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + ": Parameter forwardingFeatureList size must be from 1 to 32, found: "
                    + this.forwardingFeatureList.size());
        }

        try {

            ((SSCodeImpl) this.ssCode).encodeAll(asnOs);

            asnOs.writeTag(Tag.CLASS_UNIVERSAL, false, Tag.SEQUENCE);
            int pos = asnOs.StartContentDefiniteLength();
            for (ExtForwFeature featureItem : this.forwardingFeatureList) {
                ((ExtForwFeatureImpl) featureItem).encodeAll(asnOs);
            }
            asnOs.FinalizeContent(pos);

            if (this.extensionContainer != null)
                ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _TAG_extensionContainer);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        }
    }
882216
public void encode(AsnOutputStream aos) throws EncodeException {

        try {
            if (this.isInteger()) {
                aos.writeInteger(Tag.CLASS_PRIVATE, ApplicationContext._TAG_INTEGER, integerVal);
            } else if (this.isObjectID()) {
                aos.writeObjectIdentifier(Tag.CLASS_PRIVATE, ApplicationContext._TAG_OBJECT_ID, this.oidVal);
            } else {
                throw new EncodeException("Error while encoding ApplicationContextName: Neither OId nor Integer value is set");
            }

        } catch (IOException e) {
            throw new EncodeException("IOException while encoding ApplicationContextName: " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new EncodeException("AsnException while encoding ApplicationContextName: " + e.getMessage(), e);
        }
    }
773773
public void encodeData(AsnOutputStream asnOs) throws MAPException {

        if (this.cellGlobalIdOrServiceAreaIdFixedLength == null && this.laiFixedLength == null)
            throw new MAPException(
                    "Error while encoding the CellGlobalIdOrServiceAreaIdOrLAI: both cellGlobalIdOrServiceAreaIdFixedLength and laiFixedLength are not defined");

        if (this.cellGlobalIdOrServiceAreaIdFixedLength != null) {
            ((CellGlobalIdOrServiceAreaIdFixedLengthImpl) this.cellGlobalIdOrServiceAreaIdFixedLength).encodeData(asnOs);
        } else {
            ((LAIFixedLengthImpl) this.laiFixedLength).encodeData(asnOs);
        }
    }