marshalling

How to return a long property as JSON string value with JAXB

巧了我就是萌 提交于 2020-01-04 04:11:12
问题 I have a Java class annotated with @XmlRootElement . This Java class has a long property ( private long id ) that I want to return to a JavaScript-client. I create the JSON as follows: MyEntity myInstance = new MyEntity("Benny Neugebauer", 2517564202727464120); StringWriter writer = new StringWriter(); JSONConfiguration config = JSONConfiguration.natural().build(); Class[] types = {MyEntity.class}; JSONJAXBContext context = new JSONJAXBContext(config, types); JSONMarshaller marshaller =

Marshalling error when caching models with date prior to 1900

情到浓时终转凉″ 提交于 2020-01-04 04:09:29
问题 I have some active record models which have a "published_on" attribute. When I attempt to cache models with a published_on date prior to 1/1/1900, I get an error such as: Marshalling error for key 'popular_products': year too big to marshal: 1300 UTC You are trying to cache a Ruby object which cannot be serialized to memcached. I can reproduce a similar error with ruby: irb(main)> Marshal.dump( Time.parse("1/1/1900") ) ArgumentError: year too big to marshal: 1899 UTC What's the right approach

Passing NON null-terminated strings to unmanaged code

僤鯓⒐⒋嵵緔 提交于 2020-01-04 04:07:08
问题 Consider the following struct to be sent over TCP to an unmanaged dll [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] public struct FooMessage { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 42)] public string foo; //More fields... } Using the following function (credit to Cheeso): public byte[] RawSerialize( T item ) { int rawSize = Marshal.SizeOf( typeof(T) ); IntPtr buffer = Marshal.AllocHGlobal( rawSize ); Marshal.StructureToPtr( item, buffer, false ); byte[]

How to marshal collection in c# to pass to native (C++) code

自古美人都是妖i 提交于 2020-01-03 14:17:52
问题 I am working on an enterprise application development. the entire application is developed in c++, except the UI, which is developed in c#, now its time to hookup the UI with c++ code. After detailed study i choose PInvoke in order to do so. All is successful, the only case where i stuck is that how can i pass collection to C++ code. e.g: C# Side Code List<string> lst = new List<string>(); lst.Add("1"); lst.Add("2"); lst.Add("3"); lst.Add("4"); C++ Side Code std::vector<std::string> vStr; Now

How to marshal collection in c# to pass to native (C++) code

回眸只為那壹抹淺笑 提交于 2020-01-03 14:17:08
问题 I am working on an enterprise application development. the entire application is developed in c++, except the UI, which is developed in c#, now its time to hookup the UI with c++ code. After detailed study i choose PInvoke in order to do so. All is successful, the only case where i stuck is that how can i pass collection to C++ code. e.g: C# Side Code List<string> lst = new List<string>(); lst.Add("1"); lst.Add("2"); lst.Add("3"); lst.Add("4"); C++ Side Code std::vector<std::string> vStr; Now

Is it possible to marshal ref parameters in SAFEARRAY

旧时模样 提交于 2020-01-03 07:44:33
问题 Here is my C# server method: public void Exec(out int status, string output) { status = 3; Console.WriteLine("Exec({0}, ...)", status); output = string.Format("Hello from .NET {0}", DateTime.Now); Console.WriteLine("Exec(..., {0})", output); } My C++ client is setting up and calling this method. This works fine, but the status and output variables don't appear to be chaining. It's as though they're being passed by value instead of by reference. Here's my client code: InitCLR(); LONG index = 0

Updating a C# array inside C++ without Marshal.Copy or Unsafe

喜欢而已 提交于 2020-01-03 05:40:08
问题 I am wanting to update an array that was created inside C#, and then pass a pointer to that array over to C++ and let C++ populate the indexes, to be used back in C#. Right now I am Using a Marshal.Copy() to accomplish this task, but I would like to avoid the potentially unnecessary copy, and call back to c++ to release the array. Is this even possible? These array are floats and ints, for geometric mesh data. My current usage (working and not what I want to use) C# IntPtr intptr=new IntPtr()

flask_restplus' marshal_with returns response with null values

最后都变了- 提交于 2020-01-03 05:17:07
问题 I am using flask_restplus to create a documented API. The marshal decorator controls what data actually gets rendered in your response, but I am having trouble rendering the data. I have the following code: kpis_model = api.model('kpis', { 'cpl_actual': fields.Integer(description='costo por lead total del mes actual'), 'cpl_anterior': fields.Integer(description='costo por lead total del mes anterior'), 'cpl_diferencia': fields.Integer(description='diferencia de cpl_actual y cpl_anterior') })

Pinvoke struct translation from C++

六月ゝ 毕业季﹏ 提交于 2020-01-03 02:52:07
问题 The following is a bit of C++ that is verified working: typedef struct { PVOID buffer; UINT32 length; } DATA_BUFFER; typedef struct { DATA_BUFFER TxBuf [1]; DATA_BUFFER RxBuf [1]; } JVM_COMM_BUFFER; UINT32 SendAndRecv( IN JHI_HANDLE handle, IN CHAR* AppId, INOUT JVM_COMM_BUFFER* pComm ); The following is my attempt to port that to C#: [StructLayout(LayoutKind.Sequential)] public struct DATA_BUFFER { public byte[] buffer; public uint length; } [StructLayout(LayoutKind.Sequential)] public

Using Marshal.Copy correctly

岁酱吖の 提交于 2020-01-02 08:02:29
问题 I have a working wrapper class for Dallmeier camera devices, It contains a callback method to receive the current YUV image. See details C# wrapper for array of three pointers. I have a button on my form that gets the YUV Image. The callback returns 'yuvData' which is an array of three pointers to Y, U, and V part of image. I then copy the three pointers into thier own pointer and then copy them into a byte array. The yuvCallback continues to run until I disconnect the camera. Am I using