Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteSliceToString ¶
ByteSlice2String convert []byte to string without copy. notice: this function is not safe, the bytes passed to String must not be modified afterwards.
func StringToSliceByte ¶
StringToSliceByte is like StringToSliceByteOld,but it's more simple. notice: this function is not safe, if you want to write the []byte, you should copy it.
func StringToSliceByteOld ¶
StringToSliceByteOld if we directly use []byte(string) to convert a string to []byte, in fact, there will be a copy. The reason is that Go's design is that string is immutable, but []byte is mutable, so when converting this way, a copy will be made. If you don't want to copy the conversion, you need to use unsafe. The meaning of this code is to get the address of the string first, and then assemble a slice byte header. In this way, you can convert string to []byte without copying data, but you need to pay attention that the []byte generated in this way is not writable, otherwise the behavior is undefined.
Types ¶
This section is empty.