/* (non-Javadoc)
@see com.emc.ecs.nfsclient.nfs.NfsRequest#marshalling(com.emc.ecs.nfsclient.rpc.Xdr)
515543
public void marshalling(Xdr xdr) {
        if ( !isBareTime() ) {
            xdr.putInt(_timeSettingType);
        }
        if ( captureTime() ) {
            xdr.putUnsignedInt(seconds);
            xdr.putUnsignedInt(nanoseconds);
        }
    }
8352
public void unmarshalling(Xdr xdr) throws RpcException {
        super.unmarshalling(xdr);
        if (stateIsOk()) {
            unmarshallingFileHandle(xdr);
            unmarshallingAttributes(xdr);
        }
        _directoryWccData = new NfsWccData(xdr);
    }
828458
private static DataNode marshalObject(Map<String, AbstractDataMarshaller<?>> marshallerMap, Object object) {
        //can't be null here because it is not resolved: meaning, it is an instance of an unknown class
        final Class<?> clazz = object.getClass();

        final AbstractDataMarshaller<Object> serializer = (AbstractDataMarshaller<Object>) marshallerMap.get(clazz.getCanonicalName());
        if (serializer != null) {
            final DataNode node = serializer.marshal(object);
            node.setObject(META_CLASS_NAME, serializer.getDataClassName());
            return node;
        }
        return null; //no marshaller - let others decide what to do with that info
    }
897083
public void unmarshalling(Xdr xdr) throws RpcException {
        super.unmarshalling(xdr);
        _fileWccData = new NfsWccData(xdr);
        if (stateIsOk()) {
            _verf = xdr.getLong();
            _log.trace("verf {}", _verf);
        }
    }
508729
public void marshall(MarshallLocation marshallLocation, Object val, String paramName) {
        marshallerRegistry().getMarshaller(marshallLocation, val).marshall(val, this, paramName);
    }
1338175
public void unmarshalling(Xdr xdr) throws RpcException {
        super.unmarshalling(xdr);
        _fromDirectoryWccData = new NfsWccData(xdr);
        _toDirectoryWccData = new NfsWccData(xdr);
    }
150097
public Marshaller getMarshaller(boolean reuse)
    throws JAXBException {
    if (!reuse || this.marshaller == null) {
      Marshaller marshaller = context.createMarshaller();
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
      marshaller.setProperty(Marshaller.JAXB_ENCODING,         "UTF-8");
      this.marshaller = marshaller;
    }
    return this.marshaller;
  }
183413
public void marshal(Object obj, HierarchicalStreamWriter writer,
			MarshallingContext context) {
		XExtension extension = (XExtension)obj;
		writer.addAttribute("uri", extension.getUri().toString());
	}
686676
@Override
  protected void marshallElementContent(XMLObject xmlObject, Element domElement) throws MarshallingException {

    // Find out if the our namespace already has been defined, and if so, get the prefix.
    //
    final String namespace = CurrentAddressType.TYPE_NAME.getNamespaceURI();
    Optional<String> _prefix = xmlObject.getNamespaceManager()
      .getNamespaces()
      .stream()
      .filter(n -> namespace.equals(n.getNamespaceURI()))
      .map(n -> n.getNamespacePrefix())
      .findFirst();
    String prefix = _prefix.isPresent() ? _prefix.get() : CurrentAddressType.TYPE_NAME.getPrefix();
    
    StringBuilder sb = new StringBuilder();

    final List<XMLObject> childXMLObjects = xmlObject.getOrderedChildren();
    if (childXMLObjects != null && childXMLObjects.size() > 0) {
      for (final XMLObject childXMLObject : childXMLObjects) {
        if (childXMLObject == null) {
          continue;
        }
        if (!(childXMLObject instanceof XSString)) {
          throw new MarshallingException("Unexpected type of child element - " + childXMLObject.getClass().getName());
        }
        XSString childString = (XSString) childXMLObject;
        if (childString.getValue() == null) {
          continue;
        }
        String localPart = childString.getElementQName().getLocalPart();
        sb.append(String.format("<%s:%s>%s</%s:%s>", prefix, localPart, childString.getValue(), prefix, localPart));
      }
    }
    if (sb.length() > 0) {
      byte[] bytes;
      try {
        bytes = sb.toString().getBytes("UTF-8");
      }
      catch (UnsupportedEncodingException e) {
        throw new MarshallingException(e);
      }
      String base64String = Base64Support.encode(bytes, true);
      ElementSupport.appendTextContent(domElement, base64String);
    }
  }
588239
@Deprecated
    public void marshallAsElement(AttributeDefinition attribute, ModelNode resourceModel, XMLStreamWriter writer) throws XMLStreamException {
        marshallAsElement(attribute, resourceModel, true, writer);
    }
295905
public static XContentBuilder marshall(RoleBean bean) throws StorageException {
        try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
            preMarshall(bean);
            builder
                .startObject()
                    .field("id", bean.getId())
                    .field("name", bean.getName())
                    .field("description", bean.getDescription())
                    .field("createdBy", bean.getCreatedBy())
                    .field("createdOn", bean.getCreatedOn().getTime())
                    .field("autoGrant", bean.getAutoGrant());
            Set<PermissionType> permissions = bean.getPermissions();
            if (permissions != null && !permissions.isEmpty()) {
                builder.array("permissions", permissions.toArray(new PermissionType[permissions.size()]));
            }
            builder.endObject();
            postMarshall(bean);
            return builder;
        } catch (IOException e) {
            throw new StorageException(e);
        }
    }
107812
protected Element marshallMessage(XMLObject message) throws MessageEncodingException {
        log.debug("Marshalling message");

        try {
            return XMLObjectSupport.marshall(message);
        } catch (MarshallingException e) {
            throw new MessageEncodingException("Error marshalling message", e);
        }
    }
1130238
public void unmarshalling(Xdr xdr) {
        _loaded = true;
        linkMaximum = xdr.getUnsignedInt();
        nameMaximum = xdr.getUnsignedInt();
        noTruncation = xdr.getBoolean();
        chownRestricted = xdr.getBoolean();
        caseInsensitive = xdr.getBoolean();
        casePreserving = xdr.getBoolean();
    }
203715
public String marshal(Object jaxbObject) {

		// Precondition, check that the jaxbContext is set!
    	if (jaxbContext == null) {
    		logger.error("Trying to marshal with a null jaxbContext, returns null. Check your configuration, e.g. jaxb-transformers!");
    		return null;
    	}

    	try {

            StringWriter writer = new StringWriter();
        	Marshaller marshaller = jaxbContext.createMarshaller();
        	if (marshallProps != null) {
	        	for (Entry<String, Object> entry : marshallProps.entrySet()) {
	        		marshaller.setProperty(entry.getKey(), entry.getValue());
				}
        	}
        	marshaller.marshal(jaxbObject, writer);

        	String xml = writer.toString();
        	
            if (logger.isDebugEnabled()) logger.debug("marshalled jaxb object of type {}, returns xml: {}",  jaxbObject.getClass().getSimpleName(), xml);
          
            return xml;
	    } catch (JAXBException e) {
	        throw new RuntimeException(e);
		}
    }
529804
public void marshal(Object obj, HierarchicalStreamWriter writer,
			MarshallingContext context) {
		XEvent event = (XEvent) obj;
		writer.addAttribute("xid", event.getID().toString());
		if (event.getAttributes().size() > 0) {
			writer.startNode("XAttributeMap");
			context.convertAnother(event.getAttributes(), XesXStreamPersistency.attributeMapConverter);
			writer.endNode();
		}

	}
610691
private void xdr_string(String s) {
    byte[] bytes = s.getBytes();
    int len = bytes.length;
    xdr_int(len);
    System.arraycopy(bytes, 0, buffer, offset, len);
    offset += len;
    pad();
  }
17003
public static void marshallByteArray(byte[] array, ObjectOutput out) throws IOException {
      final int size = array == null ? NULL_VALUE : array.length;
      marshallSize(out, size);
      if (size <= 0) {
         return;
      }
      out.write(array);
   }