/*
(non-Javadoc)

@see org.restcomm.protocols.ss7.map.primitives.MAPAsnPrimitive#encodeData (org.mobicents.protocols.asn.AsnOutputStream)
163640
public void encodeData(AsnOutputStream asnOs) throws MAPException {

        if (this.cugSubscriptionList == null)
            throw new MAPException("Error while encoding " + _PrimitiveName + ": cugSubscriptionList required.");
        if (this.cugSubscriptionList.size() > 10) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + ": Parameter cugSubscriptionList size must be from 0 to 10, found: " + this.cugSubscriptionList.size());
        }

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

        try {

            asnOs.writeTag(Tag.CLASS_UNIVERSAL, false, Tag.SEQUENCE);
            int posa = asnOs.StartContentDefiniteLength();
            for (CUGSubscription subscriptionItem : this.cugSubscriptionList) {
                ((CUGSubscriptionImpl) subscriptionItem).encodeAll(asnOs);
            }
            asnOs.FinalizeContent(posa);

            if (this.cugFeatureList != null) {
                asnOs.writeTag(Tag.CLASS_UNIVERSAL, false, Tag.SEQUENCE);
                int posb = asnOs.StartContentDefiniteLength();
                for (CUGFeature featureItem : this.cugFeatureList) {
                    ((CUGFeatureImpl) featureItem).encodeAll(asnOs);
                }
                asnOs.FinalizeContent(posb);
            }

            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);
        }
    }
269128
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        try {
            if (this.locationInformation) {
                asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _ID_locationInformation);
            }
        } catch (IOException e) {
            throw new MAPException("IOException when encoding parameter locationInformation: ", e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding parameter locationInformation: ", e);
        }

        try {
            if (this.subscriberState) {
                asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _ID_subscriberState);
            }
        } catch (IOException e) {
            throw new MAPException("IOException when encoding parameter subscriberState: ", e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding parameter subscriberState: ", e);
        }

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

        try {
            if (this.currentLocation) {
                asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _ID_currentLocation);
            }
        } catch (IOException e) {
            throw new MAPException("IOException when encoding parameter currentLocation: ", e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding parameter currentLocation: ", e);
        }

        try {
            if (this.requestedDomain != null) {
                asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _ID_requestedDomain, this.requestedDomain.getType());
            }
        } catch (IOException e) {
            throw new MAPException("IOException when encoding parameter requestedDomain: ", e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding parameter requestedDomain: ", e);
        }

        try {
            if (this.imei) {
                asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _ID_imei);
            }
        } catch (IOException e) {
            throw new MAPException("IOException when encoding parameter imei: ", e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding parameter imei: ", e);
        }

        try {
            if (this.msClassmark) {
                asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _ID_msclassmark);
            }
        } catch (IOException e) {
            throw new MAPException("IOException when encoding parameter msClassmark: ", e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding parameter msClassmark: ", e);
        }

        try {
            if (this.mnpRequestedInfo) {
                asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _ID_mnpRequestedInfo);
            }
        } catch (IOException e) {
            throw new MAPException("IOException when encoding parameter mnpRequestedInfo: ", e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding parameter mnpRequestedInfo: ", e);
        }
    }
758710
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.mSCNumber == null && this.sGSNNumber == null)
            throw new MAPException("Error when encoding " + _PrimitiveName + ": both mscNumber and sgsnNumber must not be null");
        if (this.mSCNumber != null && this.sGSNNumber != null)
            throw new MAPException("Error when encoding " + _PrimitiveName
                    + ": both mscNumber and sgsnNumber must not be not null");

        if (this.mSCNumber != null) {
            ((ISDNAddressStringImpl) this.mSCNumber).encodeData(asnOs);
        } else {
            ((ISDNAddressStringImpl) this.sGSNNumber).encodeData(asnOs);
        }
    }
1002084
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.areaType == null) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + " the mandatory parameter[areaType [0] AreaType] is not defined");
        }

        if (this.areaIdentification == null) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + " the mandatory parameter[areaIdentification [1] AreaIdentification] is not defined");
        }

        try {
            asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_areaType, this.areaType.getType());

            ((AreaIdentificationImpl) this.areaIdentification).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_areaIdentification);

        } 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;
    }
787854
func encodeData(o interface{}) (io.Reader, int, error) {
	if o == nil {
		return nil, 0, nil
	}
	buf, err := json.Marshal(&o)
	if err != nil {
		return nil, 0, err
	} else {
		return bytes.NewReader(buf), len(buf), nil
	}
}
202542
public static byte[] encode(final byte[] data) throws IOException {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        DeflaterOutputStream deflateOut = null;
        try {
            deflateOut = new DeflaterOutputStream(byteOut);
            deflateOut.write(data);
            deflateOut.close();
            byteOut.close();
            return byteOut.toByteArray();
        } finally {
            deflateOut.close();
            byteOut.close();
        }
    }
1337638
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.areaDefinition == null) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + " the mandatory parameter[areaDefinition [0] AreaDefinition] is not defined");
        }

        ((AreaDefinitionImpl) this.areaDefinition).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_areaDefinition);

        try {
            if (this.occurrenceInfo != null) {
                asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_OCCURRENCE_INFO, this.occurrenceInfo.getInfo());
            }

            if (this.intervalTime != null) {
                asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_INTERVAL_TIME, this.intervalTime);
            }

        } 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);
        }
    }
794518
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.horizontalAccuracy != null) {
            try {
                asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_HORIZONTAL_ACCURACY,
                        new byte[] { this.horizontalAccuracy.byteValue() });
            } catch (IOException e) {
                throw new MAPException("IOException when encoding parameter horizontalAccuracy: ", e);
            } catch (AsnException e) {
                throw new MAPException("AsnException when encoding parameter horizontalAccuracy: ", e);
            }
        }

        if (this.verticalCoordinateRequest) {
            try {
                asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_VERTICAL_COORDINATE_REQUEST);
            } catch (IOException e) {
                throw new MAPException("IOException when encoding parameter verticalCoordinateRequest: ", e);
            } catch (AsnException e) {
                throw new MAPException("IOException when encoding parameter verticalCoordinateRequest: ", e);
            }
        }

        if (this.verticalAccuracy != null) {
            try {
                asnOs.writeOctetString(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_VERTICAL_ACCURACY,
                        new byte[] { this.verticalAccuracy.byteValue() });
            } catch (IOException e) {
                throw new MAPException("IOException when encoding parameter verticalAccuracy: ", e);
            } catch (AsnException e) {
                throw new MAPException("AsnException when encoding parameter verticalAccuracy: ", e);
            }
        }

        if (this.responseTime != null) {
            ((ResponseTimeImpl) this.responseTime).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_RESPONSE_TIME);
        }

        if (this.extensionContainer != null) {
            ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_EXTENSION_CONTAINER);
        }
    }
438113
@Override
    public byte[] decode(final String data) {
        return data != null ? data.getBytes(CHARSET) : null;
    }
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);
        }
    }
857051
public void encodeData(AsnOutputStream asnOs) throws MAPException {

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

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

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

        try {

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

            asnOs.writeTag(Tag.CLASS_UNIVERSAL, false, Tag.SEQUENCE);
            int pos = asnOs.StartContentDefiniteLength();
            for (ExtCallBarringFeature featureItem : this.callBarringFeatureList) {
                ((ExtCallBarringFeatureImpl) featureItem).encodeAll(asnOs);
            }
            asnOs.FinalizeContent(pos);

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

        if (this.getProblem() == null)
            throw new EncodeException("Error encoding Reject: RejectProblem must not be null");

        try {
            // tag
            aos.writeTag(Tag.CLASS_PRIVATE, false, Reject._TAG_REJECT);
            int pos = aos.StartContentDefiniteLength();

            // correlationId
            byte[] buf;
            if (this.correlationId != null) {
                buf = new byte[1];
                buf[0] = (byte) (long) this.correlationId;
            } else {
                buf = new byte[0];
            }
            aos.writeOctetString(Tag.CLASS_PRIVATE, Component._TAG_INVOKE_ID, buf);

            // rejectProblem
            aos.writeInteger(Tag.CLASS_PRIVATE, Reject._TAG_REJECT_PROBLEM, this.rejectProblem.getType());

            // Empty parameter
            aos.writeTag(Tag.CLASS_PRIVATE, false, Parameter._TAG_SEQUENCE);
            aos.writeLength(0);

            aos.FinalizeContent(pos);

        } catch (IOException e) {
            throw new EncodeException("IOException while encoding Reject: " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new EncodeException("AsnException while encoding Reject: " + e.getMessage(), e);
        }
    }
1346895
@SuppressWarnings("unchecked")
    public static Map<String, Object> bytesToDocument(byte[] data) {
        return data != null && data.length > 0
                ? SerializationUtils.fromByteArrayFst(data, Map.class)
                : null;
    }
479335
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.externalAddress != null) {
            ((ISDNAddressStringImpl) this.externalAddress).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_EXTERNAL_ADDRESS);
        }

        if (this.extensionContainer != null) {
            ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_EXTENSION_CONTAINER);
        }
    }
1294237
private function encodeNonUtf8ToUtf8(array $serializedData)
    {
        $encodedKeys = [];
        $encodedData = [];
        foreach ($serializedData as $key => $value) {
            if (is_array($value)) {
                $value = $this->encodeNonUtf8ToUtf8($value);
            }

            if (!mb_check_encoding($key, 'UTF-8')) {
                $key = mb_convert_encoding($key, 'UTF-8', '8bit');
                $encodedKeys[$key] = (isset($encodedKeys[$key]) ? $encodedKeys[$key] : 0) | static::KEY_UTF8ENCODED;
            }

            if (is_string($value)) {
                if (!mb_check_encoding($value, 'UTF-8')) {
                    $value = mb_convert_encoding($value, 'UTF-8', '8bit');
                    $encodedKeys[$key] = (isset($encodedKeys[$key]) ? $encodedKeys[$key] : 0) | static::VALUE_UTF8ENCODED;
                }
            }

            $encodedData[$key] = $value;
        }

        if (!empty($encodedKeys)) {
            $encodedData[$this->encodingAnnotation] = $encodedKeys;
        }

        return $encodedData;
    }
1052068
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        if (this.locationEstimateType == null) {
            throw new MAPException("Error while encoding " + _PrimitiveName
                    + " the mandatory parameter LocationEstimateType is not defined");
        }

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

        if (this.deferredLocationEventType != null) {
            ((DeferredLocationEventTypeImpl) this.deferredLocationEventType).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_DEFERRED_LOCATION_EVET_TYPE);
        }
    }