SSP21-CPP
SeqByteField.h
1 
2 #ifndef SSP21_SEQBYTEFIELD_H
3 #define SSP21_SEQBYTEFIELD_H
4 
5 #include "ser4cpp/serialization/BigEndian.h"
6 
7 #include "ssp21/util/SequenceTypes.h"
8 
9 #include "ssp21/crypto/gen/FormatError.h"
10 #include "ssp21/crypto/gen/ParseError.h"
11 
12 #include "ssp21/crypto/IMessagePrinter.h"
13 #include "ssp21/crypto/IntegerField.h"
14 
15 #include "ssp21/crypto/VLength.h"
16 
17 
18 namespace ssp21
19 {
20  class SeqByteField final : public seq32_t
21  {
22  public:
23 
24  size_t size() const
25  {
26  return VLength::size_in_bytes(this->length()) + this->length();
27  }
28 
29  SeqByteField() {}
30 
31  SeqByteField& operator=(const seq32_t& other)
32  {
33  seq32_t::operator=(other);
34  return *this;
35  }
36 
37  explicit SeqByteField(const seq32_t& value) : seq32_t(value)
38  {}
39 
40  ParseError read(seq32_t& input)
41  {
42  uint32_t length;
43  const auto err = VLength::read(length, input);
44  if (any(err)) return err;
45 
46  if (input.length() < length)
47  {
49  }
50 
51  *this = input.take(length);
52  input.advance(length);
53  return ParseError::ok;
54  }
55 
56  FormatError write(wseq32_t& dest) const
57  {
58  const auto err = VLength::write(this->length(), dest);
59  if (any(err)) return err;
60 
61  if (dest.length() < this->length()) return FormatError::insufficient_space;
62 
63  dest.copy_from(*this);
64 
65  return FormatError::ok;
66  }
67 
68  void print(const char* name, IMessagePrinter& printer) const
69  {
70  printer.print(name, *this);
71  }
72 
73  };
74 
75 }
76 
77 #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