import { codec , Schema } from '@liskhq/lisk-codec' ; import { P2PPeerInfo , P2PNodeInfo , ProtocolPeerInfo } from '../types' ; import { InvalidPeerInfoError , InvalidNodeInfoError } from '../errors' ; export const decodePeerInfo = ( peerInfoSchema , data ? ) : P2PPeerInfo => { try { if ( ! Buffer . isBuffer ( data ) ) { throw new Error ( 'Invalid encoded data' ) ; } return codec . decode < P2PPeerInfo > ( peerInfoSchema , data ) ; } catch ( error ) { throw new InvalidPeerInfoError ( ( error as Error ) . message ) ; } } ; export const decodeNodeInfo = ( nodeInfoSchema , data ? ) : P2PNodeInfo => { try { if ( ! Buffer . isBuffer ( data ) ) { throw new Error ( 'Invalid encoded data' ) ; } return codec . decode < P2PNodeInfo > ( nodeInfoSchema , data ) ; } catch ( error ) { throw new InvalidNodeInfoError ( ( error as Error ) . message ) ; } } ; export const encodePeerInfo = ( peerInfoSchema , data ) : Buffer => codec . encode ( peerInfoSchema , data ) ; export const encodeNodeInfo = ( nodeInfoSchema , data ) : Buffer => codec . encode ( nodeInfoSchema , data ) ;