Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10 | |
| 11 | |
| 12 | namespace v8 { |
| 13 | namespace internal { |
| 14 | |
| 15 | void SnapshotByteSource::CopyRaw(byte* to, int number_of_bytes) { |
| 16 | memcpy(to, data_ + position_, number_of_bytes); |
| 17 | position_ += number_of_bytes; |
| 18 | } |
| 19 | |
| 20 | |
| 21 | void 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 | |
| 36 | void 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 | |
| 42 | int 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 |