fuchsia / samples / 79fdad16b3522da2bfa3df4205386caf72c105bd / . / src / calculator / fidl / calculator.fidl

// Copyright 2019 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. | |

/// Library describing a calculator protocol. Such a protocol allows a calculator UI and its | |

/// mathematical operations to be independent. | |

/// | |

/// This library only operates on and returns 64-bit floating point numbers. All operations | |

/// are performed in floating point and may lose precision. | |

library fuchsia.examples.calculator; | |

/// An operation that generates a result for a single input value. | |

type UnaryOp = strict enum { | |

NEGATION = 0; | |

}; | |

/// An operation that generates a result for two input values. | |

type BinaryOp = strict enum { | |

ADDITION = 0; | |

SUBTRACTION = 1; | |

MULTIPLICATION = 2; | |

DIVISION = 3; | |

}; | |

/// The result of a failed operation. | |

type Error = struct { | |

message string:200; | |

}; | |

// [START union] | |

/// The result of an operation. A result is either a single number or an | |

/// [Error] value. | |

type Result = union { | |

1: number float64; | |

2: reserved; | |

3: error Error; | |

}; | |

// [END union] | |

/// A calculator that can perform mathematical operations. | |

@discoverable | |

protocol Calculator { | |

/// Performs the requested operation on a single value and returns the result. | |

DoUnaryOp(struct { operation UnaryOp; a float64; }) -> (struct { result Result; }); | |

/// Performs the requested operation on two values and returns the result. | |

DoBinaryOp(struct { operation BinaryOp; a float64; b float64; }) -> (struct { result Result; }); | |

}; |