mirror of
https://github.com/fumiama/go-base16384.git
synced 2026-06-08 03:56:20 +08:00
完成
This commit is contained in:
25
README.md
25
README.md
@@ -1,2 +1,27 @@
|
||||
# go-base16384
|
||||
base16384 interface of golang
|
||||
|
||||
# Functions
|
||||
|
||||
## func Encode(b []byte) []byte
|
||||
Encode b to utf16be.
|
||||
## func Decode(b []byte) []byte
|
||||
Decode from encoded b.
|
||||
## func UTF16be2utf8(b []byte) ([]byte, error)
|
||||
Display the result.
|
||||
## func UTF82utf16be(b []byte) ([]byte, error)
|
||||
Turn the result to its original coding form to decode.
|
||||
|
||||
# Usage
|
||||
## As package
|
||||
Just include it in your project.
|
||||
## As lib
|
||||
Copy this repo to `$GOPATH/src`, then execute
|
||||
```bash
|
||||
go install -buildmode=shared -linkshared std
|
||||
go install -buildmode=shared -linkshared base14
|
||||
```
|
||||
Now you can use
|
||||
```bash
|
||||
go build -linkshared ...
|
||||
```
|
||||
29
base1432.go
Normal file
29
base1432.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// +build 386 arm
|
||||
|
||||
// Package base14 base16384 的 go 接口
|
||||
package base14
|
||||
|
||||
// #cgo CFLAGS: -I/usr/local/include
|
||||
// #cgo LDFLAGS: -L/usr/local/lib -lbase14
|
||||
// #include <stdlib.h>
|
||||
// #include <base14.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func Encode(b []byte) []byte {
|
||||
ld := C.encode((*C.uchar)(unsafe.Pointer(&b[0])), (uint)(len(b)))
|
||||
ldlen := uintptr(ld.len)
|
||||
// []byte 的数据结构
|
||||
e := [3]uintptr{uintptr(unsafe.Pointer(ld.data)), ldlen, ldlen}
|
||||
return *(*[]byte)(unsafe.Pointer(&e))
|
||||
}
|
||||
|
||||
func Decode(b []byte) []byte {
|
||||
ld := C.decode((*C.uchar)(unsafe.Pointer(&b[0])), (uint)(len(b)))
|
||||
ldlen := uintptr(ld.len)
|
||||
// []byte 的数据结构
|
||||
e := [3]uintptr{uintptr(unsafe.Pointer(ld.data)), ldlen, ldlen}
|
||||
return *(*[]byte)(unsafe.Pointer(&e))
|
||||
}
|
||||
29
base1464.go
Normal file
29
base1464.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// +build amd64 arm64
|
||||
|
||||
// Package base14 base16384 的 go 接口
|
||||
package base14
|
||||
|
||||
// #cgo CFLAGS: -I/usr/local/include
|
||||
// #cgo LDFLAGS: -L/usr/local/lib -lbase14
|
||||
// #include <stdlib.h>
|
||||
// #include <base14.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func Encode(b []byte) []byte {
|
||||
ld := C.encode((*C.uchar)(unsafe.Pointer(&b[0])), (C.ulong)(len(b)))
|
||||
ldlen := uintptr(ld.len)
|
||||
// []byte 的数据结构
|
||||
e := [3]uintptr{uintptr(unsafe.Pointer(ld.data)), ldlen, ldlen}
|
||||
return *(*[]byte)(unsafe.Pointer(&e))
|
||||
}
|
||||
|
||||
func Decode(b []byte) []byte {
|
||||
ld := C.decode((*C.uchar)(unsafe.Pointer(&b[0])), (C.ulong)(len(b)))
|
||||
ldlen := uintptr(ld.len)
|
||||
// []byte 的数据结构
|
||||
e := [3]uintptr{uintptr(unsafe.Pointer(ld.data)), ldlen, ldlen}
|
||||
return *(*[]byte)(unsafe.Pointer(&e))
|
||||
}
|
||||
15
conv.go
Normal file
15
conv.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package base14
|
||||
|
||||
import (
|
||||
"golang.org/x/text/encoding/unicode"
|
||||
)
|
||||
|
||||
var format = unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM)
|
||||
|
||||
func UTF16be2utf8(b []byte) ([]byte, error) {
|
||||
return format.NewDecoder().Bytes(b)
|
||||
}
|
||||
|
||||
func UTF82utf16be(b []byte) ([]byte, error) {
|
||||
return format.NewEncoder().Bytes(b)
|
||||
}
|
||||
5
go.mod
Normal file
5
go.mod
Normal file
@@ -0,0 +1,5 @@
|
||||
module github.com/fumiama/go-base16384
|
||||
|
||||
go 1.16
|
||||
|
||||
require golang.org/x/text v0.3.6
|
||||
3
go.sum
Normal file
3
go.sum
Normal file
@@ -0,0 +1,3 @@
|
||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
Reference in New Issue
Block a user