Class MDBVal

  • All Implemented Interfaces:
    java.lang.AutoCloseable, NativeResource, Pointer

    public class MDBVal
    extends Struct
    implements NativeResource
    Generic structure used for passing keys and data in and out of the database.

    Values returned from the database are valid only until a subsequent update operation, or the end of the transaction. Do not modify or free them, they commonly point into the database itself.

    Key sizes must be between 1 and env_get_maxkeysize inclusive. The same applies to data sizes in databases with the DUPSORT flag. Other data items can in theory be from 0 to 0xffffffff bytes long.

    Member documentation

    • mv_size – Size of the data item.
    • mv_data – Address of the data item.

    Layout

    
     struct MDB_val {
         size_t mv_size;
         void * mv_data;
     }
    • Field Detail

      • SIZEOF

        The struct size in bytes.
      • ALIGNOF

        The struct alignment in bytes.
      • MV_SIZE, MV_DATA

        The struct member offsets.
    • Constructor Detail

      • MDBVal

        public MDBVal​(java.nio.ByteBuffer container)
        Creates a MDBVal instance at the current position of the specified ByteBuffer container. Changes to the buffer's content will be visible to the struct instance and vice versa.

        The created instance holds a strong reference to the container object.

    • Method Detail

      • sizeof

        public int sizeof()
        Description copied from class: Struct
        Returns sizeof(struct).
        Specified by:
        sizeof in class Struct
      • mv_size

        public long mv_size()
        Returns the value of the mv_size field.
      • mv_data

        @Nullable
        public java.nio.ByteBuffer mv_data()
        Returns a ByteBuffer view of the data pointed to by the mv_data field.
      • mv_size

        public MDBVal mv_size​(long value)
        Sets the specified value to the mv_size field.
      • mv_data

        public MDBVal mv_data​(@Nullable
                              java.nio.ByteBuffer value)
        Sets the address of the specified ByteBuffer to the mv_data field.
      • set

        public MDBVal set​(long mv_size,
                          @Nullable
                          java.nio.ByteBuffer mv_data)
        Initializes this struct with the specified values.
      • set

        public MDBVal set​(MDBVal src)
        Copies the specified struct data to this struct.
        Parameters:
        src - the source struct
        Returns:
        this struct
      • malloc

        public static MDBVal malloc()
        Returns a new MDBVal instance allocated with memAlloc. The instance must be explicitly freed.
      • calloc

        public static MDBVal calloc()
        Returns a new MDBVal instance allocated with memCalloc. The instance must be explicitly freed.
      • create

        public static MDBVal create​(long address)
        Returns a new MDBVal instance for the specified memory address.
      • createSafe

        @Nullable
        public static MDBVal createSafe​(long address)
        Like create, but returns null if address is NULL.
      • malloc

        public static MDBVal.Buffer malloc​(int capacity)
        Returns a new MDBVal.Buffer instance allocated with memAlloc. The instance must be explicitly freed.
        Parameters:
        capacity - the buffer capacity
      • calloc

        public static MDBVal.Buffer calloc​(int capacity)
        Returns a new MDBVal.Buffer instance allocated with memCalloc. The instance must be explicitly freed.
        Parameters:
        capacity - the buffer capacity
      • create

        public static MDBVal.Buffer create​(long address,
                                           int capacity)
        Create a MDBVal.Buffer instance at the specified memory.
        Parameters:
        address - the memory address
        capacity - the buffer capacity
      • createSafe

        @Nullable
        public static MDBVal.Buffer createSafe​(long address,
                                               int capacity)
        Like create, but returns null if address is NULL.
      • mallocStack

        public static MDBVal mallocStack()
        Returns a new MDBVal instance allocated on the thread-local MemoryStack.
      • callocStack

        public static MDBVal callocStack()
        Returns a new MDBVal instance allocated on the thread-local MemoryStack and initializes all its bits to zero.
      • mallocStack

        public static MDBVal mallocStack​(MemoryStack stack)
        Returns a new MDBVal instance allocated on the specified MemoryStack.
        Parameters:
        stack - the stack from which to allocate
      • callocStack

        public static MDBVal callocStack​(MemoryStack stack)
        Returns a new MDBVal instance allocated on the specified MemoryStack and initializes all its bits to zero.
        Parameters:
        stack - the stack from which to allocate
      • mallocStack

        public static MDBVal.Buffer mallocStack​(int capacity)
        Returns a new MDBVal.Buffer instance allocated on the thread-local MemoryStack.
        Parameters:
        capacity - the buffer capacity
      • callocStack

        public static MDBVal.Buffer callocStack​(int capacity)
        Returns a new MDBVal.Buffer instance allocated on the thread-local MemoryStack and initializes all its bits to zero.
        Parameters:
        capacity - the buffer capacity
      • mallocStack

        public static MDBVal.Buffer mallocStack​(int capacity,
                                                MemoryStack stack)
        Returns a new MDBVal.Buffer instance allocated on the specified MemoryStack.
        Parameters:
        stack - the stack from which to allocate
        capacity - the buffer capacity
      • callocStack

        public static MDBVal.Buffer callocStack​(int capacity,
                                                MemoryStack stack)
        Returns a new MDBVal.Buffer instance allocated on the specified MemoryStack and initializes all its bits to zero.
        Parameters:
        stack - the stack from which to allocate
        capacity - the buffer capacity
      • nmv_size

        public static long nmv_size​(long struct)
        Unsafe version of mv_size().
      • nmv_data

        @Nullable
        public static java.nio.ByteBuffer nmv_data​(long struct)
        Unsafe version of mv_data.
      • nmv_size

        public static void nmv_size​(long struct,
                                    long value)
        Sets the specified value to the mv_size field of the specified struct.
      • nmv_data

        public static void nmv_data​(long struct,
                                    @Nullable
                                    java.nio.ByteBuffer value)
        Unsafe version of mv_data.