Aweto

package module
v0.0.0-...-4385d76 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2020 License: MIT Imports: 4 Imported by: 1

README

Aweto数据转换

为了实现常用数据类型与字节切片的相互转换,我开发了这个库。目前支持的数据类型包括bool,int16,uint16,int32,uint32,int64,uint64,float32,float64。

函数定义

数据转换为字节数组的函数定义
 func ToBytes(i interface{}, BigEndian bool, Swap int, Len int) (data []byte, err error)

第一个参数类型为interface{},接收要转换的数据
第二个参数类型为bool,用来标识是否是大端转换
第三个参数类型为int,用来标识进行数据交换的方式(0:为不做交换,1:字节交换,2:字交换)
第四个参数类型为int,用来把转换完的数据的字节切片填充零为到定长,如果Len长度小于等于接收数据的长度则不起作用。

字节数组转化为数据的函数定义
 func ToValue(buf []byte, Type string, BigEndian bool, Swap int) (data interface{}, err error)

第一个参数类型为[]byte,用来接收要转换的数据
第二个参数类型为string,用来接受要进行转换的类型
第三个参数类型为bool,用来标识是否是大端转换
第四个参数类型为int,用来标识进行数据交换的方式(0:为不做交换,1:字节交换,2:字交换)

使用方法

v, err := ToBytes(int16(1), true, 0, 8)
fmt.Println(v, err)
d,err2:=ToValue(v, "int16", true, 0)
fmt.Println(d,err2)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteSwap

func ByteSwap(buf []byte) (err error)

字节交换函数

func BytesCombine

func BytesCombine(pBytes ...[]byte) []byte

字节切片合并函数

func ToBytes

func ToBytes(i interface{}, BigEndian bool, Swap int, Len int) (data []byte, err error)

值转字节数组

func ToValue

func ToValue(buf []byte, Type string, BigEndian bool, Swap int) (data interface{}, err error)

字节数组转值

func WordSwap

func WordSwap(buf []byte) (err error)

字交换函数

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL