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/bindings/lib/message.h" 8 9 namespace mojo { 10 namespace internal { 11 12 MessageBuilder::MessageBuilder(uint32_t message_name, size_t payload_size) 13 : buf_(sizeof(MessageHeader) + payload_size) { 14 MessageHeader* header = 15 static_cast<MessageHeader*>(buf_.Allocate(sizeof(MessageHeader))); 16 header->num_bytes = static_cast<uint32_t>(buf_.size()); 17 header->name = message_name; 18 } 19 20 MessageBuilder::~MessageBuilder() { 21 } 22 23 MessageData* MessageBuilder::Finish() { 24 return static_cast<MessageData*>(buf_.Leak()); 25 } 26 27 } // namespace internal 28 } // namespace mojo 29