1// Copyright 2018 The Fuchsia 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#ifndef ZIRCON_SYSTEM_HOST_FIDL_INCLUDE_FIDL_TYPE_SHAPE_H_ 6#define ZIRCON_SYSTEM_HOST_FIDL_INCLUDE_FIDL_TYPE_SHAPE_H_ 7 8#include <stddef.h> 9 10class TypeShape { 11public: 12 constexpr TypeShape(uint32_t size, uint32_t alignment, uint32_t depth = 0u, uint32_t max_handles = 0u, uint32_t max_out_of_line = 0u) 13 : size_(size), alignment_(alignment), depth_(depth), max_handles_(max_handles), max_out_of_line_(max_out_of_line) {} 14 constexpr TypeShape() 15 : TypeShape(0u, 0u, 0u, 0u, 0u) {} 16 17 TypeShape(const TypeShape&) = default; 18 TypeShape& operator=(const TypeShape&) = default; 19 20 uint32_t Size() const { return size_; } 21 uint32_t Alignment() const { return alignment_; } 22 uint32_t Depth() const { return depth_; } 23 uint32_t MaxHandles() const { return max_handles_; } 24 uint32_t MaxOutOfLine() const { return max_out_of_line_; } 25 26private: 27 uint32_t size_; 28 uint32_t alignment_; 29 uint32_t depth_; 30 uint32_t max_handles_; 31 uint32_t max_out_of_line_; 32}; 33 34class FieldShape { 35public: 36 explicit FieldShape(TypeShape typeshape, uint32_t offset = 0u) 37 : typeshape_(typeshape), offset_(offset) {} 38 FieldShape() 39 : FieldShape(TypeShape()) {} 40 41 TypeShape& Typeshape() { return typeshape_; } 42 TypeShape Typeshape() const { return typeshape_; } 43 44 uint32_t Size() const { return typeshape_.Size(); } 45 uint32_t Alignment() const { return typeshape_.Alignment(); } 46 uint32_t Depth() const { return typeshape_.Depth(); } 47 uint32_t Offset() const { return offset_; } 48 uint32_t MaxHandles() const { return typeshape_.MaxHandles(); } 49 uint32_t MaxOutOfLine() const { return typeshape_.MaxOutOfLine(); } 50 51 void SetTypeshape(TypeShape typeshape) { typeshape_ = typeshape; } 52 void SetOffset(uint32_t offset) { offset_ = offset; } 53 54private: 55 TypeShape typeshape_; 56 uint32_t offset_; 57}; 58 59#endif // ZIRCON_SYSTEM_HOST_FIDL_INCLUDE_FIDL_TYPE_SHAPE_H_ 60