ONE - On-device Neural Engine
Loading...
Searching...
No Matches
buffer_ref.h
Go to the documentation of this file.
1
/*
2
* Copyright 2021 Google Inc. All rights reserved.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
17
#ifndef FLATBUFFERS_BUFFER_REF_H_
18
#define FLATBUFFERS_BUFFER_REF_H_
19
20
#include "
flatbuffers/base.h
"
21
#include "
flatbuffers/verifier.h
"
22
23
namespace
flatbuffers
{
24
25
// Convenient way to bundle a buffer and its length, to pass it around
26
// typed by its root.
27
// A BufferRef does not own its buffer.
28
struct
BufferRefBase
{};
// for std::is_base_of
29
30
template
<
typename
T>
struct
BufferRef
:
BufferRefBase
{
31
BufferRef
() :
buf
(nullptr),
len
(0),
must_free
(false) {}
32
BufferRef
(uint8_t *_buf, uoffset_t _len)
33
:
buf
(_buf),
len
(_len),
must_free
(false) {}
34
35
~BufferRef
() {
36
if
(
must_free
) free(
buf
);
37
}
38
39
const
T *
GetRoot
()
const
{
return
flatbuffers::GetRoot<T>(
buf
); }
40
41
bool
Verify
() {
42
Verifier verifier(
buf
,
len
);
43
return
verifier.VerifyBuffer<T>(
nullptr
);
44
}
45
46
uint8_t *
buf
;
47
uoffset_t
len
;
48
bool
must_free
;
49
};
50
51
}
// namespace flatbuffers
52
53
#endif
// FLATBUFFERS_BUFFER_REF_H_
base.h
flatbuffers
Definition
allocator.h:22
verifier.h
flatbuffers::BufferRefBase
Definition
buffer_ref.h:28
flatbuffers::BufferRef
Definition
buffer_ref.h:30
flatbuffers::BufferRef::GetRoot
const T * GetRoot() const
Definition
buffer_ref.h:39
flatbuffers::BufferRef::Verify
bool Verify()
Definition
buffer_ref.h:41
flatbuffers::BufferRef::buf
uint8_t * buf
Definition
buffer_ref.h:46
flatbuffers::BufferRef::must_free
bool must_free
Definition
buffer_ref.h:48
flatbuffers::BufferRef::len
uoffset_t len
Definition
buffer_ref.h:47
flatbuffers::BufferRef::BufferRef
BufferRef()
Definition
buffer_ref.h:31
flatbuffers::BufferRef::BufferRef
BufferRef(uint8_t *_buf, uoffset_t _len)
Definition
buffer_ref.h:32
flatbuffers::BufferRef::~BufferRef
~BufferRef()
Definition
buffer_ref.h:35
onert-micro
externals
flatbuffers
buffer_ref.h
Generated by
1.9.8