blob: 4326040c32781cd42c2f066990c9b1ed83761ea2 [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/**
* Copyright (C) 2013 Regents of the University of California.
* @author: Jeff Thompson <jefft0@remap.ucla.edu>
* See COPYING for copyright and distribution information.
*/
#include <ndn-cpp/common.hpp>
#include <ndn-cpp/data.hpp>
using namespace std;
namespace ndn {
const Block&
Data::wireEncode() const
{
if (wire_.hasWire())
return wire_;
wire_ = Block(Tlv::Data);
// Name
wire_.push_back(getName().wireEncode());
// MetaInfo
wire_.push_back(getMetaInfo().wireEncode());
// Content
wire_.push_back(content_);
if (!signature_) {
throw Error("Requested wire format, but data packet has not been signed yet");
}
///////////////
// Signature //
///////////////
// SignatureInfo
wire_.push_back(signature_.getInfo());
// SignatureValue
wire_.push_back(signature_.getValue());
wire_.encode();
return wire_;
}
/**
* Decode the input using a particular wire format and update this Data.
* @param input The input byte array to be decoded.
*/
void
Data::wireDecode(const Block &wire)
{
wire_ = wire;
wire_.parse();
// Name
name_.wireDecode(wire_.get(Tlv::Name));
// MetaInfo
metaInfo_.wireDecode(wire_.get(Tlv::MetaInfo));
// Content
content_ = wire_.get(Tlv::Content);
///////////////
// Signature //
///////////////
// SignatureInfo
signature_.setInfo(wire_.get(Tlv::SignatureInfo));
// SignatureValue
signature_.setValue(wire_.get(Tlv::SignatureValue));
}
}