serialization

Serialize C++ functor

徘徊边缘 提交于 2019-12-29 09:06:13
问题 Can you save the function body of a C++ lambda/functor? For example, say you have light0->lightFunction = []( real tEl, real pAz ) -> Vector { return Vector( // red is up lobe std::max<real>( 0., 5*cos(tEl)-4 ), // green lower lobe std::max<real>( 0., -4*sin(tEl-PI)*cos(pAz-2.5)-3), 0. ) ; } ; And you want to save the function body, so you can load it later (instead of always having to hard code it). Can you do it? 回答1: This lambda doesn't have state (not a closure), so it's an ordinary

Serialization in Java, invalid type code 00

杀马特。学长 韩版系。学妹 提交于 2019-12-29 08:41:48
问题 I'm getting an error (java.io.StreamCorruptedException: invalid type code: 00) when reading in a serialised object. Here is the class that implements serializable: package guts; import cc.mallet.classify.*; import java.io.*; public class NaiveBayesWithID implements Serializable { private NaiveBayes nb; private static final long serialVersionUID = 1; private static final int CURRENT_SERIAL_VERSION = 1; public NaiveBayesWithID(NaiveBayes nb) { this.nb = nb; } public NaiveBayesWithID(){ this.nb

Serialization in Java, invalid type code 00

前提是你 提交于 2019-12-29 08:41:47
问题 I'm getting an error (java.io.StreamCorruptedException: invalid type code: 00) when reading in a serialised object. Here is the class that implements serializable: package guts; import cc.mallet.classify.*; import java.io.*; public class NaiveBayesWithID implements Serializable { private NaiveBayes nb; private static final long serialVersionUID = 1; private static final int CURRENT_SERIAL_VERSION = 1; public NaiveBayesWithID(NaiveBayes nb) { this.nb = nb; } public NaiveBayesWithID(){ this.nb

Why can I not deserialize this custom struct using Json.Net?

佐手、 提交于 2019-12-29 08:36:28
问题 I have a struct representing a DateTime which also has zone info as below: public struct DateTimeWithZone { private readonly DateTime _utcDateTime; private readonly TimeZoneInfo _timeZone; public DateTimeWithZone(DateTime dateTime, TimeZoneInfo timeZone, DateTimeKind kind = DateTimeKind.Utc) { dateTime = DateTime.SpecifyKind(dateTime, kind); _utcDateTime = dateTime.Kind != DateTimeKind.Utc ? TimeZoneInfo.ConvertTimeToUtc(dateTime, timeZone) : dateTime; _timeZone = timeZone; } public DateTime

XmlSerializer: How to Deserialize an enum value that no longer exists

随声附和 提交于 2019-12-29 08:32:36
问题 I am using the XMLSerializer to save this class to a file. The class has a string and an enum as shown below: public class IOPoint { string Name {get; set;} TypeEnum {get; set;} } public enum TypeEnum { Temperature, Pressure, Humidity, } When serialized it looks like this. <IOPoint> <Name>Relative Humidity</Name> <TypeEnum>Humidity</TypeEnum> </IOPoint> I've been serializing and deserializing this object with no problems for several versions. I no longer want to support Humidity, so I removed

How to encode file of any type into base64 string and then decode it into file again using Lazarus/Delphi?

℡╲_俬逩灬. 提交于 2019-12-29 08:19:11
问题 Can you tell me how can I do that? Is there any Freepascal unit that can do this for me? I need that so my program can store binary data in it's XML-based fileformat. 回答1: Use the base64 unit and its two classes, TBase64EncodingStream and TBase64DecodingStream . Here is a simple example: program demo; uses Classes, base64; var DecodedStream: TStringStream; EncodedStream: TStringStream; Encoder: TBase64EncodingStream; Output: string; begin DecodedStream := TStringStream.Create('Hello World!');

vector serialization

江枫思渺然 提交于 2019-12-29 07:43:09
问题 I am trying to binary serialize the data of vector. In this sample below I serialize to a string, and then deserialize back to a vector, but do not get the same data I started with. Why is this the case? vector<size_t> v; v.push_back(1); v.push_back(2); v.push_back(3); string s((char*)(&v[0]), 3 * sizeof(size_t)); vector<size_t> w(3); strncpy((char*)(&w[0]), s.c_str(), 3 * sizeof(size_t)); for (size_t i = 0; i < w.size(); ++i) { cout << w[i] << endl; } I expect to get the output 1 2 3 but

Persisting a trie to a file - C

こ雲淡風輕ζ 提交于 2019-12-29 06:19:46
问题 I have a trie which I am using to do some string processing. I have a simple compiler which generates trie from some data. Once generated, my trie won't change at run time. I am looking for an approach where I can persist the trie in a file and load it effectively. I have looked at sqllite to understand how they are persisting b-tree but their file format looks bit advanced and I may not need all of those. It'd be helpful if someone can provide some ideas to persist and read the trie . I am

Java serialization and duplicate objects

▼魔方 西西 提交于 2019-12-29 05:19:08
问题 I have the following setup: public class A { private Set<C> cSet; } public class B { private Set<C> cSet; } public class C {} A's and B's cSet might have references to same C instances. I want to serialize A and B such that upon deserialization I don't have duplicate C objects. Will Java know how to do the right thing if I serialize/deserialize it into the same ObjectOutputStream, or might I end up with more C instances than I started out with? 回答1: No, you won't get more instances of C than

Serialization of scala functions

吃可爱长大的小学妹 提交于 2019-12-29 04:46:45
问题 I know that there is Jerkson and scalaxb and even Java's XStream that successfully able to serialize scala's data. I know that they handle well Strings, Integers and even case classes pretty well. But if I have function as one of the fields? e.g. if I have something like: case class Foo(bar: (Int) => Boolean, baz: Int) Can these fields been somehow serialized to JSON or XML (actually, I don't care to which one, they should be human-readable, thats why I don't want to use SBinary)? EDIT Why