/*
(non-Javadoc)

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

        if (this.networkNodeNumber == null) {
            throw new MAPException(
                    "Error while encoding LCSLocationInfo the mandatory parameter networkNode-Number ISDN-AddressString is not defined");
        }

        ((ISDNAddressStringImpl) this.networkNodeNumber).encodeAll(asnOs);

        if (this.lmsi != null) {
            // lmsi [0] LMSI OPTIONAL,
            ((LMSIImpl) this.lmsi).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_LMSI);
        }

        if (this.extensionContainer != null) {
            // extensionContainer [1] ExtensionContainer OPTIONAL,
            ((MAPExtensionContainerImpl) this.extensionContainer).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_EXTENSION_CONTAINER);
        }

        if (this.gprsNodeIndicator) {
            // gprsNodeIndicator [2] NULL OPTIONAL,
            try {
                asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _TAG_GPRS_NODE_IND);
            } catch (IOException e) {
                throw new MAPException(
                        "Error while encoding LCSLocationInfo the optional parameter gprsNodeIndicator encoding failed ", e);
            } catch (AsnException e) {
                throw new MAPException(
                        "Error while encoding LCSLocationInfo the optional parameter gprsNodeIndicator encoding failed ", e);
            }
        }

        if (this.additionalNumber != null) {
            // additional-Number [3] Additional-Number OPTIONAL,
            try {
                asnOs.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, _TAG_ADDITIONAL_NUMBER);
            } catch (AsnException e) {
                throw new MAPException("AsnException while encoding parameter additional-Number");
            }

            int pos = asnOs.StartContentDefiniteLength();
            ((AdditionalNumberImpl) this.additionalNumber).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    ((AdditionalNumberImpl) this.additionalNumber).getTag());
            asnOs.FinalizeContent(pos);
        }

        if (this.supportedLCSCapabilitySets != null) {
            // supportedLCS-CapabilitySets [4] SupportedLCS-CapabilitySets
            // OPTIONAL,
            ((SupportedLCSCapabilitySetsImpl) this.supportedLCSCapabilitySets).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_SUPPORTED_LCS_CAPBILITY_SET);
        }

        if (this.additionalLCSCapabilitySets != null) {
            // additional-LCS-CapabilitySets [5] SupportedLCS-CapabilitySets
            // OPTIONAL
            ((SupportedLCSCapabilitySetsImpl) this.additionalLCSCapabilitySets).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                    _TAG_ADDITIONAL_LCS_CAPBILITY_SET);
        }

        if (this.mmeName != null) {
            ((DiameterIdentityImpl) this.mmeName).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_mme_Name);
        }
        if (this.aaaServerName != null) {
            ((DiameterIdentityImpl) this.aaaServerName).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_aaa_Server_Name);
        }
    }
494778
public void encodeData(AsnOutputStream asnOs) throws MAPException {

        int cnt = 0;
        if (this.forwardingInfo != null)
            cnt++;
        if (this.callBarringInfo != null)
            cnt++;
        if (this.cugInfo != null)
            cnt++;
        if (this.ssData != null)
            cnt++;
        if (this.emlppInfo != null)
            cnt++;

        if (cnt != 1)
            throw new MAPException("Error while encoding " + _PrimitiveName + ": one and only one choice is required.");

        if (this.forwardingInfo != null) {
            ((ExtForwInfoImpl) this.forwardingInfo).encodeData(asnOs);
            return;
        }

        if (this.callBarringInfo != null) {
            ((ExtCallBarInfoImpl) this.callBarringInfo).encodeData(asnOs);
            return;
        }

        if (this.cugInfo != null) {
            ((CUGInfoImpl) this.cugInfo).encodeData(asnOs);
            return;
        }

        if (this.ssData != null) {
            ((ExtSSDataImpl) this.ssData).encodeData(asnOs);
            return;
        }

        if (this.emlppInfo != null) {
            ((EMLPPInfoImpl) this.emlppInfo).encodeData(asnOs);
            return;
        }
    }
1215079
@Nonnull
  public static byte [] getSerializedByteArray (@Nonnull final Serializable aData)
  {
    ValueEnforcer.notNull (aData, "Data");

    try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ())
    {
      // Convert to byte array
      try (final ObjectOutputStream aOOS = new ObjectOutputStream (aBAOS))
      {
        aOOS.writeObject (aData);
      }

      // Main sending
      return aBAOS.toByteArray ();
    }
    catch (final NotSerializableException ex)
    {
      throw new IllegalArgumentException ("Not serializable: " + ex.getMessage (), ex);
    }
    catch (final IOException ex)
    {
      throw new IllegalArgumentException ("Failed to write serializable object " +
                                          aData +
                                          " of type " +
                                          aData.getClass ().getName (),
                                          ex);
    }
  }
111956
@Nullable protected String encode(@Nullable byte[] data) {
    return data == null ? null : Base64.getUrlEncoder().encodeToString(data);
  }
448851
public static byte[] encodeLZ(String data, String dictionary) {
    byte[] asBytes = new byte[0];
    try {
      asBytes = data.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    }
    return encodeLZ(asBytes, dictionary);
  }
67540
@SuppressWarnings("AssignmentToForLoopParameter")
    public static String encode(final byte[] data) {
        final int len = data.length;
        final StringBuilder result = new StringBuilder((len / 3 + 1) * 4);
        int bte;
        int index;

        for (int i = 0; i < len; i++) {

            bte = data[i];

            // First 6 bits
            index = bte >> 2 & MASK_6;
            result.append(CHAR_TABLE.charAt(index));

            // Last 2 bits plus 4 from next byte
            index = bte << 4 & MASK_6;

            if (++i < len) {
                bte = data[i];
                index |= bte >> 4 & MASK_4;
            }
            result.append(CHAR_TABLE.charAt(index));

            // 4 + 2 from next
            if (i < len) {
                index = bte << 2 & MASK_6;
                if (++i < len) {
                    bte = data[i];
                    index |= bte >> 6 & MASK_2;
                }
                result.append(CHAR_TABLE.charAt(index));
            } else {
                i++;
                result.append(CHAR_TABLE.charAt(64));
            }
            if (i < len) {
                index = bte & MASK_6;
                result.append(CHAR_TABLE.charAt(index));
            } else {
                result.append(CHAR_TABLE.charAt(64));
            }
        }

        return result.toString();
    }
726771
public void encodeData(AsnOutputStream asnOs) throws MAPException {
        try {

            if (this.locationInformation != null)
                ((LocationInformationImpl) this.locationInformation).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_locationInformation);

            if (this.subscriberState != null) {
                asnOs.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, _ID_subscriberState);
                int pos = asnOs.StartContentDefiniteLength();
                ((SubscriberStateImpl) this.subscriberState).encodeAll(asnOs);
                asnOs.FinalizeContent(pos);
            }

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

            if (this.locationInformationGPRS != null)
                ((LocationInformationGPRSImpl) this.locationInformationGPRS).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _ID_locationInformationGPRS);

            if (this.psSubscriberState != null) {
                asnOs.writeTag(Tag.CLASS_CONTEXT_SPECIFIC, false, _ID_psSubscriberState);
                int pos = asnOs.StartContentDefiniteLength();
                ((PSSubscriberStateImpl) this.psSubscriberState).encodeAll(asnOs);
                asnOs.FinalizeContent(pos);
            }

            if (this.imei != null)
                ((IMEIImpl) this.imei).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_imei);

            if (this.msClassmark2 != null)
                ((MSClassmark2Impl) this.msClassmark2).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_msclassmark2);

            if (this.gprsMSClass != null)
                ((GPRSMSClassImpl) this.gprsMSClass).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_gprsMSClass);

            if (this.mnpInfoRes != null)
                ((MNPInfoResImpl) this.mnpInfoRes).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_mnpInfoRes);

        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding " + _PrimitiveName + ": " + e.getMessage(), e);
        }
    }
371103
func (enc *HTTPEncoder) EncodeData(data []byte) error {
	setContentType(enc.writer, ContentBinary)

	_, err := enc.writer.Write(data)
	if err != nil {
		http.Error(enc.writer, fmt.Sprintf("Unable to encode binary data: %s", err.Error()), http.StatusInternalServerError)
	}
	return err
}
513644
public void encodeData(AsnOutputStream asnOs) throws MAPException {

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

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

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

        try {

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

            ((ExtSSStatusImpl) this.ssStatus).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _TAG_ss_Status);

            if (this.ssSubscriptionOption != null) {
                ((SSSubscriptionOptionImpl) this.ssSubscriptionOption).encodeAll(asnOs);
            }

            if (this.basicServiceGroupList != null) {
                asnOs.writeTag(Tag.CLASS_UNIVERSAL, false, Tag.SEQUENCE);
                int pos = asnOs.StartContentDefiniteLength();
                for (ExtBasicServiceCode serviceItem : this.basicServiceGroupList) {
                    ((ExtBasicServiceCodeImpl) serviceItem).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);
        }
    }
269653
public void encodeAll(AsnOutputStream asnOs) throws MAPException {
        this.encodeAll(asnOs, Tag.CLASS_UNIVERSAL, Tag.STRING_BIT);
    }
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);
        }
    }
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;
	}
1346895
@SuppressWarnings("unchecked")
    public static Map<String, Object> bytesToDocument(byte[] data) {
        return data != null && data.length > 0
                ? SerializationUtils.fromByteArrayFst(data, Map.class)
                : null;
    }
845094
@Override
  public T decode(final byte[] data) {
    final WakeTuplePBuf tuple;
    try {
      tuple = WakeTuplePBuf.parseFrom(data);
    } catch (final InvalidProtocolBufferException e) {
      e.printStackTrace();
      throw new RemoteRuntimeException(e);
    }

    final String className = tuple.getClassName();
    final byte[] message = tuple.getData().toByteArray();
    final Class<?> clazz;
    try {
      clazz = Class.forName(className);
    } catch (final ClassNotFoundException e) {
      e.printStackTrace();
      throw new RemoteRuntimeException(e);
    }
    return clazzToDecoderMap.get(clazz).decode(message);
  }
547449
public static String encode(byte[] data)
  {
	  StringBuffer result = new StringBuffer();

    for (int i = 0; i < data.length; i++) {
	    result.append(trans[(data[i] >> 4) & 0xf]);
	    result.append(trans[data[i] & 0xf]);
	  }

    return result.toString();
  }
328653
public void encodeData(AsnOutputStream asnOs) throws MAPException {

        if (this.pdpType == null || this.qosSubscribed == null || this.apn == null) {
            throw new MAPException("pdpType, qosSubscribed and apn parameters must not be null");
        }

        try {
            asnOs.writeInteger((int) this.pdpContextId);

            ((PDPTypeImpl) this.pdpType).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_pdp_Type);

            if (this.pdpAddress != null)
                ((PDPAddressImpl) this.pdpAddress).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_pdp_Address);

            ((QoSSubscribedImpl) this.qosSubscribed).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_QoS_Subscribed);

            if (this.vplmnAddressAllowed)
                asnOs.writeNull(Tag.CLASS_CONTEXT_SPECIFIC, _ID_vplmnAddressAllowed);

            ((APNImpl) this.apn).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_apn);

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

            if (this.extQoSSubscribed != null)
                ((ExtQoSSubscribedImpl) this.extQoSSubscribed).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _ID_ext_QoS_Subscribed);

            if (this.chargingCharacteristics != null)
                ((ChargingCharacteristicsImpl) this.chargingCharacteristics).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _ID_pdp_ChargingCharacteristics);

            if (this.ext2QoSSubscribed != null)
                ((Ext2QoSSubscribedImpl) this.ext2QoSSubscribed).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _ID_ext2_QoS_Subscribed);

            if (this.ext3QoSSubscribed != null)
                ((Ext3QoSSubscribedImpl) this.ext3QoSSubscribed).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _ID_ext3_QoS_Subscribed);

            if (this.ext4QoSSubscribed != null)
                ((Ext4QoSSubscribedImpl) this.ext4QoSSubscribed).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _ID_ext4_QoS_Subscribed);

            if (this.apnoiReplacement != null)
                ((APNOIReplacementImpl) this.apnoiReplacement).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC,
                        _ID_apn_oi_Replacement);

            if (this.extpdpType != null)
                ((ExtPDPTypeImpl) this.extpdpType).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_ext_pdp_Type);

            if (this.extpdpAddress != null)
                ((PDPAddressImpl) this.extpdpAddress).encodeAll(asnOs, Tag.CLASS_CONTEXT_SPECIFIC, _ID_ext_pdp_Address);

            if (this.sipToPermission != null)
                asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _ID_sipto_Permission, this.sipToPermission.getCode());

            if (this.lipaPermission != null)
                asnOs.writeInteger(Tag.CLASS_CONTEXT_SPECIFIC, _ID_lipa_Permission, this.lipaPermission.getCode());

        } catch (IOException e) {
            throw new MAPException("IOException when encoding PDPContext : " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new MAPException("AsnException when encoding PDPContext : " + 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);
        }
    }