File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -274,6 +274,14 @@ class BufferStream {
274274 return this ->write (obj);
275275 }
276276
277+ template <BufferStreamPODType T = std::byte>
278+ BufferStream& pad (std::uint64_t n) {
279+ for (std::uint64_t i = 0 ; i < n * sizeof (T); i++) {
280+ this ->write <std::byte>({});
281+ }
282+ return *this ;
283+ }
284+
277285 template <BufferStreamPODType T, std::uint64_t N>
278286 BufferStream& read (T(&obj)[N]) {
279287 if (this ->useExceptions && this ->bufferPos + sizeof (T) * N > this ->bufferLen ) {
Original file line number Diff line number Diff line change @@ -235,6 +235,14 @@ class FileStream {
235235 return this ->write (obj);
236236 }
237237
238+ template <BufferStreamPODType T = std::byte>
239+ FileStream& pad (std::uint64_t n) {
240+ for (std::uint64_t i = 0 ; i < n * sizeof (T); i++) {
241+ this ->write <std::byte>({});
242+ }
243+ return *this ;
244+ }
245+
238246 template <BufferStreamPODType T, std::uint64_t N>
239247 FileStream& read (T(&obj)[N]) {
240248 return this ->read (&obj, N);
Original file line number Diff line number Diff line change @@ -154,6 +154,22 @@ TEST(BufferStream, skip) {
154154 EXPECT_EQ (stream.tell (), 3 );
155155}
156156
157+ TEST (BufferStream, pad) {
158+ std::vector<unsigned char > buffer;
159+ BufferStream stream{buffer};
160+
161+ EXPECT_EQ (stream.tell (), 0 );
162+
163+ stream.pad (1 );
164+ EXPECT_EQ (stream.tell (), 1 );
165+
166+ stream.pad (2 );
167+ EXPECT_EQ (stream.tell (), 3 );
168+
169+ stream.pad <std::int16_t >(1 );
170+ EXPECT_EQ (stream.tell (), 3 + sizeof (std::int16_t ));
171+ }
172+
157173TEST (BufferStream, read_int_ref) {
158174 {
159175 int x = 10 ;
You can’t perform that action at this time.
0 commit comments