SST  15.1.0
StructuralSimulationToolkit
ser_buffer_accessor.h
1 // Copyright 2009-2025 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2025, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_SERIALIZATION_IMPL_SER_BUFFER_ACCESSOR_H
13 #define SST_CORE_SERIALIZATION_IMPL_SER_BUFFER_ACCESSOR_H
14 
15 #ifndef SST_INCLUDING_SERIALIZER_H
16 #warning \
17  "The header file sst/core/serialization/impl/ser_buffer_accessor.h should not be directly included as it is not part of the stable public API. The file is included in sst/core/serialization/serializer.h"
18 #endif
19 
20 #include <cstddef>
21 #include <stdexcept>
22 
24 
26 {
27  char* const bufstart_;
28  size_t const max_size_;
29  char* bufptr_ = bufstart_;
30  size_t size_ = 0;
31 
32 public:
33  // constructor which is inherited by packer and unpacker
34  ser_buffer_accessor(void* buffer, size_t size) :
35  bufstart_(static_cast<char*>(buffer)),
36  max_size_(size)
37  {}
38 
40  ser_buffer_accessor& operator=(const ser_buffer_accessor&) = delete;
41  ~ser_buffer_accessor() = default;
42 
43  // return a pointer to the buffer and then advance it size bytes
44  void* buf_next(size_t size)
45  {
46  size_ += size;
47  if ( size_ > max_size_ ) throw std::out_of_range("serialization buffer overrun");
48  char* buf = bufptr_;
49  bufptr_ += size;
50  return buf;
51  }
52 
53  size_t size() const { return size_; }
54 };
55 
56 } // namespace SST::Core::Serialization::pvt
57 
58 #endif // SST_CORE_SERIALIZATION_IMPL_SER_BUFFER_ACCESSOR_H
Definition: ser_buffer_accessor.h:25
Definition: baseComponent.cc:1107