monotone

monotone Mtn Source Tree

Root/epoch.cc

1// Copyright (C) 2005 Nathaniel Smith <njs@pobox.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#include "epoch.hh"
11#include "netio.hh"
12#include "constants.hh"
13#include "transforms.hh"
14
15#include <string>
16
17using std::string;
18
19void
20read_epoch(string const & in,
21 cert_value & branch, epoch_data & epoch)
22{
23 size_t pos = 0;
24 string raw_branch;
25 data raw_epoch;
26 extract_variable_length_string(in, raw_branch, pos, "epoch, branch name");
27 raw_epoch = data(extract_substring(in, pos, constants::epochlen_bytes,
28 "epoch, epoch data"));
29 branch = cert_value(raw_branch);
30 hexenc<data> tmp;
31 encode_hexenc(raw_epoch, tmp);
32 epoch = epoch_data(tmp);
33}
34
35void
36write_epoch(cert_value const & branch, epoch_data const & epoch,
37 string & out)
38{
39 insert_variable_length_string(branch(), out);
40 data raw_epoch;
41 decode_hexenc(epoch.inner(), raw_epoch);
42 out += raw_epoch();
43}
44
45void
46epoch_hash_code(cert_value const & branch, epoch_data const & epoch,
47 epoch_id & eid)
48{
49 string tmp(branch() + ":" + epoch.inner()());
50 data tdat(tmp);
51 hexenc<id> out;
52 calculate_ident(tdat, out);
53 eid = epoch_id(out);
54}
55
56// Local Variables:
57// mode: C++
58// fill-column: 76
59// c-file-style: "gnu"
60// indent-tabs-mode: nil
61// End:
62// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status