- 提升 go.mod 基线到 Go 1.20,并补齐对应测试 - 修正 Passwd / PasswdResponseSignal 语义,Ctrl+C 默认退出当前流程 - 优化 raw terminal redraw、Restore 与 StopUntil 的边界行为 - 新增 StarPipe、FrameReader/FrameWriter、ReadFullContext/WriteFullContext/CopyContext、IsTerminal/ReadPasswordContext - 收口 StarQueue / StarBuffer 语义,删除 EndWrite,统一 Close / Abort 行为 - 补齐 signal、timeout、queue、terminal、pipe、buffer 的回归测试与 race 覆盖
35 lines
693 B
Go
35 lines
693 B
Go
package stario
|
|
|
|
import "encoding/binary"
|
|
|
|
// Uint32ToByte 4位uint32转byte。
|
|
func Uint32ToByte(src uint32) []byte {
|
|
res := make([]byte, 4)
|
|
binary.BigEndian.PutUint32(res, src)
|
|
return res
|
|
}
|
|
|
|
// ByteToUint32 byte转4位uint32。
|
|
func ByteToUint32(src []byte) uint32 {
|
|
return binary.BigEndian.Uint32(src)
|
|
}
|
|
|
|
// Uint16ToByte 2位uint16转byte。
|
|
func Uint16ToByte(src uint16) []byte {
|
|
res := make([]byte, 2)
|
|
binary.BigEndian.PutUint16(res, src)
|
|
return res
|
|
}
|
|
|
|
// ByteToUint16 用于byte转uint16。
|
|
func ByteToUint16(src []byte) uint16 {
|
|
return binary.BigEndian.Uint16(src)
|
|
}
|
|
|
|
func cloneBytes(src []byte) []byte {
|
|
if len(src) == 0 {
|
|
return nil
|
|
}
|
|
return append([]byte(nil), src...)
|
|
}
|