monotone

monotone Mtn Source Tree

Root/epoch.cc

1// copyright (C) 2005 nathaniel smith <njs@pobox.com>
2// all rights reserved.
3// licensed to the public under the terms of the GNU GPL (>= 2)
4// see the file COPYING for details
5
6#include "epoch.hh"
7#include "netio.hh"
8#include "constants.hh"
9#include "transforms.hh"
10
11#include <string>
12
13void
14read_epoch(std::string const & in,
15 cert_value & branch, epoch_data & epoch)
16{
17 size_t pos = 0;
18 std::string raw_branch;
19 data raw_epoch;
20 extract_variable_length_string(in, raw_branch, pos, "epoch, branch name");
21 raw_epoch = data(extract_substring(in, pos, constants::epochlen_bytes,
22 "epoch, epoch data"));
23 branch = cert_value(raw_branch);
24 hexenc<data> tmp;
25 encode_hexenc(raw_epoch, tmp);
26 epoch = epoch_data(tmp);
27}
28
29void
30write_epoch(cert_value const & branch, epoch_data const & epoch,
31 std::string & out)
32{
33 insert_variable_length_string(branch(), out);
34 data raw_epoch;
35 decode_hexenc(epoch.inner(), raw_epoch);
36 out += raw_epoch();
37}
38
39void
40epoch_hash_code(cert_value const & branch, epoch_data const & epoch,
41 epoch_id & eid)
42{
43 std::string tmp(branch() + ":" + epoch.inner()());
44 data tdat(tmp);
45 hexenc<id> out;
46 calculate_ident(tdat, out);
47 eid = epoch_id(out);
48}

Archive Download this file

Branches

Tags

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