MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PacketSerializer.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  AbstractDriver.h String translator for Packets
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
28 #ifndef PACKETDECODER_H
29 #define PACKETDECODER_H
30 
31 #include "ByteSerializable.h"
32 #include "Packet.h"
33 #include "AtomSerializer.h"
34 
35 namespace MFM
36 {
37  template <class CC>
39  {
40  typedef typename CC::PARAM_CONFIG P;
41  typedef typename CC::ATOM_TYPE T;
42  enum { BPA = P::BITS_PER_ATOM };
43 
44  private:
45  Packet<T>& m_packet;
46 
47  public:
48  PacketSerializer(Packet<T>& packet) :
49  m_packet(packet)
50  { }
51 
52  virtual Result PrintTo(ByteSink& byteSink, s32 argument = 0)
53  {
54  SPoint loc = m_packet.GetLocation();
55  AtomSerializer<CC> atom(m_packet.GetAtom());
56  byteSink.Printf("Pkt%d{%d/%s, gen:%d, nghb:%d, (%d, %d), %@}",
57  sizeof(Packet<T>),
58  (u32) m_packet.GetType(),
59  m_packet.GetTypeString(),
60  m_packet.GetGeneration(),
61  m_packet.GetReceivingNeighbor(),
62  loc.GetX(), loc.GetY(),
63  &atom);
64 
65  return SUCCESS;
66  }
67 
68  virtual Result ReadFrom(ByteSource & byteSource, s32 argument = 0)
69  {
70  return UNSUPPORTED;
71  }
72  };
73 }
74 
75 #endif /* PACKETDECODER_H */
virtual Result ReadFrom(ByteSource &byteSource, s32 argument=0)
Definition: PacketSerializer.h:68
T GetY() const
Definition: Point.tcc:40
Definition: ByteSource.h:44
virtual Result PrintTo(ByteSink &byteSink, s32 argument=0)
Definition: PacketSerializer.h:52
Definition: Packet.h:71
Definition: ByteSink.h:47
Definition: PacketSerializer.h:38
Definition: Atom.h:44
Definition: ByteSerializable.h:45
T GetX() const
Definition: Point.tcc:34