Note: This document covers API impact only. For more details, see the ABI compatibility page

Add a bits member

Overview

-initstep 1step 2
fidllinklink
dartlinklink
golinklink
hlcpplinklink
llcpplinklink
rustlinklink

Initial State

FIDL

type Flags = flexible bits {
    OPTION_A = 1;
    OPTION_B = 2;
};

Dart

void useBits(fidllib.Flags bits) {
  if ((bits & fidllib.Flags.optionA).$value != 0) {
    print('option A is set');
  }
  if ((bits & fidllib.Flags.optionB).$value != 0) {
    print('option B is set');
  }
  if (bits.hasUnknownBits()) {
    print('unknown options: ${bits.getUnknownBits()}');
  }
}

Go

func useBits(bits lib.Flags) {
	if bits.HasBits(lib.FlagsOptionA) {
		fmt.Println("option C is set")
	}
	if bits.HasBits(lib.FlagsOptionB) {
		fmt.Println("option C is set")
	}
	if bits.HasUnknownBits() {
		fmt.Printf("unknown options: 0x%x", bits.GetUnknownBits())
	}
}

HLCPP

void use_member(fidl_test::Flags bits) {
  if (bits & fidl_test::Flags::OPTION_A) {
    printf("option A is set\n");
  }
  if (bits & fidl_test::Flags::OPTION_B) {
    printf("option B is set\n");
  }
  if (bits.has_unknown_bits()) {
    printf("unknown options: 0x%04x", uint32_t(bits.unknown_bits()));
  }
}

LLCPP

void use_bits(fidl_test::wire::Flags bits) {
  if (bits & fidl_test::wire::Flags::kOptionA) {
    printf("option A is set\n");
  }
  if (bits & fidl_test::wire::Flags::kOptionB) {
    printf("option B is set\n");
  }
  if (bits.has_unknown_bits()) {
    printf("unknown options: 0x%04x", uint32_t(bits.unknown_bits()));
  }
}

Rust

fn use_bits(bits: &fidl_lib::Flags) {
    if bits.contains(fidl_lib::Flags::OptionA) {
        println!("option A is set");
    }
    if bits.contains(fidl_lib::Flags::OptionB) {
        println!("option B is set");
    }
    if bits.has_unknown_bits() {
        println!("unknown options: {:x}", bits.get_unknown_bits());
    }
}

Update FIDL Library

  • Add the new member
  type Flags = flexible bits {
      OPTION_A = 1;
      OPTION_B = 2;
+     OPTION_C = 4;
  };

Update Source Code

Dart

  • You can now use the new member
  void useBits(fidllib.Flags bits) {
    if ((bits & fidllib.Flags.optionA).$value != 0) {
      print('option A is set');
    }
    if ((bits & fidllib.Flags.optionB).$value != 0) {
      print('option B is set');
    }
+   if ((bits & fidllib.Flags.optionC).$value != 0) {
+     print('option C is set');
+   }
    if (bits.hasUnknownBits()) {
      print('unknown options: ${bits.getUnknownBits()}');
    }
  }

Go

  • You can now use the new member
  func useBits(bits lib.Flags) {
  	if bits.HasBits(lib.FlagsOptionA) {
  		fmt.Println("option C is set")
  	}
  	if bits.HasBits(lib.FlagsOptionB) {
  		fmt.Println("option C is set")
  	}
+ 	if bits.HasBits(lib.FlagsOptionC) {
+ 		fmt.Println("option C is set")
+ 	}
  	if bits.HasUnknownBits() {
  		fmt.Printf("unknown options: 0x%x", bits.GetUnknownBits())
  	}
  }
  

HLCPP

  • You can now use the new member
  void use_member(fidl_test::Flags bits) {
    if (bits & fidl_test::Flags::OPTION_A) {
      printf("option A is set\n");
    }
    if (bits & fidl_test::Flags::OPTION_B) {
      printf("option B is set\n");
    }
+   if (bits & fidl_test::Flags::OPTION_C) {
+     printf("option C is set\n");
+   }
    if (bits.has_unknown_bits()) {
      printf("unknown options: 0x%04x", uint32_t(bits.unknown_bits()));
    }
  }

LLCPP

  • You can now use the new member
  void use_bits(fidl_test::wire::Flags bits) {
    if (bits & fidl_test::wire::Flags::kOptionA) {
      printf("option A is set\n");
    }
    if (bits & fidl_test::wire::Flags::kOptionB) {
      printf("option B is set\n");
    }
+   if (bits & fidl_test::wire::Flags::kOptionC) {
+     printf("option C is set\n");
+   }
    if (bits.has_unknown_bits()) {
      printf("unknown options: 0x%04x", uint32_t(bits.unknown_bits()));
    }
  }

Rust

  • You can now use the new member
  fn use_bits(bits: &fidl_lib::Flags) {
      if bits.contains(fidl_lib::Flags::OptionA) {
          println!("option A is set");
      }
      if bits.contains(fidl_lib::Flags::OptionB) {
          println!("option B is set");
      }
+     if bits.contains(fidl_lib::Flags::OptionC) {
+         println!("option C is set");
+     }
      if bits.has_unknown_bits() {
          println!("unknown options: {:x}", bits.get_unknown_bits());
      }
  }