All files / lib/deserialize/address deserializeAddress.ts

100% Statements 11/11
100% Branches 4/4
100% Functions 1/1
100% Lines 11/11

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    1x 1x 1x 1x 1x           1x 501x   497x   2x   1x   1x      
import { BufferReader } from "@node-lightning/bufio";
import { Address } from "../../domain/Address";
import { AddressType } from "../../domain/AddressType";
import { deserializeIPv4 } from "./deserializeIPv4";
import { deserializeIPv6 } from "./deserializeIPv6";
import { deserializeTor2 } from "./deserializeTor2";
import { deserializeTor3 } from "./deserializeTor3";
 
/**
 * Deserializes an address based on the type and returns
 * an instance of Address as a polymorphic type.
 */
export function deserializeAddress(type: AddressType, reader: BufferReader): Address {
    switch (type) {
        case AddressType.IPv4:
            return deserializeIPv4(reader);
        case AddressType.IPv6:
            return deserializeIPv6(reader);
        case AddressType.TOR2:
            return deserializeTor2(reader);
        case AddressType.TOR3:
            return deserializeTor3(reader);
    }
}