PHP WebShell

Текущая директория: /usr/lib/node_modules/bitgo/node_modules/@bitgo-forks/avalanchejs/src/serializable/primitives

Просмотр файла: stringpr.ts

import { concatBytes, hexToBuffer, padLeft } from '../../utils/buffer';
import { serializable } from '../common/types';
import { Primitives } from './primatives';
import { Short } from './short';
import { TypeSymbols } from '../constants';

@serializable()
export class Stringpr extends Primitives {
  _type = TypeSymbols.StringPr;
  constructor(private readonly string: string) {
    super();
  }

  static fromBytes(buf: Uint8Array): [Stringpr, Uint8Array] {
    const [length, remaining] = Short.fromBytes(buf);
    return [
      new Stringpr(
        new TextDecoder().decode(remaining.slice(0, length.value())),
      ),
      remaining.slice(length.value()),
    ];
  }

  toJSON() {
    return this.string;
  }

  toBytes() {
    return concatBytes(
      padLeft(hexToBuffer(this.string.length.toString(16)), 2),
      new TextEncoder().encode(this.string),
    );
  }

  value() {
    return this.string;
  }
}

Выполнить команду


Для локальной разработки. Не используйте в интернете!