mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
parent
de6d753f79
commit
b4d29e6096
@ -316,6 +316,18 @@ get_message() const {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the datagram's data as a bytes object.
|
||||
*/
|
||||
INLINE vector_uchar Datagram::
|
||||
__bytes__() const {
|
||||
if (!_data.empty()) {
|
||||
return vector_uchar(_data.v());
|
||||
} else {
|
||||
return vector_uchar();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pointer to the beginning of the datagram's data.
|
||||
*/
|
||||
|
@ -84,6 +84,7 @@ PUBLISHED:
|
||||
void assign(const void *data, size_t size);
|
||||
|
||||
INLINE string get_message() const;
|
||||
INLINE vector_uchar __bytes__() const;
|
||||
INLINE const void *get_data() const;
|
||||
INLINE size_t get_length() const;
|
||||
|
||||
|
@ -76,6 +76,16 @@ def datagram_large():
|
||||
|
||||
return dg, readback_function
|
||||
|
||||
def test_datagram_bytes():
|
||||
"""Tests that we can put and get a bytes object on Datagram."""
|
||||
dg = core.Datagram(b'abc\x00')
|
||||
dg.append_data(b'\xff123')
|
||||
assert bytes(dg) == b'abc\x00\xff123'
|
||||
|
||||
dgi = core.DatagramIterator(dg)
|
||||
dgi.get_remaining_bytes() == b'abc\x00\xff123'
|
||||
|
||||
|
||||
def test_iterator(datagram_small):
|
||||
"""This tests Datagram/DatagramIterator, and sort of serves as a self-check
|
||||
of the test fixtures too."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user