File: utf16leencoder.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-- 538 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 UTF16LEEncode struct{}

func (u UTF16LEEncode) 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.LittleEndian.PutUint16(tmp, r)
		b.Write(tmp)
	}
	return b.Bytes(), nil
}

func (u UTF16LEEncode) HelpText() string {
	return "UTF-16 encoder (Little Endian)"
}

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