X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FOnionMessageContents.java;h=999f5a01dcaae8ec2d06d146355f93f775a599f6;hb=2bb592fb946e316dba9f4d1123f8ac72ff4e9bf8;hp=8bc1a7ed1f015ed5363f880530722896b45a1cca;hpb=40764e2a87c8cc70c5749a4d681f68842f975f59;p=ldk-java diff --git a/src/main/java/org/ldk/structs/OnionMessageContents.java b/src/main/java/org/ldk/structs/OnionMessageContents.java index 8bc1a7ed..999f5a01 100644 --- a/src/main/java/org/ldk/structs/OnionMessageContents.java +++ b/src/main/java/org/ldk/structs/OnionMessageContents.java @@ -7,40 +7,98 @@ import java.util.Arrays; import java.lang.ref.Reference; import javax.annotation.Nullable; - /** - * The contents of an onion message. In the context of offers, this would be the invoice, invoice - * request, or invoice error. + * The contents of an onion message. */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class OnionMessageContents extends CommonBase { - private OnionMessageContents(Object _dummy, long ptr) { super(ptr); } + final bindings.LDKOnionMessageContents bindings_instance; + OnionMessageContents(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private OnionMessageContents(bindings.LDKOnionMessageContents arg) { + super(bindings.LDKOnionMessageContents_new(arg)); + this.ptrs_to.add(arg); + this.bindings_instance = arg; + } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - super.finalize(); + if (ptr != 0) { bindings.OnionMessageContents_free(ptr); } super.finalize(); + } + /** + * Destroys the object, freeing associated resources. After this call, any access + * to this object may result in a SEGFAULT or worse. + * + * You should generally NEVER call this method. You should let the garbage collector + * do this for you when it finalizes objects. However, it may be useful for types + * which represent locks and should be closed immediately to avoid holding locks + * until the GC runs. + */ + public void destroy() { if (ptr != 0) { bindings.OnionMessageContents_free(ptr); } + ptr = 0; + } + public static interface OnionMessageContentsInterface { + /** + * Returns the TLV type identifying the message contents. MUST be >= 64. + */ + long tlv_type(); + /** + * Serialize the object into a byte array + */ + byte[] write(); + /** + * Return a human-readable "debug" string describing this object + */ + String debug_str(); + } + private static class LDKOnionMessageContentsHolder { OnionMessageContents held; } + public static OnionMessageContents new_impl(OnionMessageContentsInterface arg) { + final LDKOnionMessageContentsHolder impl_holder = new LDKOnionMessageContentsHolder(); + impl_holder.held = new OnionMessageContents(new bindings.LDKOnionMessageContents() { + @Override public long tlv_type() { + long ret = arg.tlv_type(); + Reference.reachabilityFence(arg); + return ret; + } + @Override public byte[] write() { + byte[] ret = arg.write(); + Reference.reachabilityFence(arg); + return ret; + } + @Override public String debug_str() { + String ret = arg.debug_str(); + Reference.reachabilityFence(arg); + return ret; + } + }); + return impl_holder.held; } - static OnionMessageContents constr_from_ptr(long ptr) { - bindings.LDKOnionMessageContents raw_val = bindings.LDKOnionMessageContents_ref_from_ptr(ptr); - if (raw_val.getClass() == bindings.LDKOnionMessageContents.Custom.class) { - return new Custom(ptr, (bindings.LDKOnionMessageContents.Custom)raw_val); - } - assert false; return null; // Unreachable without extending the (internal) bindings interface + /** + * Returns the TLV type identifying the message contents. MUST be >= 64. + */ + public long tlv_type() { + long ret = bindings.OnionMessageContents_tlv_type(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + /** + * Serialize the object into a byte array + */ + public byte[] write() { + byte[] ret = bindings.OnionMessageContents_write(this.ptr); + Reference.reachabilityFence(this); + return ret; } /** - * A custom onion message specified by the user. + * Return a human-readable "debug" string describing this object */ - public final static class Custom extends OnionMessageContents { - public final org.ldk.structs.CustomOnionMessageContents custom; - private Custom(long ptr, bindings.LDKOnionMessageContents.Custom obj) { - super(null, ptr); - long custom = obj.custom; - CustomOnionMessageContents ret_hu_conv = new CustomOnionMessageContents(null, custom); - if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; - this.custom = ret_hu_conv; - } + public String debug_str() { + String ret = bindings.OnionMessageContents_debug_str(this.ptr); + Reference.reachabilityFence(this); + return ret; } + long clone_ptr() { long ret = bindings.OnionMessageContents_clone_ptr(this.ptr); Reference.reachabilityFence(this); @@ -48,28 +106,15 @@ public class OnionMessageContents extends CommonBase { } /** - * Creates a copy of the OnionMessageContents + * Creates a copy of a OnionMessageContents */ public OnionMessageContents clone() { long ret = bindings.OnionMessageContents_clone(this.ptr); Reference.reachabilityFence(this); if (ret >= 0 && ret <= 4096) { return null; } - org.ldk.structs.OnionMessageContents ret_hu_conv = org.ldk.structs.OnionMessageContents.constr_from_ptr(ret); + OnionMessageContents ret_hu_conv = new OnionMessageContents(null, ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } - /** - * Utility method to constructs a new Custom-variant OnionMessageContents - */ - public static OnionMessageContents custom(org.ldk.structs.CustomOnionMessageContents a) { - long ret = bindings.OnionMessageContents_custom(a.ptr); - Reference.reachabilityFence(a); - if (ret >= 0 && ret <= 4096) { return null; } - org.ldk.structs.OnionMessageContents ret_hu_conv = org.ldk.structs.OnionMessageContents.constr_from_ptr(ret); - if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; - if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); }; - return ret_hu_conv; - } - }