Google is committed to advancing racial equity for Black communities. See how.

Remove a protocol method

Overview

- init step 1 step 2 step 3 step 4
fidl link link link
dart link link
go link link link
hlcpp link link
llcpp link link
rust link link link

Initial State

FIDL

protocol Example {
    ExistingMethod();
    OldMethod();
};

Dart

class Server extends fidllib.Example {
  @override
  Future<void> existingMethod() async {}

  @override
  Future<void> oldMethod() async {}
}

void client(fidllib.ExampleProxy client) async {
  await client.existingMethod();
  await client.oldMethod();
}

Go

type client struct {
    removeMethod *lib.ExampleWithCtxInterface
}

func (c client) test() {
    c.removeMethod.ExistingMethod(context.Background())
    c.removeMethod.OldMethod(context.Background())
}

type server struct{}

// Assert that server implements the Example interface
var _ lib.ExampleWithCtx = &server{}

func (*server) ExistingMethod(fidl.Context) error {
    return nil
}

func (*server) OldMethod(fidl.Context) error {
    return nil
}

HLCPP

class Server : public fidl_test::Example {
  void ExistingMethod() final {}
  void OldMethod() final {}
};

void client(fidl_test::ExamplePtr client) {
  client->ExistingMethod();
  client->OldMethod();
}

LLCPP

class Server final : public fidl::WireServer<fidl_test::Example> {
 public:
  void ExistingMethod(ExistingMethodRequestView request,
                      ExistingMethodCompleter::Sync& completer) final {}
  void OldMethod(OldMethodRequestView request, OldMethodCompleter::Sync& completer) final {}
};

void client(fidl::WireClient<fidl_test::Example> client) {
  client->ExistingMethod();
  client->OldMethod();
}

Rust

struct ExampleFakeProxy;

impl fidl_lib::ExampleProxyInterface for ExampleFakeProxy {
    fn existing_method(&self) -> Result<(), fidl::Error> {
        Ok(())
    }
    fn old_method(&self) -> Result<(), fidl::Error> {
        Ok(())
    }
}

async fn example_service(chan: fasync::Channel) -> Result<(), fidl::Error> {
    let mut stream = fidl_lib::ExampleRequestStream::from_channel(chan);
    while let Some(req) = stream.try_next().await? {
        match req {
            fidl_lib::ExampleRequest::ExistingMethod { .. } => {}
            fidl_lib::ExampleRequest::OldMethod { .. } => {}
        }
    }
    Ok(())
}

Update FIDL Library

  • Mark the method that is being removed with the [Transitional] attribute.
  protocol Example {
      ExistingMethod();
+     @transitional
      OldMethod();
  };

Update Source Code

Dart

  • Remove references to the method in client code and server code.
  class Server extends fidllib.Example {
    @override
    Future<void> existingMethod() async {}
- 
-   @override
-   Future<void> oldMethod() async {}
  }
  
  void client(fidllib.ExampleProxy client) async {
    await client.existingMethod();
-   await client.oldMethod();
  }

Go

  • Embed the protocol's WithCtxTransitionBase struct into the server type.
  • Remove the implementation for the method being removed from the server.
  • Remove any references to the method in client code (e.g. request calls being made)
  type client struct {
    removeMethod *lib.ExampleWithCtxInterface
  }
  
  func (c client) test() {
    c.removeMethod.ExistingMethod(context.Background())
-   c.removeMethod.OldMethod(context.Background())
  }
  
- type server struct{}
+ type server struct {
+   lib.ExampleWithCtxInterface
+ }
  
  // Assert that server implements the Example interface
  var _ lib.ExampleWithCtx = &server{}
  
  func (*server) ExistingMethod(fidl.Context) error {
    return nil
  }
  
- func (*server) OldMethod(fidl.Context) error {
-   return nil
- }
- 

HLCPP

  • Remove references to the method in client code and server code.
  class Server : public fidl_test::Example {
    void ExistingMethod() final {}
-   void OldMethod() final {}
  };
  
- void client(fidl_test::ExamplePtr client) {
-   client->ExistingMethod();
-   client->OldMethod();
- }
+ void client(fidl_test::ExamplePtr client) { client->ExistingMethod(); }

LLCPP

  • Remove references to the method in client code and server code.
  class Server final : public fidl::WireServer<fidl_test::Example> {
   public:
    void ExistingMethod(ExistingMethodRequestView request,
                        ExistingMethodCompleter::Sync& completer) final {}
-   void OldMethod(OldMethodRequestView request, OldMethodCompleter::Sync& completer) final {}
  };
  
- void client(fidl::WireClient<fidl_test::Example> client) {
-   client->ExistingMethod();
-   client->OldMethod();
- }
+ void client(fidl::WireClient<fidl_test::Example> client) { client->ExistingMethod(); }

Rust

  • Add #[allow(unreachable_patterns)] to the server's request stream match.
  • Replace the match arm for the method that is being removed with a catchall (_) arm.
  • Remove any references to the method in client code (e.g. as part of implementations of the ProxyInterface).
  struct ExampleFakeProxy;
  
  impl fidl_lib::ExampleProxyInterface for ExampleFakeProxy {
      fn existing_method(&self) -> Result<(), fidl::Error> {
-         Ok(())
-     }
-     fn old_method(&self) -> Result<(), fidl::Error> {
          Ok(())
      }
  }
  
  async fn example_service(chan: fasync::Channel) -> Result<(), fidl::Error> {
      let mut stream = fidl_lib::ExampleRequestStream::from_channel(chan);
      while let Some(req) = stream.try_next().await? {
+         #[allow(unreachable_patterns)]
          match req {
              fidl_lib::ExampleRequest::ExistingMethod { .. } => {}
-             fidl_lib::ExampleRequest::OldMethod { .. } => {}
+             _ => {}
          }
      }
      Ok(())
  }

Update FIDL Library

  • Remove the method.
  protocol Example {
      ExistingMethod();
-     @transitional
-     OldMethod();
  };

Update Source Code

Go

  • Remove the embedded WithCtxInterface struct.
  type client struct {
    removeMethod *lib.ExampleWithCtxInterface
  }
  
  func (c client) test() {
    c.removeMethod.ExistingMethod(context.Background())
  }
  
- type server struct {
-   lib.ExampleWithCtxInterface
- }
+ type server struct{}
  
  // Assert that server implements the Example interface
  var _ lib.ExampleWithCtx = &server{}
  
  func (*server) ExistingMethod(fidl.Context) error {
    return nil
  }
  

Rust

  • Remove the #[allow(unreachable_patterns)] attribute and the catch-all match arm.
  struct ExampleFakeProxy;
  
  impl fidl_lib::ExampleProxyInterface for ExampleFakeProxy {
      fn existing_method(&self) -> Result<(), fidl::Error> {
          Ok(())
      }
  }
  
  async fn example_service(chan: fasync::Channel) -> Result<(), fidl::Error> {
      let mut stream = fidl_lib::ExampleRequestStream::from_channel(chan);
      while let Some(req) = stream.try_next().await? {
-         #[allow(unreachable_patterns)]
          match req {
              fidl_lib::ExampleRequest::ExistingMethod { .. } => {}
-             _ => {}
          }
      }
      Ok(())
  }