Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(520)

Side by Side Diff: mojo/public/bindings/lib/message_builder.cc

Issue 220243007: Mojo: Move mojo/public/bindings/lib to mojo/public/cpp/bindings/lib. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/public/bindings/lib/message_builder.h ('k') | mojo/public/bindings/lib/message_internal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium 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 #include "mojo/public/bindings/lib/message_builder.h"
6
7 #include "mojo/public/cpp/bindings/message.h"
8
9 namespace mojo {
10 namespace internal {
11
12 template <typename Header>
13 void Allocate(Buffer* buf, Header** header) {
14 *header = static_cast<Header*>(buf->Allocate(sizeof(Header)));
15 (*header)->num_bytes = sizeof(Header);
16 }
17
18 MessageBuilder::MessageBuilder(uint32_t name, size_t payload_size)
19 : buf_(sizeof(MessageHeader) + payload_size) {
20 MessageHeader* header;
21 Allocate(&buf_, &header);
22 header->num_fields = 2;
23 header->name = name;
24 }
25
26 MessageBuilder::~MessageBuilder() {
27 }
28
29 void MessageBuilder::Finish(Message* message) {
30 uint32_t num_bytes = static_cast<uint32_t>(buf_.size());
31 message->AdoptData(num_bytes, static_cast<MessageData*>(buf_.Leak()));
32 }
33
34 MessageBuilder::MessageBuilder(size_t size)
35 : buf_(size) {
36 }
37
38 MessageWithRequestIDBuilder::MessageWithRequestIDBuilder(uint32_t name,
39 size_t payload_size,
40 uint32_t flags,
41 uint64_t request_id)
42 : MessageBuilder(sizeof(MessageHeaderWithRequestID) + payload_size) {
43 MessageHeaderWithRequestID* header;
44 Allocate(&buf_, &header);
45 header->num_fields = 3;
46 header->name = name;
47 header->flags = flags;
48 header->request_id = request_id;
49 }
50
51 } // namespace internal
52 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/bindings/lib/message_builder.h ('k') | mojo/public/bindings/lib/message_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698