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