marshalling
JAXB marshalling XMPP stanzas
How about the following?: Create a custom XMLStreamWriter that will treat all namespace declarations as default namespaces, and then marshal to that: ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLOutputFactory xof = XMLOutputFactory.newFactory(); XMLStreamWriter xsw = xof.createXMLStreamWriter(System.out); xsw = new MyXMLStreamWriter(xsw); m.marshal(iq, xsw); xsw.close(); MyXMLStreamWriter import java.util.Iterator; import javax.xml.namespace.NamespaceContext; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; public class MyXMLStreamWriter implements … Read more
What is Serialization?
Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network. Deserialization is the reverse process: turning a stream of bytes into an object in memory.
C++ .NET convert System::String to std::string
There is cleaner syntax if you’re using a recent version of .net #include “stdafx.h” #include <string> #include <msclr\marshal_cppstd.h> using namespace System; int main(array<System::String ^> ^args) { System::String^ managedString = “test”; msclr::interop::marshal_context context; std::string standardString = context.marshal_as<std::string>(managedString); return 0; } This also gives you better clean-up in the face of exceptions. There is an msdn article … Read more
Is it possible to get all arguments of a function as single object inside that function?
Use arguments. You can access it like an array. Use arguments.length for the number of arguments.
How to marshall and unmarshall a Parcelable to a byte array with help of Parcel?
First create a helper class ParcelableUtil.java: public class ParcelableUtil { public static byte[] marshall(Parcelable parceable) { Parcel parcel = Parcel.obtain(); parceable.writeToParcel(parcel, 0); byte[] bytes = parcel.marshall(); parcel.recycle(); return bytes; } public static Parcel unmarshall(byte[] bytes) { Parcel parcel = Parcel.obtain(); parcel.unmarshall(bytes, 0, bytes.length); parcel.setDataPosition(0); // This is extremely important! return parcel; } public static <T> … 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
How do you serialize an object in C++?
Talking about serialization, the boost serialization API comes to my mind. As for transmitting the serialized data over the net, I’d either use Berkeley sockets or the asio library. Edit: If you want to serialize your objects to a byte array, you can use the boost serializer in the following way (taken from the tutorial … Read more