![]() |
|
|||
File indexing completed on 2025-08-27 09:30:24
0001 /* 0002 * Copyright 2021 Google Inc. All rights reserved. 0003 * 0004 * Licensed under the Apache License, Version 2.0 (the "License"); 0005 * you may not use this file except in compliance with the License. 0006 * You may obtain a copy of the License at 0007 * 0008 * http://www.apache.org/licenses/LICENSE-2.0 0009 * 0010 * Unless required by applicable law or agreed to in writing, software 0011 * distributed under the License is distributed on an "AS IS" BASIS, 0012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0013 * See the License for the specific language governing permissions and 0014 * limitations under the License. 0015 */ 0016 0017 #ifndef FLATBUFFERS_BUFFER_REF_H_ 0018 #define FLATBUFFERS_BUFFER_REF_H_ 0019 0020 #include "flatbuffers/base.h" 0021 #include "flatbuffers/verifier.h" 0022 0023 namespace flatbuffers { 0024 0025 // Convenient way to bundle a buffer and its length, to pass it around 0026 // typed by its root. 0027 // A BufferRef does not own its buffer. 0028 struct BufferRefBase {}; // for std::is_base_of 0029 0030 template<typename T> struct BufferRef : BufferRefBase { 0031 BufferRef() : buf(nullptr), len(0), must_free(false) {} 0032 BufferRef(uint8_t *_buf, uoffset_t _len) 0033 : buf(_buf), len(_len), must_free(false) {} 0034 0035 ~BufferRef() { 0036 if (must_free) free(buf); 0037 } 0038 0039 const T *GetRoot() const { return flatbuffers::GetRoot<T>(buf); } 0040 0041 bool Verify() { 0042 Verifier verifier(buf, len); 0043 return verifier.VerifyBuffer<T>(nullptr); 0044 } 0045 0046 uint8_t *buf; 0047 uoffset_t len; 0048 bool must_free; 0049 }; 0050 0051 } // namespace flatbuffers 0052 0053 #endif // FLATBUFFERS_BUFFER_REF_H_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |