v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
snapshot-data.cc
Go to the documentation of this file.
1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
9
10namespace v8 {
11namespace internal {
12
13void SerializedData::AllocateData(uint32_t size) {
16 size_ = size;
17 owns_data_ = true;
18}
19
20// static
21constexpr uint32_t SerializedData::kMagicNumber;
22
25 const std::vector<uint8_t>* payload = serializer->Payload();
26
27 // Calculate sizes.
28 uint32_t size = kHeaderSize + static_cast<uint32_t>(payload->size());
29
30 // Allocate backing store and create result data.
31 AllocateData(size);
32
33 // Zero out pre-payload data. Part of that is only used for padding.
34 memset(data_, 0, kHeaderSize);
35
36 // Set header values.
38 SetHeaderValue(kPayloadLengthOffset, static_cast<int>(payload->size()));
39
40 // Copy serialized data.
41 CopyBytes(data_ + kHeaderSize, payload->data(),
42 static_cast<size_t>(payload->size()));
43}
44
46 const uint8_t* payload = data_ + kHeaderSize;
47 uint32_t length = GetHeaderValue(kPayloadLengthOffset);
48 DCHECK_EQ(data_ + size_, payload + length);
49 return base::Vector<const uint8_t>(payload, length);
50}
51
52} // namespace internal
53} // namespace v8
void SetHeaderValue(uint32_t offset, uint32_t value)
static constexpr uint32_t kMagicNumber
void AllocateData(uint32_t size)
uint32_t GetHeaderValue(uint32_t offset) const
const std::vector< uint8_t > * Payload() const
Definition serializer.h:189
static const uint32_t kHeaderSize
static const uint32_t kPayloadLengthOffset
virtual base::Vector< const uint8_t > Payload() const
void CopyBytes(T *dst, const T *src, size_t num_bytes)
Definition memcopy.h:261
T * NewArray(size_t size)
Definition allocation.h:43
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485