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.
6 #include "src/snapshot/snapshot-source-sink.h"
8 #include "src/base/logging.h"
9 #include "src/handles-inl.h"
10 #include "src/snapshot/serialize.h" // for SerializerDeserializer::nop()
16 void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) {
17 memcpy(to, data_ + position_, number_of_bytes);
18 position_ += number_of_bytes;
22 void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
23 DCHECK(integer < 1 << 30);
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");
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));
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;
52 bool SnapshotByteSource::GetBlob(const byte** data, int* number_of_bytes) {
54 *number_of_bytes = size;
56 if (position_ + size <= length_) {
57 *data = &data_[position_];
61 Advance(length_ - position_); // proceed until end.
66 } // namespace v8::internal