MCPcopy Create free account
hub / github.com/LagrangeDev/LagrangeGo / ReadBytesWithLength

Method ReadBytesWithLength

utils/binary/reader.go:177–199  ·  view source on GitHub ↗
(prefix string, withPerfix bool)

Source from the content-addressed store, hash-verified

175}
176
177func (r *Reader) ReadBytesWithLength(prefix string, withPerfix bool) []byte {
178 var length int
179 switch prefix {
180 case "u8":
181 length = int(r.ReadU8())
182 case "u16":
183 length = int(r.ReadU16())
184 case "u32":
185 length = int(r.ReadU32())
186 case "u64":
187 length = int(r.ReadU64())
188 default:
189 panic("invaild prefix")
190 }
191 if withPerfix {
192 plus, err := strconv.Atoi(prefix[1:])
193 if err != nil {
194 panic(err)
195 }
196 length -= plus / 8
197 }
198 return r.ReadBytes(length)
199}
200
201func (r *Reader) ReadStringWithLength(prefix string, withPerfix bool) string {
202 return utils.B2S(r.ReadBytesWithLength(prefix, withPerfix))

Callers 5

FetchQRCodeMethod · 0.95
UnmarshalSigInfoFunction · 0.95
ReadStringWithLengthMethod · 0.95
ParseMessageElementsFunction · 0.95

Calls 5

ReadU8Method · 0.95
ReadU16Method · 0.95
ReadU32Method · 0.95
ReadU64Method · 0.95
ReadBytesMethod · 0.95

Tested by

no test coverage detected