关于Uinit8和Byte: The Go Programming Language Specification Numeric types uint8 the set of all unsigned 8-bit integers (0 to 255) byte alias for uint8 将[]uinit8转换为string: func B2S(bs []int8) string { ba := []byte{} for _, b := range bs { ba = append(ba,…
golang []byte和string的高性能转换 在fasthttp的最佳实践中有这么一句话: Avoid conversion between []byte and string, since this may result in memory allocation+copy. Fasthttp API provides functions for both []byte and string - use these functions instead of converting manu…
要把一个string赋值给一个array,哥哥遇到一个纠结的困难,研究一番,发现主要原因是array和slice在golang里不是一个东西,本文提供两种解决方案. 在网络编程中network packet transfer,经常要定义固定的字节长度,如下面的f1: package main import"fmt" type T1 struct{ f1 [5]byte// I use fixed size here for file format or network packet f…