aboutsummaryrefslogtreecommitdiff
path: root/src/serialize.h
AgeCommit message (Collapse)Author
2015-05-14fix header include groupsPhilip Kaufmann
2015-03-06src/serialize.h: base serialization level endianness neutralityWladimir J. van der Laan
Serialization type-safety and endianness compatibility.
2015-01-31Remove whitespaces before double colon in errors and logsPavel Janík
2014-12-19Added "Core" to copyright headerssandakersmann
Github-Pull: #5494 Rebased-From: 15de949bb9277e442302bdd8dee299a8d6deee60
2014-10-31Update serialize comments to be doxygen compatibleMichael Ford
2014-10-22boost: split stream classes out of serialize.hCory Fields
serialization now has no dependencies.
2014-10-22CAutoFile: Explicit Get() and remove unused methodsWladimir J. van der Laan
Also add documentation to some methods.
2014-10-20Add IsNull() to class CAutoFile and remove operator !Ruben Dario Ponticeli
2014-10-15boost: drop dependency on tuple in serializationCory Fields
There's only one user of this form of serialization, so it can be easily dropped. It could be re-added if desired when we switch to c++11.
2014-10-15boost: drop dependency on is_fundamental in serializationCory Fields
There's only one case where a vector containing a fundamental type is serialized all-at-once, unsigned char. Anything else would lead to strange results. Use a dummy argument to overload in that case.
2014-10-02CAutoFile: make file privatePhilip Kaufmann
2014-10-02CBufferedFile: add explicit close functionPhilip Kaufmann
- also use identical close function for CAutoFile (avoids setting file to NULL under wrong conditions)
2014-10-02CBufferedFile: convert into a non-refcounted RAII wrapperPhilip Kaufmann
- it now takes over the passed file descriptor and closes it in the destructor - this fixes a leak in LoadExternalBlockFile(), where an exception could cause the file to not getting closed - disallow copies (like recently added for CAutoFile) - make nType and nVersion private
2014-09-28LLu is standard, but not portable. use ULLsinetek
2014-09-26autofile: Disallow by-value copies of CAutoFileCory Fields
One might assume that CAutoFile would be ref-counted so that a copied object would delay closing the underlying file until all copies have gone out of scope. Since that's not the case with CAutoFile, explicitly disable copying.
2014-09-21Fixing improper input syntax and failing bounds checkENikS
2014-09-14header include cleanupPhilip Kaufmann
- ensures alphabetical ordering for includes etc. in source file headers
2014-09-02Rename IMPLEMENT_SERIALIZE to ADD_SERIALIZE_METHODSPieter Wuille
2014-09-01Merge pull request #4737Pieter Wuille
31e9a83 Use CSizeComputer to avoid counting sizes in SerializationOp (Pieter Wuille) 84881f8 rework overhauled serialization methods to non-static (Kamil Domanski) 5d96b4a remove fields of ser_streamplaceholder (Kamil Domanski) 3d796f8 overhaul serialization code (Kamil Domanski)
2014-08-31Use CSizeComputer to avoid counting sizes in SerializationOpPieter Wuille
2014-08-31rework overhauled serialization methods to non-staticKamil Domanski
Thanks to Pieter Wuille for most of the work on this commit. I did not fixup the overhaul commit, because a rebase conflicted with "remove fields of ser_streamplaceholder". I prefer not to risk making a mistake while resolving it.
2014-08-31remove fields of ser_streamplaceholderKamil Domanski
The nType and nVersion fields of stream objects are never accessed from outside the class (or perhaps from the inside too, I haven't checked). Thus no need to have them in a placeholder, whose only purpose is to fill the "Stream" template parameter in serialization implementation.
2014-08-31overhaul serialization codeKamil Domanski
The implementation of each class' serialization/deserialization is no longer passed within a macro. The implementation now lies within a template of form: template <typename T, typename Stream, typename Operation> inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { size_t nSerSize = 0; /* CODE */ return nSerSize; } In cases when codepath should depend on whether or not we are just deserializing (old fGetSize, fWrite, fRead flags) an additional clause can be used: bool fRead = boost::is_same<Operation, CSerActionUnserialize>(); The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize, Serialize and Unserialize. These are now wrappers around the "SerializationOp" template.
2014-08-28add missing header end commentsPhilip Kaufmann
- ensures a consistent usage in header files - also add a blank line after the copyright header where missing - also remove orphan new-lines at the end of some files
2014-08-24Merge pull request #4618Pieter Wuille
eb0b56b Simplify serialize.h's exception handling (Pieter Wuille)
2014-08-18replace int with size_t in stream methodsKamil Domanski
Thus the read(...) and write(...) methods of all stream classes now have identical parameter lists. This will bring these classes one step closer to a common interface.
2014-08-09Simplify serialize.h's exception handlingPieter Wuille
Remove the 'state' and 'exceptmask' from serialize.h's stream implementations, as well as related methods. As exceptmask always included 'failbit', and setstate was always called with bits = failbit, all it did was immediately raise an exception. Get rid of those variables, and replace the setstate with direct exception throwing (which also removes some dead code). As a result, good() is never reached after a failure (there are only 2 calls, one of which is in tests), and can just be replaced by !eof(). fail(), clear(n) and exceptions() are just never called. Delete them.
2014-08-09Add a way to limit deserialized string lengthsPieter Wuille
and use it for most strings being serialized.
2014-07-16Break up CAddrMan's IMPLEMENT_SERIALIZEPieter Wuille
2014-06-23Avoid undefined behavior using CFlatData in CScript serializationWladimir J. van der Laan
`&vch[vch.size()]` and even `&vch[0]` on vectors can cause assertion errors with VC in debug mode. This is the problem mentioned in #4239. The deeper problem with this is that we rely on undefined behavior. - Add `begin_ptr` and `end_ptr` functions that get the beginning and end pointer of vector in a reliable way that copes with empty vectors and doesn't reference outside the vector (see https://stackoverflow.com/questions/1339470/how-to-get-the-address-of-the-stdvector-buffer-start-most-elegantly/1339767#1339767). - Add a convenience constructor to CFlatData that wraps a vector. I added `begin_ptr` and `end_ptr` as separate functions as I imagine they will be useful in more places.
2014-03-28remove an assignment which is never used.Yoichi Hirai
2013-11-10Cleanup code using forward declarations.Brandon Dahler
Use misc methods of avoiding unnecesary header includes. Replace int typedefs with int##_t from stdint.h. Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h. Normalize QT_VERSION ifs where possible. Resolve some indirect dependencies as direct ones. Remove extern declarations from .cpp files.
2013-10-30Merge pull request #3173 from gavinandresen/fuzzmessagesGavin Andresen
-fuzzmessagestest=N : randomly corrupt 1-of-N sent messages
2013-10-29Bug fix: CDataStream::GetAndClear() when nReadPos > 0Gavin Andresen
Changed CDataStream::GetAndClear() to use the most obvious get get and clear instead of a tricky swap(). Added a unit test for CDataStream insert/erase/GetAndClear. Note: GetAndClear() is not performance critical, it is used only by the send-a-message-to-the-network code. Bug was not noticed before now because the send-a-message code never erased from the stream.
2013-10-26Remove redundant insert method in serialize.Pieter Wuille
This seems to cause problems on recent clang, and looks totally redundant and unused. The const_iterator version is identical to the vector::const_iterator one (which is a typedef thereof). Marking it private (instead of removing) compiles fine, so this version is effectively unused even.
2013-10-20Merge pull request #3119Pieter Wuille
db0e8cc Bump Year Number to 2013 (super3)
2013-10-20Bump Year Number to 2013super3
2013-08-09Reject non-canonically-encoded sizesGavin Andresen
The length of vectors, maps, sets, etc are serialized using Write/ReadCompactSize -- which, unfortunately, do not use a unique encoding. So deserializing and then re-serializing a transaction (for example) can give you different bits than you started with. That doesn't cause any problems that we are aware of, but it is exactly the type of subtle mismatch that can lead to exploits. With this pull, reading a non-canonical CompactSize throws an exception, which means nodes will ignore 'tx' or 'block' or other messages that are not properly encoded. Please check my logic... but this change is safe with respect to causing a network split. Old clients that receive non-canonically-encoded transactions or blocks deserialize them into CTransaction/CBlock structures in memory, and then re-serialize them before relaying them to peers. And please check my logic with respect to causing a blockchain split: there are no CompactSize fields in the block header, so the block hash is always canonical. The merkle root in the block header is computed on a vector<CTransaction>, so any non-canonical encoding of the transactions in 'tx' or 'block' messages is erased as they are read into memory by old clients, and does not affect the block hash. And, as noted above, old clients re-serialize (with canonical encoding) 'tx' and 'block' messages before relaying to peers.
2013-03-29Use per-message send buffer, rather than per connectionPieter Wuille
2012-11-16Split off CBlockHeader from CBlockPieter Wuille
Cleaner and removes the need for the application-specific flags in serialize.h.
2012-11-09Add CBufferedFilePieter Wuille
2012-10-20Compact serialization for variable-length integersPieter Wuille
Variable-length integers: bytes are a MSB base-128 encoding of the number. The high bit in each byte signifies whether another digit follows. To make the encoding is one-to-one, one is subtracted from all but the last digit. Thus, the byte sequence a[] with length len, where all but the last byte has bit 128 set, encodes the number: (a[len-1] & 0x7F) + sum(i=1..len-1, 128^i*((a[len-i-1] & 0x7F)+1)) Properties: * Very small (0-127: 1 byte, 128-16511: 2 bytes, 16512-2113663: 3 bytes) * Every integer has exactly one encoding * Encoding does not depend on size of original integer type
2012-09-09Remove VC6 comment and pointless #ifdef'd benchmark codeWladimir J. van der Laan
We're in a wholly different world now, C++-compiler-wise. Current std::stringstream implementations don't have the stated problem anymore, and are just as fast as CDataStream. The #ifdef'd block does not even compile anymore; CDataStream constructor changed, and missing some std::. Also timing in whole seconds is also way too granular to say anything sensible in such microbenchmarks. Just remove it, it can always be found again in git history.
2012-07-02Fix signed/unsigned warnings in {script,serialize}.h (fixes #1541)Matt Corallo
2012-05-18Update License in File HeadersFordy
I originally created a pull to replace the "COPYING" in crypter.cpp and crypter.h, but it turned out that COPYING was actually the correct file.
2012-05-01remove unused typedef in serialize.hPhilip Kaufmann
2012-04-17Further reduce header dependenciesPieter Wuille
This commit removes the dependency of serialize.h on PROTOCOL_VERSION, and makes this parameter required instead of implicit. This is much saner, as it makes the places where changing a version number can have an influence obvious.
2012-04-17Merge pull request #1106 from jgarzik/sign-compareGavin Andresen
Fix many sign-comparison warnings found in bitcoin codebase
2012-04-17Merge pull request #1115 from laanwj/2012_04_cleanupmiscGavin Andresen
Delete unused, unreachable and commented code, add missing initializer
2012-04-17Remove unused and unreachable codeWladimir J. van der Laan