get method

T get (
  1. int id
)

Retrieves the stored object with the ID id from this box's database. Returns null if not found.

Implementation

T get(int id) {
  final dataPtrPtr = allocate<Pointer<Uint8>>();
  final sizePtr = allocate<IntPtr>();

  try {
    // get element with specified id from database
    return _store.runInTransaction(TxMode.Read, () {
      checkObx(bindings.obx_box_get(_cBox, id, dataPtrPtr, sizePtr));

      // ignore: omit_local_variable_types
      Pointer<Uint8> dataPtr = dataPtrPtr.value;
      final size = sizePtr.value;

      // create a no-copy view
      final bytes = dataPtr.asTypedList(size);

      return _fbManager.unmarshal(bytes);
    });
  } finally {
    free(dataPtrPtr);
    free(sizePtr);
  }
}