OLD | NEW |
| (Empty) |
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-source-sink.h" | |
7 | |
8 #include "src/base/logging.h" | |
9 #include "src/handles-inl.h" | |
10 #include "src/serialize.h" // for SerializerDeserializer::nop() in AtEOF() | |
11 | |
12 | |
13 namespace v8 { | |
14 namespace internal { | |
15 | |
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 | |
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 | |
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 | |
43 bool SnapshotByteSource::AtEOF() { | |
44 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false; | |
45 for (int x = position_; x < length_; x++) { | |
46 if (data_[x] != SerializerDeserializer::nop()) return false; | |
47 } | |
48 return true; | |
49 } | |
50 | |
51 | |
52 bool SnapshotByteSource::GetBlob(const byte** data, int* number_of_bytes) { | |
53 int size = GetInt(); | |
54 *number_of_bytes = size; | |
55 | |
56 if (position_ + size <= length_) { | |
57 *data = &data_[position_]; | |
58 Advance(size); | |
59 return true; | |
60 } else { | |
61 Advance(length_ - position_); // proceed until end. | |
62 return false; | |
63 } | |
64 } | |
65 | |
66 } // namespace v8::internal | |
67 } // namespace v8 | |
OLD | NEW |