Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | 1x 1x 1x 1x 1x 40x 40x 40x 36x 3x 1x 1x 1x 36x 36x 36x 36x 36x 37x 1x 17x 17x 17x 17x 1x 1x 3x 3x 3x 3x 3x 3x 4x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 2x 2x 1x 1x 1x 1x 1x 2x 1x 1x 1x | import { BufferReader, BufferWriter } from '@node-dlc/bufio';
import { MessageType } from '../MessageType';
import { getTlv } from '../serialize/getTlv';
import { IDlcMessage } from './DlcMessage';
import { RoundingIntervalsV0 } from './RoundingIntervalsV0';
import { IRoundingIntervalsV0JSON } from './RoundingIntervalsV0';
export abstract class NegotiationFields {
public static deserialize(
buf: Buffer,
): NegotiationFieldsV0 | NegotiationFieldsV1 | NegotiationFieldsV2 {
const reader = new BufferReader(buf);
const type = Number(reader.readBigSize());
switch (type) {
case MessageType.NegotiationFieldsV0:
return NegotiationFieldsV0.deserialize(buf);
case MessageType.NegotiationFieldsV1:
return NegotiationFieldsV1.deserialize(buf);
case MessageType.NegotiationFieldsV2:
return NegotiationFieldsV2.deserialize(buf);
default:
throw new Error(
`Negotiation fields TLV type must be NegotiationFieldsV0, NegotiationFieldsV1 or NegotiationFieldsV2`,
);
}
}
public abstract type: number;
public abstract length: bigint;
public abstract toJSON():
| INegotiationFieldsV0JSON
| INegotiationFieldsV1JSON
| INegotiationFieldsV2JSON;
public abstract serialize(): Buffer;
}
/**
* NegotiationFields V0 contains preferences of the accepter of a DLC
* which are taken into account during DLC construction.
*/
export class NegotiationFieldsV0
extends NegotiationFields
implements IDlcMessage {
public static type = MessageType.NegotiationFieldsV0;
/**
* Deserializes an negotiation_fields_v0 message
* @param buf
*/
public static deserialize(buf: Buffer): NegotiationFieldsV0 {
const instance = new NegotiationFieldsV0();
const reader = new BufferReader(buf);
reader.readBigSize(); // read type
instance.length = reader.readBigSize();
return instance;
}
/**
* The type for negotiation_fields_v0 message. negotiation_fields_v0 = 55334
*/
public type = NegotiationFieldsV0.type;
public length: bigint;
/**
* Converts negotiation_fields_v0 to JSON
*/
public toJSON(): INegotiationFieldsV0JSON {
return {
type: this.type,
};
}
/**
* Serializes the negotiation_fields_v0 message into a Buffer
*/
public serialize(): Buffer {
const writer = new BufferWriter();
writer.writeBigSize(this.type);
writer.writeBigSize(0);
return writer.toBuffer();
}
}
/**
* NegotiationFields V1 contains preferences of the acceptor of a DLC
* which are taken into account during DLC construction.
*/
export class NegotiationFieldsV1
extends NegotiationFields
implements IDlcMessage {
public static type = MessageType.NegotiationFieldsV1;
/**
* Deserializes an negotiation_fields_v1 message
* @param buf
*/
public static deserialize(buf: Buffer): NegotiationFieldsV1 {
const instance = new NegotiationFieldsV1();
const reader = new BufferReader(buf);
reader.readBigSize(); // read type
instance.length = reader.readBigSize();
instance.roundingIntervals = RoundingIntervalsV0.deserialize(
getTlv(reader),
);
return instance;
}
/**
* The type for negotiation_fields_v1 message. negotiation_fields_v1 = 55336
*/
public type = NegotiationFieldsV1.type;
public length: bigint;
public roundingIntervals: RoundingIntervalsV0;
/**
* Converts negotiation_fields_v1 to JSON
*/
public toJSON(): INegotiationFieldsV1JSON {
return {
type: this.type,
roundingIntervals: this.roundingIntervals.toJSON(),
};
}
/**
* Serializes the negotiation_fields_v1 message into a Buffer
*/
public serialize(): Buffer {
const writer = new BufferWriter();
writer.writeBigSize(this.type);
const dataWriter = new BufferWriter();
dataWriter.writeBytes(this.roundingIntervals.serialize());
writer.writeBigSize(dataWriter.size);
writer.writeBytes(dataWriter.toBuffer());
return writer.toBuffer();
}
}
/**
* NegotiationFields V2 contains preferences of the acceptor of a DLC
* which are taken into account during DLC construction.
*/
export class NegotiationFieldsV2
extends NegotiationFields
implements IDlcMessage {
public static type = MessageType.NegotiationFieldsV2;
/**
* Deserializes an negotiation_fields_v1 message
* @param buf
*/
public static deserialize(buf: Buffer): NegotiationFieldsV2 {
const instance = new NegotiationFieldsV2();
const reader = new BufferReader(buf);
reader.readBigSize(); // read type
instance.length = reader.readBigSize();
reader.readBigSize(); // num_disjoint_events
while (!reader.eof) {
instance.negotiationFieldsList.push(
NegotiationFields.deserialize(getTlv(reader)),
);
}
return instance;
}
/**
* The type for negotiation_fields_v2 message. negotiation_fields_v2 = 55346
*/
public type = NegotiationFieldsV2.type;
public length: bigint;
public negotiationFieldsList: NegotiationFields[] = [];
/**
* Converts negotiation_fields_v2 to JSON
*/
public toJSON(): INegotiationFieldsV2JSON {
return {
type: this.type,
negotiationFieldsList: this.negotiationFieldsList.map((field) =>
field.toJSON(),
),
};
}
/**
* Serializes the negotiation_fields_v2 message into a Buffer
*/
public serialize(): Buffer {
const writer = new BufferWriter();
writer.writeBigSize(this.type);
const dataWriter = new BufferWriter();
dataWriter.writeBigSize(this.negotiationFieldsList.length);
for (const negotiationFields of this.negotiationFieldsList) {
dataWriter.writeBytes(negotiationFields.serialize());
}
writer.writeBigSize(dataWriter.size);
writer.writeBytes(dataWriter.toBuffer());
return writer.toBuffer();
}
}
export interface INegotiationFieldsV0JSON {
type: number;
}
export interface INegotiationFieldsV1JSON {
type: number;
roundingIntervals: IRoundingIntervalsV0JSON;
}
export interface INegotiationFieldsV2JSON {
type: number;
negotiationFieldsList:
| INegotiationFieldsV0JSON[]
| INegotiationFieldsV1JSON[]
| INegotiationFieldsV2JSON[];
}
|