org.gnome.soup.Range Maven / Gradle / Ivy
Show all versions of soup Show documentation
// Java-GI - Java language bindings for GObject-Introspection-based libraries
// Copyright (C) 2022-2024 Jan-Willem Harmannij
//
// SPDX-License-Identifier: LGPL-2.1-or-later
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see .
//
// This file has been generated with Java-GI.
// Do not edit this file directly!
// Visit for more information.
//
package org.gnome.soup;
import io.github.jwharm.javagi.base.ProxyInstance;
import io.github.jwharm.javagi.interop.Interop;
import java.lang.Deprecated;
import java.lang.foreign.Arena;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import javax.annotation.processing.Generated;
/**
* Represents a byte range as used in the Range header.
*
* If {@code end} is non-negative, then {@code start} and {@code end} represent the bounds
* of of the range, counting from 0. (Eg, the first 500 bytes would be
* represented as {@code start} = 0 and {@code end} = 499.)
*
* If {@code end} is -1 and {@code start} is non-negative, then this represents a
* range starting at {@code start} and ending with the last byte of the
* requested resource body. (Eg, all but the first 500 bytes would be
* {@code start} = 500, and {@code end} = -1.)
*
* If {@code end} is -1 and {@code start} is negative, then it represents a "suffix
* range", referring to the last -{@code start} bytes of the resource body.
* (Eg, the last 500 bytes would be {@code start} = -500 and {@code end} = -1.)
*/
@Generated("io.github.jwharm.JavaGI")
public class Range extends ProxyInstance {
static {
Soup.javagi$ensureInitialized();
}
/**
* Create a Range proxy instance for the provided memory address.
*
* @param address the memory address of the native object
*/
public Range(MemorySegment address) {
super(Interop.reinterpret(address, getMemoryLayout().byteSize()));
}
/**
* Allocate a new Range.
*
* @param arena to control the memory allocation scope
*/
public Range(Arena arena) {
super(arena.allocate(getMemoryLayout()));
}
/**
* Allocate a new Range.
* The memory is allocated with {@link Arena#ofAuto}.
*/
public Range() {
super(Arena.ofAuto().allocate(getMemoryLayout()));
}
/**
* Allocate a new Range with the fields set to the provided values.
*
* @param start value for the field {@code start}
* @param end value for the field {@code end}
* @param arena to control the memory allocation scope
*/
public Range(long start, long end, Arena arena) {
this(arena);
writeStart(start);
writeEnd(end);
}
/**
* Allocate a new Range with the fields set to the provided values.
* The memory is allocated with {@link Arena#ofAuto}.
*
* @param start value for the field {@code start}
* @param end value for the field {@code end}
*/
public Range(long start, long end) {
this(Arena.ofAuto());
writeStart(start);
writeEnd(end);
}
/**
* The memory layout of the native struct.
* @return the memory layout
*/
public static MemoryLayout getMemoryLayout() {
return MemoryLayout.structLayout(
ValueLayout.JAVA_LONG.withName("start"),
ValueLayout.JAVA_LONG.withName("end")
).withName("SoupRange");
}
/**
* Allocate a new Range.
*
* @param arena to control the memory allocation scope
* @return a new, uninitialized {@link Range}
* @deprecated Replaced by {@link Range#Range(Arena)}
*/
@Deprecated
public static Range allocate(Arena arena) {
MemorySegment segment = arena.allocate(getMemoryLayout());
return new Range(segment);
}
/**
* Allocate a new Range with the fields set to the provided values.
*
* @param arena to control the memory allocation scope
* @param start value for the field {@code start}
* @param end value for the field {@code end}
* @return a new {@link Range} with the fields set to the provided values
* @deprecated Replaced by {@link Range#Range(long, long, Arena)}
*/
@Deprecated
public static Range allocate(Arena arena, long start, long end) {
return new Range(start, end, arena);
}
/**
* Read the value of the field {@code start}.
*
* @return The value of the field {@code start}
*/
public long readStart() {
var _result = (long) getMemoryLayout()
.varHandle(MemoryLayout.PathElement.groupElement("start")).get(handle(), 0);
return _result;
}
/**
* Write a value in the field {@code start}.
*
* @param start The new value for the field {@code start}
*/
public void writeStart(long start) {
getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("start"))
.set(handle(), 0, start);
}
/**
* Read the value of the field {@code end}.
*
* @return The value of the field {@code end}
*/
public long readEnd() {
var _result = (long) getMemoryLayout()
.varHandle(MemoryLayout.PathElement.groupElement("end")).get(handle(), 0);
return _result;
}
/**
* Write a value in the field {@code end}.
*
* @param end The new value for the field {@code end}
*/
public void writeEnd(long end) {
getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("end"))
.set(handle(), 0, end);
}
}