Options
All
  • Public
  • Public/Protected
  • All
Menu

文字列のエンコード関数をまとめたクラス. Major Typeは3.

Hierarchy

  • StringEncoder

Index

Properties

Methods

Properties

Static shiftedMajorType

shiftedMajorType: number = majorType.text.type << 5

1byteで表現されるdata item headerの先頭3bit. 8bitあるうちの先頭3bitにcategory typeを持ってきたいのでmajor typeを5bitシフトさせる.

Methods

Static stringEncode

  • stringEncode(str: string): Buffer
  • 受け取った文字列をCBORに変換する。 data item headerはmajor typeと長さの情報を入れる。 長さが23までならそのままdata item headerにそのまま長さを入れる。 長さが24より大きくなるなら data item header の次のバイトで長さを指定する。 2^8以上の長さがあり足りない場合は、必要に応じて次のbyteを使っていく。 FYI: https://en.wikipedia.org/wiki/CBOR

    例) a => 61 61(unicode表) => 011_00011 xxxxxxxx = 99 xx 例) aaa => 63 61(unicode表) 61 61 => 011_00100 xxxxxxxx = 101 xx 例) aaaaaaaaaaaaaaaaaaaaaaa => 77 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61(unicode表) => 010_010101 xxxxxxxx = 101 xx => 0x63 0xXX 例) aaaaaaaaaaaaaaaaaaaaaaaa => 0x78 0x18(長さ) 0x61 0x61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61(unicode表) => 011_11000 000_11000 xxxxxxxx = 101 xx => 0x63 0xXX

    Parameters

    • str: string

      変換したい文字列

    Returns Buffer

    Buffer バイト列

Generated using TypeDoc