|
|
|
@ -51,25 +51,16 @@ func TestWrite(t *testing.T) {
|
|
|
|
|
assert.Equal(t, []byte{2, 0, 0, 0, 0, 0, 5, 6, 0, 0, 0, 0, 0, 0, 0, 1, 2}, buf.Bytes())
|
|
|
|
|
buf.Reset()
|
|
|
|
|
|
|
|
|
|
err = packer.writeConnect(buf, "live", "rtmp://127.0.0.1/live")
|
|
|
|
|
err = packer.writeConnect(buf, "live", "rtmp://127.0.0.1/live", true)
|
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
|
result = []byte{
|
|
|
|
|
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x14, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x07, 0x63,
|
|
|
|
|
0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x00, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
|
|
|
|
|
0x00, 0x03, 0x61, 0x70, 0x70, 0x02, 0x00, 0x04, 0x6c, 0x69, 0x76, 0x65, 0x00, 0x04, 0x74, 0x79,
|
|
|
|
|
0x70, 0x65, 0x02, 0x00, 0x0a, 0x6e, 0x6f, 0x6e, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x00,
|
|
|
|
|
0x08, 0x66, 0x6c, 0x61, 0x73, 0x68, 0x56, 0x65, 0x72, 0x02, 0x00, 0x1f, 0x46, 0x4d, 0x4c, 0x45,
|
|
|
|
|
0x2f, 0x33, 0x2e, 0x30, 0x20, 0x28, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65,
|
|
|
|
|
0x3b, 0x20, 0x4c, 0x61, 0x6c, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x29, 0x00, 0x05, 0x74, 0x63, 0x55,
|
|
|
|
|
0x72, 0x6c, 0x02, 0x00, 0x15, 0x72, 0x74, 0x6d, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e,
|
|
|
|
|
0x30, 0x2e, 0x30, 0x2e, 0x31, 0x2f, 0x6c, 0x69, 0x76, 0x65, 0x00, 0x00, 0x09,
|
|
|
|
|
}
|
|
|
|
|
result = []byte{0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x14, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x07, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x00, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x61, 0x70, 0x70, 0x02, 0x00, 0x04, 0x6c, 0x69, 0x76, 0x65, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x02, 0x00, 0x0a, 0x6e, 0x6f, 0x6e, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x00, 0x08, 0x66, 0x6c, 0x61, 0x73, 0x68, 0x56, 0x65, 0x72, 0x02, 0x00, 0x20, 0x46, 0x4d, 0x4c, 0x45, 0x2f, 0x33, 0x2e, 0x30, 0x20, 0x28, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65, 0x3b, 0x20, 0x6c, 0x61, 0x6c, 0x30, 0x2e, 0x31, 0x33, 0x2e, 0x30, 0x29, 0x00, 0x05, 0x74, 0x63, 0x55, 0x72, 0x6c, 0x02, 0x00, 0x15, 0x72, 0x74, 0x6d, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x2f, 0x6c, 0x69, 0x76, 0x65, 0x00, 0x00, 0x09}
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, result, buf.Bytes())
|
|
|
|
|
buf.Reset()
|
|
|
|
|
|
|
|
|
|
err = packer.writeConnectResult(buf, 1)
|
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
|
result = []byte{0x3, 0x0, 0x0, 0x0, 0x0, 0x0,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|
|
|
|
result = []byte{0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x14, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x07, 0x5f, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x00, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x66, 0x6d, 0x73, 0x56, 0x65, 0x72, 0x02, 0x00, 0x0d, 0x46, 0x4d, 0x53, 0x2f, 0x33, 0x2c, 0x30, 0x2c, 0x31, 0x2c, 0x31, 0x32, 0x33, 0x00, 0x0c, 0x63, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x69, 0x65, 0x73, 0x00, 0x40, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x03, 0x00, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x02, 0x00, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x00, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x02, 0x00, 0x1d, 0x4e, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2e, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x00, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x02, 0x00, 0x15, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x75, 0x63, 0x63, 0x65, 0x65, 0x64, 0x65, 0x64, 0x2e, 0x00, 0x0e, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x02, 0x00, 0x06, 0x30, 0x2c, 0x31, 0x33, 0x2c, 0x30, 0x00, 0x00, 0x09}
|
|
|
|
|
assert.Equal(t, result, buf.Bytes())
|
|
|
|
|
buf.Reset()
|
|
|
|
|
|
|
|
|
@ -139,7 +130,7 @@ func TestPackCorner(t *testing.T) {
|
|
|
|
|
assert.IsNotNil(t, err)
|
|
|
|
|
err = packer.writePeerBandwidth(mw, 1, 2)
|
|
|
|
|
assert.IsNotNil(t, err)
|
|
|
|
|
err = packer.writeConnect(mw, "live", "rtmp://127.0.0.1/live")
|
|
|
|
|
err = packer.writeConnect(mw, "live", "rtmp://127.0.0.1/live", true)
|
|
|
|
|
assert.IsNotNil(t, err)
|
|
|
|
|
err = packer.writeConnectResult(mw, 1)
|
|
|
|
|
assert.IsNotNil(t, err)
|
|
|
|
@ -161,6 +152,6 @@ func BenchmarkMessagePacker(b *testing.B) {
|
|
|
|
|
mw := fake.NewWriter(fake.WriterTypeDoNothing)
|
|
|
|
|
packer := NewMessagePacker()
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
_ = packer.writeConnect(mw, "live", "rtmp://127.0.0.1/live")
|
|
|
|
|
_ = packer.writeConnect(mw, "live", "rtmp://127.0.0.1/live", true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|