mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-05 14:13:30 -04:00
25 lines
421 B
Go
25 lines
421 B
Go
![]() |
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
|
||
|
}
|