serialization

Python serialize lexical closures?

柔情痞子 提交于 2019-12-29 04:12:08
问题 Is there a way to serialize a lexical closure in Python using the standard library? pickle and marshal appear not to work with lexical closures. I don't really care about the details of binary vs. string serialization, etc., it just has to work. For example: def foo(bar, baz) : def closure(waldo) : return baz * waldo return closure I'd like to just be able to dump instances of closure to a file and read them back. Edit: One relatively obvious way that this could be solved is with some

Dictionary in protocol buffers

☆樱花仙子☆ 提交于 2019-12-29 03:56:06
问题 Is there any way to serialize a dictionary using protocol buffers, or I'll have to use Thrift if I need that? 回答1: People typically write down the dictionary as a list of key-value pairs, and then rebuild the dictionary on the other end. message Pair { optional string key = 1; optional string value = 2; } message Dictionary { repeated Pair pairs = 1; } 回答2: For future answer seekers, ProtoBuf now supports Maps natively: message MapMessage { map<string, string> MyMap = 1; } 回答3: You can check

How to Serialize Inherited Class with ProtoBuf-Net

我只是一个虾纸丫 提交于 2019-12-29 03:37:07
问题 I am sorry if this is a duplicate. I have searched several places for an answer that I might understand including: ProtoBuf.net Base class properties is not included when serializing derived class Serialize inherited classes using protobuf-net My apologies but I did not really understand the answers. I am looking for a faster more compact binary serializer and ProtoBuf looks like it might be the answer. I need to serialize a set of classes that all derive from a single base class. There are a

boost serialization of native type defined with typedef contained within struct

别来无恙 提交于 2019-12-29 02:06:27
问题 I have a MyFile.hpp header file which contains various types and enums. How do i do serialization/ desrialization of given example code. //MyFile.hpp namespace A { namespace B { typedef std::string MyString; typedef std::map<std::string,std::string> my_type; typedef bool result; struct MyTimer { int time; private : friend class boost::serialization::access; template<class Archive> void serialize(Archive &ar, const unsigned int version) { ar & time; } }; enum MODE { Sleep=1, HybridSleep,

How to make java class Serializable which is generated by wsdl

荒凉一梦 提交于 2019-12-29 01:56:06
问题 In my project, classes are generated by wsdl. One of these classes is User class. This class must be Serializable. How can I change my pom.xml file for making User Serializable? I can find example but can't apply it to my project https://pragmaticintegrator.wordpress.com/2009/03/14/make-serializable-jax-ws-clients-with-maven2/ 回答1: Finally I could find answer for my question. In our project we use org.apache.cxf plugin to generate classes. I created binding.xml file in resources folder. <?xml

Selectively escape HTML in strings during deserialization

◇◆丶佛笑我妖孽 提交于 2019-12-29 01:41:13
问题 I'm looking to write a JsonConverter which escapes HTML in strings, unless the [AllowHtml] attribute has been applied; private class ObjectWithStrings { // will be HTML-escaped public string Name { get; set; } // won't be escaped [AllowHtml] public string Unsafe { get; set; } } So I'm trying to write a JsonConverter with a custom ReadJson property; public override bool CanConvert(Type objectType) { return objectType == typeof(string); } public override object ReadJson(JsonReader reader, Type

XML serialization force full closing tag on null or empty value

≯℡__Kan透↙ 提交于 2019-12-29 01:40:07
问题 I have class public class Testowa { public string test { get; set; } } When I serialize it without value for test, I get <test/> But I want get <test></test> How I can do it? 回答1: Extend XmlWriter From there, If you use a code similar to the following for your serialization: XmlSerializer s = new XmlSerializer(typeof(Testowa)); using (FileStream fs = new FileStream(File, FileMode.CreateNew)) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.GetEncoding("ISO

c# JSON Serialization Use Value Instead of Property Name

可紊 提交于 2019-12-29 00:44:28
问题 I am working on a JSON driven project and I would like to provide the SessionManager object with a dynamic list of permissionst. While I can work with an array of key value pairs for permissions, I was wondering if I could remove the property names so that the key is the Permission value and the value is the IsAllowed value. public class SessionPermission { public string Permission { get; set; } public bool IsAllowed { get; set; } } public class SessionManager { public string UserName { get;

c# JSON Serialization Use Value Instead of Property Name

北城以北 提交于 2019-12-29 00:44:26
问题 I am working on a JSON driven project and I would like to provide the SessionManager object with a dynamic list of permissionst. While I can work with an array of key value pairs for permissions, I was wondering if I could remove the property names so that the key is the Permission value and the value is the IsAllowed value. public class SessionPermission { public string Permission { get; set; } public bool IsAllowed { get; set; } } public class SessionManager { public string UserName { get;

C# memcpy equivalent

巧了我就是萌 提交于 2019-12-28 23:06:54
问题 I have 2 objects from the same type and i would like to shallow copy one state to the other. In C++ i have memcpy which is great. How can i do it in C#? The MemberwiseClone() is not good enough because it creates & returns a new object and i like to copy to an existing object. I thought of using reflection but i'm afraid it will be too slow for production code. I also thought of using one of the .Net serializers but i think they also create object rather than setting an existing one. My Use