blob: 0c4d8ed40b69faf0856dfe5993a7f91608d8ac9a [file] [log] [blame]
// Copyright 2020 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.
// NOTE: This file contains the source for FIDL examples used in documentation.
// Check that associated docs are kept in sync when modifying this file. You
// can find usages by grepping for
// `gerrit_path="examples/fidl/fuchsia.examples/types.test.fidl"`
// [START lib]
library fuchsia.examples;
// [END lib]
using zx;
// [START consts]
const BOARD_SIZE uint8 = 9;
const NAME string = "Tic-Tac-Toe";
// [END consts]
// [START bits]
type FileMode = strict bits : uint16 {
READ = 0b001;
WRITE = 0b010;
EXECUTE = 0b100;
};
// [END bits]
// [START flexible_bits]
type FlexibleFileMode = flexible bits : uint16 {
READ = 0b001;
WRITE = 0b010;
EXECUTE = 0b100;
};
// [END flexible_bits]
// [START enums]
type LocationType = strict enum {
MUSEUM = 1;
AIRPORT = 2;
RESTAURANT = 3;
};
// [END enums]
// [START flexible_enums]
type FlexibleLocationType = flexible enum {
MUSEUM = 1;
AIRPORT = 2;
RESTAURANT = 3;
};
// [END flexible_enums]
// [START structs]
type Color = struct {
id uint32;
@allow_deprecated_struct_defaults
name string:MAX_STRING_LENGTH = "red";
};
// [END structs]
// [START resource_structs]
type EventStruct = resource struct {
event zx.Handle:<EVENT, optional>;
};
// [END resource_structs]
// [START unions]
type JsonValue = strict union {
1: int_value int32;
2: string_value string:MAX_STRING_LENGTH;
};
// [END unions]
// [START flexible_unions]
type FlexibleJsonValue = flexible union {
1: int_value int32;
2: string_value string:MAX_STRING_LENGTH;
};
// [END flexible_unions]
// [START tables]
type User = table {
1: age uint8;
2: name string:MAX_STRING_LENGTH;
};
// [END tables]
// [START protocols-preface]
type GameState = struct {};
// [END protocols-preface]
// NOTE: a version of this protocol using error types is also used in the
// bindings reference docs, but is not tested
// [START protocols]
closed protocol TicTacToe {
strict StartGame(struct {
start_first bool;
});
strict MakeMove(struct {
row uint8;
col uint8;
}) -> (struct {
success bool;
new_state box<GameState>;
});
strict -> OnOpponentMove(struct {
new_state GameState;
});
};
// [END protocols]