How to marshal multi-dimensional arrays

By this discription about Blittable and Non-Blittable Types in the link below you could try the System.Double in place of float, because they do not require conversion when they are passed between managed and unmanaged code wich means no more special handling by the interop marshaler with a plus in performance: https://msdn.microsoft.com/en-us/library/75dwhxf7%28v=vs.110%29.aspx I did a … Read more

What input will cause golang’s json.Marshal to return an error?

Just to complement Jonathan’s answer, the json.Marshal function can return two types of errors: UnsupportedTypeError or UnsupportedValueError The first one can be caused, as Jonathan said by trying to Marshal an invalid type: _, err := json.Marshal(make(chan int)) _, ok := err.(*json.UnsupportedTypeError) // ok == true On the other hand you can also have the … Read more

What is marshalling? What is happening when something is “marshalled?”

Computations often need to move data from one site to another, and don’t have any shared memory. So one computation sends a message containing the data to the other. How should that data, if it is arbitrarily complicated, be sent in a message? Marshalling is the process of converting a data field, or an entire … Read more

How do you specify the date format used when JAXB marshals xsd:dateTime?

You can use an XmlAdapter to customize how a date type is written to XML. package com.example; import java.text.SimpleDateFormat; import java.util.Date; import javax.xml.bind.annotation.adapters.XmlAdapter; public class DateAdapter extends XmlAdapter<String, Date> { private final SimpleDateFormat dateFormat = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”); @Override public String marshal(Date v) throws Exception { synchronized (dateFormat) { return dateFormat.format(v); } } @Override public … Read more

Reading a C/C++ data structure in C# from a byte array

From what I can see in that context, you don’t need to copy SomeByteArray into a buffer. You simply need to get the handle from SomeByteArray, pin it, copy the IntPtr data using PtrToStructure and then release. No need for a copy. That would be: NewStuff ByteArrayToNewStuff(byte[] bytes) { GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); try … Read more

Marshaling – what is it and why do we need it?

Because different languages and environments have different calling conventions, different layout conventions, different sizes of primitives (cf. char in C# and char in C), different object creation/destruction conventions, and different design guidelines. You need a way to get the stuff out of managed land an into somewhere where unmanaged land can see and understand it … Read more

Convert Python ElementTree to string

Element objects have no .getroot() method. Drop that call, and the .tostring() call works: xmlstr = ElementTree.tostring(et, encoding=’utf8′, method=’xml’) You only need to use .getroot() if you have an ElementTree instance. Other notes: This produces a bytestring, which in Python 3 is the bytes type. If you must have a str object, you have two … Read more

JAXB creating context and marshallers cost

Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group. JAXBContext is thread safe and should only be created once and reused to avoid the cost of initializing the metadata multiple times. Marshaller and Unmarshaller are not thread safe, but are lightweight to create and could be created … Read more

tech