X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=blobdiff_plain;f=ts%2Fstructs%2FCustomMessageReader.mts;h=4f31381980091a1fc269978058c6c1cfec8d5ae8;hp=4189b3348ab736d83af6835551e25b6007a19c97;hb=c629a01650402c8e2f9b9db8ced9ed63ce687727;hpb=d1d0121c000b713c10fd0bedd249eb8dda2e4db7 diff --git a/ts/structs/CustomMessageReader.mts b/ts/structs/CustomMessageReader.mts index 4189b334..4f313819 100644 --- a/ts/structs/CustomMessageReader.mts +++ b/ts/structs/CustomMessageReader.mts @@ -283,7 +283,13 @@ import * as bindings from '../bindings.mjs' +/** An implementation of CustomMessageReader */ export interface CustomMessageReaderInterface { + /**Decodes a custom message to `CustomMessageType`. If the given message type is known to the + * implementation and the message could be decoded, must return `Ok(Some(message))`. If the + * message type is unknown to the implementation, must return `Ok(None)`. If a decoding error + * occur, must return `Err(DecodeError::X)` where `X` details the encountered error. + */ read(message_type: number, buffer: Uint8Array): Result_COption_TypeZDecodeErrorZ; } @@ -291,6 +297,10 @@ class LDKCustomMessageReaderHolder { held: CustomMessageReader; } +/** + * Trait to be implemented by custom message (unrelated to the channel/gossip LN layers) + * decoders. + */ export class CustomMessageReader extends CommonBase { /* @internal */ public bindings_instance?: bindings.LDKCustomMessageReader; @@ -301,7 +311,8 @@ export class CustomMessageReader extends CommonBase { this.bindings_instance = null; } - static new_impl(arg: CustomMessageReaderInterface): CustomMessageReader { + /** Creates a new instance of CustomMessageReader from a given implementation */ + public static new_impl(arg: CustomMessageReaderInterface): CustomMessageReader { const impl_holder: LDKCustomMessageReaderHolder = new LDKCustomMessageReaderHolder(); let structImplementation = { read (message_type: number, buffer: number): number { @@ -317,6 +328,13 @@ export class CustomMessageReader extends CommonBase { impl_holder.held.bindings_instance = structImplementation; return impl_holder.held; } + + /** + * Decodes a custom message to `CustomMessageType`. If the given message type is known to the + * implementation and the message could be decoded, must return `Ok(Some(message))`. If the + * message type is unknown to the implementation, must return `Ok(None)`. If a decoding error + * occur, must return `Err(DecodeError::X)` where `X` details the encountered error. + */ public read(message_type: number, buffer: Uint8Array): Result_COption_TypeZDecodeErrorZ { const ret: number = bindings.CustomMessageReader_read(this.ptr, message_type, bindings.encodeUint8Array(buffer)); const ret_hu_conv: Result_COption_TypeZDecodeErrorZ = Result_COption_TypeZDecodeErrorZ.constr_from_ptr(ret);