File: utf16beencoder.go

package info (click to toggle)
golang-github-ffuf-pencode 0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 224 kB
  • sloc: makefile: 2; sh: 1
file content (29 lines) | stat: -rw-r--r-- 532 bytes parent folder | download
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
26
27
28
29
package pencode

import (
	"bytes"
	"encoding/binary"
	"unicode/utf16"
)

type UTF16BEEncode struct{}

func (u UTF16BEEncode) Encode(input []byte) ([]byte, error) {
	var b bytes.Buffer
	runes := []rune(string(input))
	utf16ints := utf16.Encode(runes)
	for _, r := range utf16ints {
		tmp := make([]byte, 2)
		binary.BigEndian.PutUint16(tmp, r)
		b.Write(tmp)
	}
	return b.Bytes(), nil
}

func (u UTF16BEEncode) HelpText() string {
	return "UTF-16 encoder (Big Endian)"
}

func (u UTF16BEEncode) Type() string {
	return "encoders"
}