marshalling

Passing a struct pointer as a parameter in C#

六眼飞鱼酱① 提交于 2020-08-24 21:58:25
问题 I have a function in C++ that I exported to a DLL. I contains a struct pointer as one of the parameters. I need to use this function in C#, so I used DLLImport for the function and recreated the struct in C# using StructLayout. I've tried passing in the parameter using ref as well as tried Marshaling it in using MarshalAs(UnmangedType.Struct) and Marshal.PtrToStructure. The parameter still isn't passing correctly. Example: [DllImport("testdll.dll")] public static extern int getProduct(int

Passing a struct pointer as a parameter in C#

喜夏-厌秋 提交于 2020-08-24 21:52:05
问题 I have a function in C++ that I exported to a DLL. I contains a struct pointer as one of the parameters. I need to use this function in C#, so I used DLLImport for the function and recreated the struct in C# using StructLayout. I've tried passing in the parameter using ref as well as tried Marshaling it in using MarshalAs(UnmangedType.Struct) and Marshal.PtrToStructure. The parameter still isn't passing correctly. Example: [DllImport("testdll.dll")] public static extern int getProduct(int

Force escaping Special character in XML Marshalling in Spring

廉价感情. 提交于 2020-06-25 03:37:30
问题 I want to force escaping special characters when I use Spring Marshaller. Below code is perfectly working when I use javax.xml.bind.Marshaller Book Class package com.odr.core.action; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRegistry; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name

How to return a vector of structs from Rust to C#?

▼魔方 西西 提交于 2020-06-24 21:29:07
问题 How is it possible to write Rust code like the C code below? This is my Rust code so far, without the option to marshal it: pub struct PackChar { id: u32, val_str: String, } #[no_mangle] pub extern "C" fn get_packs_char(size: u32) -> Vec<PackChar> { let mut out_vec = Vec::new(); for i in 0..size { let int_0 = '0' as u32; let last_char_val = int_0 + i % (126 - int_0); let last_char = char::from_u32(last_char_val).unwrap(); let buffer = format!("abcdefgHi{}", last_char); let pack_char =

JAXB remove XmlRootElement wrapper

淺唱寂寞╮ 提交于 2020-06-24 12:38:00
问题 I have this @XmlRootElement class Person. @XmlRootElement class Person { private String desc; } and the return content is {"Person": {"desc": "abc"} } and I really don't want the root wrapper, so I want the content to looks like {"desc": "abc"} Can I accomplish this via JaxB? If so, how? Thanks! 回答1: JAXB is an API for XML, not JSON. However, there are some JSON libraries (at least Jackson) which can utilize JAXB annotations. I don't know which one you are using, so I don't know exactly how

MarshalJSON without having all objects in memory at once

南笙酒味 提交于 2020-06-22 20:25:28
问题 I want to use json.Encoder to encode a large stream of data without loading all of it into memory at once. // I want to marshal this t := struct { Foo string // Bar is a stream of objects // I don't want it all to be in memory at the same time. Bar chan string }{ Foo: "Hello World", Bar: make(chan string), } // long stream of data go func() { for _, x := range []string{"one", "two", "three"} { t.Bar <- x } close(t.Bar) }() I thought maybe the json package had this functionality build in, but