
org.gnome.glib.LogField Maven / Gradle / Ivy
// 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.glib;
import io.github.jwharm.javagi.base.ManagedInstance;
import io.github.jwharm.javagi.interop.Interop;
import java.lang.Deprecated;
import java.lang.String;
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;
/**
* Structure representing a single field in a structured log entry. See
* g_log_structured() for details.
*
* Log fields may contain arbitrary values, including binary with embedded nul
* bytes. If the field contains a string, the string must be UTF-8 encoded and
* have a trailing nul byte. Otherwise, {@code length} must be set to a non-negative
* value.
* @version 2.50
*/
@Generated("io.github.jwharm.JavaGI")
public class LogField extends ManagedInstance {
static {
GLib.javagi$ensureInitialized();
}
/**
* Create a LogField proxy instance for the provided memory address.
*
* @param address the memory address of the native object
*/
public LogField(MemorySegment address) {
super(Interop.reinterpret(address, getMemoryLayout().byteSize()));
}
/**
* Allocate a new LogField.
*
* @param arena to control the memory allocation scope
*/
public LogField(Arena arena) {
super(arena.allocate(getMemoryLayout()));
}
/**
* Allocate a new LogField.
* The memory is allocated with {@link Arena#ofAuto}.
*/
public LogField() {
super(Arena.ofAuto().allocate(getMemoryLayout()));
}
/**
* Allocate a new LogField with the fields set to the provided values.
*
* @param key value for the field {@code key}
* @param value value for the field {@code value}
* @param length value for the field {@code length}
* @param arena to control the memory allocation scope
*/
public LogField(String key, MemorySegment value, long length, Arena arena) {
this(arena);
writeKey(key, arena);
writeValue(value);
writeLength(length);
}
/**
* Allocate a new LogField with the fields set to the provided values.
* The memory is allocated with {@link Arena#ofAuto}.
*
* @param key value for the field {@code key}
* @param value value for the field {@code value}
* @param length value for the field {@code length}
*/
public LogField(String key, MemorySegment value, long length) {
this(Arena.ofAuto());
writeKey(key, Arena.ofAuto());
writeValue(value);
writeLength(length);
}
/**
* The memory layout of the native struct.
* @return the memory layout
*/
public static MemoryLayout getMemoryLayout() {
return MemoryLayout.structLayout(
ValueLayout.ADDRESS.withName("key"),
ValueLayout.ADDRESS.withName("value"),
ValueLayout.JAVA_LONG.withName("length")
).withName("GLogField");
}
/**
* Allocate a new LogField.
*
* @param arena to control the memory allocation scope
* @return a new, uninitialized {@link LogField}
* @deprecated Replaced by {@link LogField#LogField(Arena)}
*/
@Deprecated
public static LogField allocate(Arena arena) {
MemorySegment segment = arena.allocate(getMemoryLayout());
return new LogField(segment);
}
/**
* Allocate a new LogField with the fields set to the provided values.
*
* @param arena to control the memory allocation scope
* @param key value for the field {@code key}
* @param value value for the field {@code value}
* @param length value for the field {@code length}
* @return a new {@link LogField} with the fields set to the provided values
* @deprecated Replaced by {@link LogField#LogField(java.lang.String, java.lang.foreign.MemorySegment, long, Arena)}
*/
@Deprecated
public static LogField allocate(Arena arena, String key, MemorySegment value, long length) {
return new LogField(key, value, length, arena);
}
/**
* Read the value of the field {@code key}.
*
* @return The value of the field {@code key}
*/
public String readKey() {
Arena _arena = Arena.ofAuto();
var _result = (MemorySegment) getMemoryLayout()
.varHandle(MemoryLayout.PathElement.groupElement("key")).get(handle());
return Interop.getStringFrom(_result, false);
}
/**
* Write a value in the field {@code key}.
*
* @param key The new value for the field {@code key}
* @param _arena to control the memory allocation scope
*/
public void writeKey(String key, Arena _arena) {
getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("key"))
.set(handle(), (key == null ? MemorySegment.NULL : Interop.allocateNativeString(key, _arena)));
}
/**
* Read the value of the field {@code value}.
*
* @return The value of the field {@code value}
*/
public MemorySegment readValue() {
var _result = (MemorySegment) getMemoryLayout()
.varHandle(MemoryLayout.PathElement.groupElement("value")).get(handle());
return _result;
}
/**
* Write a value in the field {@code value}.
*
* @param value The new value for the field {@code value}
*/
public void writeValue(MemorySegment value) {
getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("value"))
.set(handle(), (value == null ? MemorySegment.NULL : value));
}
/**
* Read the value of the field {@code length}.
*
* @return The value of the field {@code length}
*/
public long readLength() {
var _result = (long) getMemoryLayout()
.varHandle(MemoryLayout.PathElement.groupElement("length")).get(handle());
return _result;
}
/**
* Write a value in the field {@code length}.
*
* @param length The new value for the field {@code length}
*/
public void writeLength(long length) {
getMemoryLayout().varHandle(MemoryLayout.PathElement.groupElement("length"))
.set(handle(), length);
}
}