blob: cee58753107359da78e42a5f1f731dfad84018ea [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2014 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
5
6#include "src/snapshot/snapshot-source-sink.h"
7
8#include "src/base/logging.h"
9#include "src/handles-inl.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010
11
12namespace v8 {
13namespace internal {
14
15void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) {
16 memcpy(to, data_ + position_, number_of_bytes);
17 position_ += number_of_bytes;
18}
19
20
21void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
22 DCHECK(integer < 1 << 30);
23 integer <<= 2;
24 int bytes = 1;
25 if (integer > 0xff) bytes = 2;
26 if (integer > 0xffff) bytes = 3;
27 if (integer > 0xffffff) bytes = 4;
28 integer |= (bytes - 1);
29 Put(static_cast<int>(integer & 0xff), "IntPart1");
30 if (bytes > 1) Put(static_cast<int>((integer >> 8) & 0xff), "IntPart2");
31 if (bytes > 2) Put(static_cast<int>((integer >> 16) & 0xff), "IntPart3");
32 if (bytes > 3) Put(static_cast<int>((integer >> 24) & 0xff), "IntPart4");
33}
34
35
36void SnapshotByteSink::PutRaw(const byte* data, int number_of_bytes,
37 const char* description) {
38 data_.AddAll(Vector<byte>(const_cast<byte*>(data), number_of_bytes));
39}
40
41
42int SnapshotByteSource::GetBlob(const byte** data) {
43 int size = GetInt();
44 CHECK(position_ + size <= length_);
45 *data = &data_[position_];
46 Advance(size);
47 return size;
48}
49} // namespace internal
50} // namespace v8