Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
serialise.hh File Reference
#include <memory>
#include <type_traits>
#include "nix/util/fun.hh"
#include "nix/util/types.hh"
#include "nix/util/util.hh"
#include "nix/util/file-descriptor.hh"

Go to the source code of this file.

Classes

struct  nix::Sink
class  nix::NullSink
class  nix::FinishSink
class  nix::BufferedSink
struct  nix::Source
class  nix::BufferedSource
class  nix::RestartableSource
struct  nix::FdSink
struct  nix::FdSource
class  nix::StringSink
class  nix::StringSource
class  nix::TeeSink
class  nix::TeeSource
class  nix::SizedSource
class  nix::LengthSource
class  nix::LambdaSink
class  nix::LambdaSource
class  nix::ChainSource
class  nix::FramedSource
class  nix::FramedSink
class  nix::EnsureRead

Functions

std::unique_ptr< FinishSink > nix::sourceToSink (fun< void(Source &)> reader)
std::unique_ptr< Source > nix::sinkToSource (fun< void(Sink &)> writer, fun< void()> eof=[]() { throw EndOfFile("coroutine has finished");})
void nix::writePadding (size_t len, Sink &sink)
void nix::writeString (std::string_view s, Sink &sink)
Sink & nix::operator<< (Sink &sink, uint64_t n)
Sink & nix::operator<< (Sink &in, const Error &ex)
Sink & nix::operator<< (Sink &sink, std::string_view s)
Sink & nix::operator<< (Sink &sink, const Strings &s)
Sink & nix::operator<< (Sink &sink, const StringSet &s)
 nix::MakeError (SerialisationError, Error)
template<typename T>
T nix::readNum (Source &source)
unsigned int nix::readInt (Source &source)
uint64_t nix::readLongLong (Source &source)
void nix::readPadding (size_t len, Source &source)
size_t nix::readString (char *buf, size_t max, Source &source)
std::string nix::readString (Source &source, size_t max=std::numeric_limits< size_t >::max())
template<class T>
T nix::readStrings (Source &source)
Source & nix::operator>> (Source &in, std::string &s)
template<typename T>
Source & nix::operator>> (Source &in, T &n)
template<typename T>
Source & nix::operator>> (Source &in, bool &b)
Error nix::readError (Source &source)

Function Documentation

◆ operator<<()

Sink & nix::operator<< ( Sink & sink,
uint64_t n )
inline

Write a serialisation of an integer to the sink in little endian order.

Types other than uint64_t (including signed types) get implicitly converted to uint64_t.A

Negative number to unsigned conversion is actually well-defined in C++:

[n4950] 7.3.9 Integral conversions: the result is the unique value of the destination type that is congruent to the source integer modulo 2^N, where N is the width of the destination type.

[n4950] 6.8.2 Fundamental types: An unsigned integer type has the same object representation, value representation, and alignment requirements (6.7.6) as the corresponding signed integer type. For each value x of a signed integer type, the value of the corresponding unsigned integer type congruent to x modulo 2 N has the same value of corresponding bits in its value representation. This is also known as two's complement representation.

Todo
Should we even allow negative values to get serialised?

◆ readPadding()

void nix::readPadding ( size_t len,
Source & source )

Read padding bytes to align len up to a multiple of 8. Throws SerialisationError if any padding byte is non-zero.

◆ sinkToSource()

std::unique_ptr< Source > nix::sinkToSource ( fun< void(Sink &)> writer,
fun< void()> eof = []() { throw EndOfFile("coroutine has finished"); } )

Convert a function that feeds data into a Sink into a Source. The Source executes the function as a coroutine.