DNA Calib 1.1
Project brief
Blob.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6
7namespace terse {
8
9// Blob is a wrapper type around a byte-array essentially, and is used to serialize binary blobs,
10// whose size is predefined by another entity (e.g. an ArchiveSize object).
11// During serialization, the amount of bytes either written to or read from the stream will be
12// controlled by the user (by setting the size on the blob type through the setSize member function).
13// For text-based serializers, binary blobs are Base64 encoded/decoded.
14template<typename T, typename TAllocator>
15class Blob {
16 public:
17 static_assert(sizeof(T) == sizeof(char), "Blob supports only native byte-sized types.");
18
19 using value_type = T;
20 using allocator_type = TAllocator;
21
22 public:
23 Blob() = default;
24
25 explicit Blob(const allocator_type& alloc) : bytes{alloc} {
26 }
27
28 Blob(std::size_t size, const allocator_type& alloc) : bytes{size, alloc} {
29 }
30
31 allocator_type get_allocator() const noexcept {
32 return bytes.get_allocator();
33 }
34
36 return bytes.data();
37 }
38
39 const value_type* data() const {
40 return bytes.data();
41 }
42
43 std::size_t size() const {
44 return bytes.size();
45 }
46
47 void setSize(std::size_t newSize) {
49 }
50
51 private:
53};
54
55} // namespace terse
Definition: Blob.h:15
Blob(std::size_t size, const allocator_type &alloc)
Definition: Blob.h:28
T value_type
Definition: Blob.h:19
Blob(const allocator_type &alloc)
Definition: Blob.h:25
void setSize(std::size_t newSize)
Definition: Blob.h:47
DynArray< value_type, allocator_type > bytes
Definition: Blob.h:52
std::size_t size() const
Definition: Blob.h:43
TAllocator allocator_type
Definition: Blob.h:20
Blob()=default
allocator_type get_allocator() const noexcept
Definition: Blob.h:31
const value_type * data() const
Definition: Blob.h:39
value_type * data()
Definition: Blob.h:35
void resize_uninitialized(std::size_t size)
Definition: DynArray.h:191
std::size_t size() const
Definition: DynArray.h:130
allocator_type get_allocator() const noexcept
Definition: DynArray.h:113
value_type * data()
Definition: DynArray.h:122
Definition: Archive.h:14