OLD | NEW |
| (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 | |
OLD | NEW |