mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 19:17:38 +08:00
feat(jce): new api *JceReader.ReadBytes.
This commit is contained in:
parent
3ed9b8d698
commit
1abbeb148a
@ -276,6 +276,27 @@ func (r *JceReader) ReadString(tag int) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *JceReader) ReadBytes(tag int) []byte {
|
||||||
|
if !r.skipToTag(tag) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
hd, _ := r.readHead()
|
||||||
|
switch hd.Type {
|
||||||
|
case 9:
|
||||||
|
s := r.ReadInt32(0)
|
||||||
|
b := make([]byte, s)
|
||||||
|
for i := 0; i < int(s); i++ {
|
||||||
|
b[i] = r.ReadByte(0)
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
case 13:
|
||||||
|
r.readHead()
|
||||||
|
return r.readBytes(int(r.ReadInt32(0)))
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ReadAny Read any type via tag, unsupported JceStruct
|
// ReadAny Read any type via tag, unsupported JceStruct
|
||||||
func (r *JceReader) ReadAny(tag int) interface{} {
|
func (r *JceReader) ReadAny(tag int) interface{} {
|
||||||
if !r.skipToTag(tag) {
|
if !r.skipToTag(tag) {
|
||||||
|
@ -81,3 +81,15 @@ func BenchmarkRequestDataVersion2_ReadFrom(b *testing.B) {
|
|||||||
result.ReadFrom(NewJceReader(src))
|
result.ReadFrom(NewJceReader(src))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestJceReader_ReadBytes(t *testing.T) {
|
||||||
|
b := make([]byte, 1024)
|
||||||
|
rand.Read(b)
|
||||||
|
|
||||||
|
w := NewJceWriter()
|
||||||
|
w.WriteBytes(b, 0)
|
||||||
|
r := NewJceReader(w.Bytes())
|
||||||
|
rb := r.ReadBytes(0)
|
||||||
|
|
||||||
|
assert.Equal(t, b, rb)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user