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-source-sink.h"
8 #include "src/base/logging.h"
9 #include "src/handles-inl.h"
10 #include "src/serialize.h" // for SerializerDeserializer::nop() in AtEOF()
16 int32_t SnapshotByteSource::GetUnalignedInt() {
17 DCHECK(position_ < length_); // Require at least one byte left.
18 int32_t answer = data_[position_];
19 answer |= data_[position_ + 1] << 8;
20 answer |= data_[position_ + 2] << 16;
21 answer |= data_[position_ + 3] << 24;
26 void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) {
27 MemCopy(to, data_ + position_, number_of_bytes);
28 position_ += number_of_bytes;
32 void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
33 DCHECK(integer < 1 << 30);
36 if (integer > 0xff) bytes = 2;
37 if (integer > 0xffff) bytes = 3;
38 if (integer > 0xffffff) bytes = 4;
39 integer |= (bytes - 1);
40 Put(static_cast<int>(integer & 0xff), "IntPart1");
41 if (bytes > 1) Put(static_cast<int>((integer >> 8) & 0xff), "IntPart2");
42 if (bytes > 2) Put(static_cast<int>((integer >> 16) & 0xff), "IntPart3");
43 if (bytes > 3) Put(static_cast<int>((integer >> 24) & 0xff), "IntPart4");
47 void SnapshotByteSink::PutRaw(const byte* data, int number_of_bytes,
48 const char* description) {
49 data_.AddAll(Vector<byte>(const_cast<byte*>(data), number_of_bytes));
53 bool SnapshotByteSource::AtEOF() {
54 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false;
55 for (int x = position_; x < length_; x++) {
56 if (data_[x] != SerializerDeserializer::nop()) return false;
62 bool SnapshotByteSource::GetBlob(const byte** data, int* number_of_bytes) {
64 *number_of_bytes = size;
66 if (position_ + size <= length_) {
67 *data = &data_[position_];
71 Advance(length_ - position_); // proceed until end.
76 } // namespace v8::internal