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/cpp/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) : buf_(size) { | |
35 } | |
36 | |
37 MessageWithRequestIDBuilder::MessageWithRequestIDBuilder(uint32_t name, | |
38 size_t payload_size, | |
39 uint32_t flags, | |
40 uint64_t request_id) | |
41 : MessageBuilder(sizeof(MessageHeaderWithRequestID) + payload_size) { | |
42 MessageHeaderWithRequestID* header; | |
43 Allocate(&buf_, &header); | |
44 header->num_fields = 3; | |
45 header->name = name; | |
46 header->flags = flags; | |
47 header->request_id = request_id; | |
48 } | |
49 | |
50 } // namespace internal | |
51 } // namespace mojo | |
OLD | NEW |