blob: 1824ece515aae1dcb782be20716445fe050da3d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#ifndef __READER_H__
#define __READER_H__
#include <cstdint>
#include "pal.h"
namespace bundle
{
// Helper class for reading sequentially from the memory-mapped bundle file.
struct reader_t
{
reader_t(const int8_t* base_ptr, int64_t bound)
: m_base_ptr(base_ptr)
, m_ptr(base_ptr)
, m_bound(bound)
, m_bound_ptr(add_without_overflow(base_ptr, bound))
{
}
public:
void set_offset(int64_t offset);
operator const int8_t*() const
{
return m_ptr;
}
int8_t read()
{
bounds_check();
return *m_ptr++;
}
// Copy len bytes from m_ptr to dest
void read(void* dest, int64_t len)
{
bounds_check(len);
memcpy(dest, m_ptr, len);
m_ptr += len;
}
// Return a pointer to the requested bytes within the memory-mapped file.
// Skip over len bytes.
const int8_t* read_direct(int64_t len)
{
bounds_check(len);
const int8_t *ptr = m_ptr;
m_ptr += len;
return ptr;
}
size_t read_path_length();
void read_path_string(pal::string_t &str);
private:
void bounds_check(int64_t len = 1);
static const int8_t* add_without_overflow(const int8_t* ptr, int64_t len);
const int8_t* const m_base_ptr;
const int8_t* m_ptr;
const int64_t m_bound;
const int8_t* const m_bound_ptr;
};
}
#endif // __READER_H__
|