mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-04 21:55:18 -04:00
I2P string format
This commit is contained in:
24
lib/common/string.go
Normal file
24
lib/common/string.go
Normal file
@ -0,0 +1,24 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type String []byte
|
||||
|
||||
func ReadString(data []byte) (str String, remainder []byte, err error) {
|
||||
if len(data) == 0 {
|
||||
err = errors.New("no string in empty byte slice")
|
||||
return
|
||||
}
|
||||
length := Integer([]byte{data[0]})
|
||||
data = data[1:]
|
||||
|
||||
if len(data) < length {
|
||||
err = errors.New("string longer than provided slice")
|
||||
return
|
||||
}
|
||||
str = data[:length]
|
||||
remainder = data[length:]
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user