blob: 59fc6fcd872e06ec5571df897feadf00ce8d1a51 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
// Copyright 2006 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <limits>
#include "base/pickle.h"
#include "components/sessions/session_command.h"
namespace sessions {
SessionCommand::SessionCommand(id_type id, size_type size)
: id_(id),
contents_(size, 0) {
}
SessionCommand::SessionCommand(id_type id, const Pickle& pickle)
: id_(id),
contents_(pickle.size(), 0) {
DCHECK(pickle.size() < std::numeric_limits<size_type>::max());
memcpy(contents(), pickle.data(), pickle.size());
}
bool SessionCommand::GetPayload(void* dest, size_t count) const {
if (size() != count)
return false;
memcpy(dest, &(contents_[0]), count);
return true;
}
Pickle* SessionCommand::PayloadAsPickle() const {
return new Pickle(contents(), static_cast<int>(size()));
}
} // namespace sessions
|