marshalling

How do you marshal a sql.NullString such that the output is flattened to give just the value in go?

时间秒杀一切 提交于 2020-06-15 06:43:09
问题 Given a go struct type Company struct { ID int `json:"id"` Abn sql.NullString `json:"abn,string"` } when marshalled with something like this company := &Company{} company.ID = 68 company.Abn = "SomeABN" result, err := json.Marshal(company) the result is { "id": "68", "abn": { "String": "SomeABN", "Valid": true } } The result desired is { "id": "68", "abn": "SomeABN" } I've tried explicitly stating that Abn is a string. Abn sql.NullString `json:"abn,string"` which did not change the result.

Is there generally a noticeable performance hit when calling PInvoke on Win32 / COM methods?

狂风中的少年 提交于 2020-05-24 10:12:20
问题 I'm wondering whether anyone has a decent explanation or overview on the negative aspects of using DLLImport / PInvoke on Win32 methods from managed .Net code? I plan to make use of various Win32 methods and would like to have a greater understanding on the negative implications of doing so. Thanks, Brian. 回答1: According to MSDN - Calling Native Functions from Managed Code PInvoke has an overhead of between 10 and 30 x86 instructions per call. In addition to this fixed cost, marshaling

How can I ignore a field when marshalling a structure with P/Invoke

£可爱£侵袭症+ 提交于 2020-05-12 11:30:20
问题 I want to marshal a structure for use with P/Invoke, but this struct contains a field that is only relevant to my managed code, so I don't want it to be marshaled since it doesn't belong in the native structure. Is it even possible ? I was looking for an attribute similar to NonSerialized for serialization, but it doesn't seem to exist... struct MyStructure { int foo; int bar; [NotMarshaled] // This attribute doesn't exist, but that's the kind of thing I'm looking for... int ignored; } Any

C# Marshalling question

大憨熊 提交于 2020-02-24 11:56:27
问题 Based on suggestions from svick, I believe I can substancially simplify my post and question. Below, is some complete code that demonstrates my problem and question, namely marshalling bytes to structures does not work the way I'd expect... In the case of an object with two arrays seperated by another primitive, my object is not being marshalled to bytes the way I'd expect. Although I specify "Sequential", the two byte[] arrays are put in the byte array first, with the uint following. What is

Unmarshalling Hangs on Open Socket

坚强是说给别人听的谎言 提交于 2020-02-24 11:14:26
问题 I've written a runnable network class that listens on a socket and unmarshalls the input. It also can write to the socket with a marshalled object. An issue arises because the socket remains open (in order to allow later communication between client and host) - this causes the unmarshalling of the input stream to hang. I've tried writing XMLStreamConstants.END_DOCUMENT from the sender side but this causes an error unmarshalling instead of hanging. Here's some of the code for the network class

How to exclude an instance variable from marshal dump

旧时模样 提交于 2020-02-08 01:44:08
问题 My object contains an instance variable that point to a File object amongst several other attributes. Because of this Marshal cannot serialize it. How can I write a bespoke dump method so to exclude only that instance variable? class Area attr_accessor :area attr_reader :several_other_attributes ........ def initialize(name) @area = name @several_other_attributes = .... @log = File.open( 'test.log', 'w') end end 回答1: You can very easily write a marshal_dump and marshal_load method that

Attach to existing Excel Instance

安稳与你 提交于 2020-02-02 05:47:29
问题 I'm trying to determine whether or not an instance of Excel of running with a particular file open, and if so attach to it so I can control that instance. I've searched around and the majority of what I've got have come from this question. It has a reference to another site, but unfortunately it's dead for me so I cannot read up on it. My code so far is; //Is Excel open? if (Process.GetProcessesByName("EXCEL").Length != 0) { Process[] processes = Process.GetProcesses(); foreach (Process

Does proxy/stub expose the interface?

血红的双手。 提交于 2020-01-26 03:26:46
问题 Suppose I introduced a COM interface and don't want any third party to use it. I have full control over the sources of the COM component and the IDL file that holds the interface definition. My COM component will need marshalling stuff fro that interface, so I'll need to either implement IMarshal or provide a typelib or provide a proxy/stub. Obviously if I provide a typelib anyone can inspect it and find what my interface is and how it can be used. That's not what I want. What if I use proxy

Marshal.PtrToStructure in Silverlight

拟墨画扇 提交于 2020-01-25 10:43:46
问题 I got a Silverlight 5 assignment,but I struck in half way.Let me explain. My Code which works good in Windows Form (.Net framework 4) [DllImport("LiteSDK.dll", CharSet = CharSet.Ansi, EntryPoint = "GetAllUserInfo")] public static extern int GetAllUserInfo(int handle, IntPtr userHdr, ref int numOfUser); public struct BS2UserHdr { public enum ENUM { DS_MAX_NAME_LEN = 48, DS_MAX_PASSWORD_LEN = 16, DS_MIN_PASSWORD_LEN = 4, DS_TEMPLATE_SIZE = 384, DS_FACE_TEMPLATE_SIZE = 2284, MAX_FINGER = 10, MAX

Exporting a subset of a out-of-proc COM server by using an in-proc-server

允我心安 提交于 2020-01-24 17:33:07
问题 I implemented an out-of-proc COM server (implemented in a Service). I don't want other applications to access all the functionality in the COM server, so I developed an in-proc server (DLL) which would talk to the out-of-proc server. Because I don't want the interfaces in the out-of-proc COM server to be accessed directly, I don't embed the type library with the Service so I thought I could use #import and have access to the COM server through the TLB. However, when I try in my in-proc-server