PHP WebShell
Текущая директория: /usr/lib/node_modules/bitgo/node_modules/@bitgo-forks/avalanchejs/src/serializable/primitives
Просмотр файла: bytes.ts
import { bytesToString } from '@scure/base';
import { bytesForInt } from '../../fixtures/utils/bytesFor';
import { bufferToHex, concatBytes } from '../../utils/buffer';
import { serializable } from '../common/types';
import { Int } from './int';
import { Primitives } from './primatives';
import { TypeSymbols } from '../constants';
@serializable()
export class Bytes extends Primitives {
_type = TypeSymbols.Bytes;
constructor(private readonly bytes: Uint8Array) {
super();
}
toString(encoding: 'utf8' | 'hex' = 'utf8') {
return bytesToString(encoding, this.bytes);
}
toJSON() {
return bufferToHex(this.bytes);
}
static fromBytes(buf: Uint8Array): [Bytes, Uint8Array] {
const [len, remaining] = Int.fromBytes(buf);
return [
new Bytes(remaining.slice(0, len.value())),
remaining.slice(len.value()),
];
}
toBytes() {
return concatBytes(bytesForInt(this.bytes.length), this.bytes);
}
}
Выполнить команду
Для локальной разработки. Не используйте в интернете!