SSP21-CPP
IntegerField.h
1 #ifndef SSP21_INTEGERFIELD_H
2 #define SSP21_INTEGERFIELD_H
3 
4 #include "ssp21/crypto/gen/ParseError.h"
5 #include "ssp21/crypto/gen/FormatError.h"
6 #include "ssp21/crypto/IMessagePrinter.h"
7 
8 namespace ssp21
9 {
10 
11  template <typename IntegerType>
12  class IntegerField final
13  {
14  typedef typename IntegerType::type_t integer_t;
15 
16  public:
17 
18  size_t size() const
19  {
20  return IntegerType::size;
21  }
22 
23  operator integer_t& ()
24  {
25  return value;
26  }
27 
28  operator integer_t () const
29  {
30  return value;
31  }
32 
33  IntegerField()
34  {}
35 
36  IntegerField& operator=(integer_t value)
37  {
38  this->value = value;
39  return *this;
40  }
41 
42  explicit IntegerField(integer_t value) : value(value)
43  {}
44 
45  ParseError read(seq32_t& input)
46  {
47  return IntegerType::read_from(input, this->value) ? ParseError::ok : ParseError::insufficient_bytes;
48  }
49 
50  FormatError write(wseq32_t& output) const
51  {
52  return IntegerType::write_to(output, this->value) ? FormatError::ok : FormatError::insufficient_space;
53  }
54 
55  void print(const char* name, IMessagePrinter& printer) const
56  {
57  printer.print(name, this->value);
58  }
59 
60  integer_t value = 0;
61 
62  };
63 
64 
65 }
66 
67 #endif
SSP21-cpp main namespace.
Definition: BufferTypes.h:12
parser ran out of bytes before completion
ParseError
Definition: ParseError.h:27
not enough output buffer space
FormatError
Definition: FormatError.h:28