improve code import

This commit is contained in:
houseme
2021-11-16 19:29:02 +08:00
parent c6efb5ee3b
commit e86ee052cb
12 changed files with 35 additions and 34 deletions

View File

@ -8,19 +8,16 @@ package gbinary
// NOTE: THIS IS AN EXPERIMENTAL FEATURE!
// Bit Binary bit (0 | 1) 二进制位(0|1)
// Bit Binary bit (0 | 1)
type Bit int8
// EncodeBits .
// Default coding
// 默认编码
// EncodeBits does encode bits return bits Default coding
func EncodeBits(bits []Bit, i int, l int) []Bit {
return EncodeBitsWithUint(bits, uint(i), l)
}
// EncodeBitsWithUint .
// Merge ui bitwise into the bits array and occupy the length length bits (Note: binary 0 | 1 digits are stored in the uis array)
// 将ui按位合并到bits数组中并占length长度位(注意uis数组中存放的是二进制的0|1数字)
// EncodeBitsWithUint . Merge ui bitwise into the bits array and occupy the length bits
// (Note: binary 0 | 1 digits are stored in the uis array)
func EncodeBitsWithUint(bits []Bit, ui uint, l int) []Bit {
a := make([]Bit, l)
for i := l - 1; i >= 0; i-- {
@ -33,9 +30,8 @@ func EncodeBitsWithUint(bits []Bit, ui uint, l int) []Bit {
return a
}
// EncodeBitsToBytes .
// EncodeBitsToBytes . does encode bits to bytes
// Convert bits to [] byte, encode from left to right, and add less than 1 byte from 0 to the end.
// 将bits转换为[]byte从左至右进行编码不足1 byte按0往末尾补充
func EncodeBitsToBytes(bits []Bit) []byte {
if len(bits)%8 != 0 {
for i := 0; i < len(bits)%8; i++ {
@ -49,9 +45,8 @@ func EncodeBitsToBytes(bits []Bit) []byte {
return b
}
// DecodeBits .
// DecodeBits .does decode bits to int
// Resolve to int
// 解析为int
func DecodeBits(bits []Bit) int {
v := 0
for _, i := range bits {
@ -60,9 +55,7 @@ func DecodeBits(bits []Bit) int {
return v
}
// DecodeBitsToUint .
// Resolve to uint
// 解析为uint
// DecodeBitsToUint .Resolve to uint
func DecodeBitsToUint(bits []Bit) uint {
v := uint(0)
for _, i := range bits {
@ -71,9 +64,7 @@ func DecodeBitsToUint(bits []Bit) uint {
return v
}
// DecodeBytesToBits .
// Parsing [] byte into character array [] uint8
// 解析[]byte为字位数组[]uint8
// DecodeBytesToBits .Parsing [] byte into character array [] uint8
func DecodeBytesToBits(bs []byte) []Bit {
bits := make([]Bit, 0)
for _, b := range bs {

View File

@ -24,12 +24,13 @@ import (
"context"
"io/ioutil"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/internal/intlog"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/ianaindex"
"golang.org/x/text/transform"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/internal/intlog"
)
var (

View File

@ -8,10 +8,11 @@
package gyaml
import (
"gopkg.in/yaml.v3"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/util/gconv"
"gopkg.in/yaml.v3"
)
func Encode(value interface{}) (out []byte, err error) {