blob: 7aab3c54ad5feba48236ec0bbdc026a7dca349b5 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ZIRCON_SYSTEM_HOST_FIDL_INCLUDE_FIDL_ORDINALS_H_
#define ZIRCON_SYSTEM_HOST_FIDL_INCLUDE_FIDL_ORDINALS_H_
#include "raw_ast.h"
namespace fidl {
namespace ordinals {
// Returns the Selector. If the Selector attribute is present, the
// function returns its value; otherwise, it returns the name parameter.
std::string GetSelector(const raw::AttributeList* attributes,
SourceLocation name);
// Computes the ordinal for this method per the FIDL spec.
//
// The ordinal value is equal to
// *((int32_t *)sha256(library_name + "." + interface_name + "/" + method_name)) & 0x7fffffff;
// If |method| has an Selector attribute, that value will be used as the
// method_name.
raw::Ordinal GetGeneratedOrdinal(const std::vector<StringView>& library_name,
const StringView& interface_name,
const raw::InterfaceMethod& method);
// Retrieves the correct ordinal for this method per the FIDL spec.
//
// If |method.ordinal| is not null, this method will return |method.ordinal|.
// Otherwise, the ordinal value is computed with GetGeneratedOrdinal.
raw::Ordinal GetOrdinal(const std::vector<StringView>& library_name,
const StringView& interface_name,
const raw::InterfaceMethod& method);
} // namespace ordinals
} // namespace fidl
#endif // ZIRCON_SYSTEM_HOST_FIDL_INCLUDE_FIDL_ORDINALS_H_