FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-osc/pythonosc/osc_bundle_builder.py at master · FrancescElies/python-osc · GitHub
FrancescElies
/
python-osc
Public
forked from
attwad/python-osc
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-osc
/
pythonosc
/
osc_bundle_builder.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (45 loc) · 1.95 KB
Breadcrumbs
python-osc
/
pythonosc
/
osc_bundle_builder.py
Copy path
File metadata and controls
57 lines (45 loc) · 1.95 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Build OSC bundles for client applications."""
from
pythonosc
import
osc_bundle
from
pythonosc
import
osc_message
from
pythonosc
.
parsing
import
osc_types
# Shortcut to specify an immediate execution of messages in the bundle.
IMMEDIATELY
=
osc_types
.
IMMEDIATELY
class
BuildError
(
Exception
):
"""Error raised when an error occurs building the bundle."""
class
OscBundleBuilder
(
object
):
"""Builds arbitrary OscBundle instances."""
def
__init__
(
self
,
timestamp
:
int
)
->
None
:
"""Build a new bundle with the associated timestamp.
Args:
- timestamp: system time represented as a floating point number of
seconds since the epoch in UTC or IMMEDIATELY.
"""
self
.
_timestamp
=
timestamp
self
.
_contents
=
[]
def
add_content
(
self
,
content
:
osc_bundle
.
OscBundle
)
->
None
:
"""Add a new content to this bundle.
Args:
- content: Either an OscBundle or an OscMessage
"""
self
.
_contents
.
append
(
content
)
def
build
(
self
)
->
osc_bundle
.
OscBundle
:
"""Build an OscBundle with the current state of this builder.
Raises:
- BuildError: if we could not build the bundle.
"""
dgram
=
b'#bundle
\x00
'
try
:
dgram
+=
osc_types
.
write_date
(
self
.
_timestamp
)
for
content
in
self
.
_contents
:
if
(
type
(
content
)
==
osc_message
.
OscMessage
or
type
(
content
)
==
osc_bundle
.
OscBundle
):
size
=
content
.
size
dgram
+=
osc_types
.
write_int
(
size
)
dgram
+=
content
.
dgram
else
:
raise
BuildError
(
"Content must be either OscBundle or OscMessage"
"found {}"
.
format
(
type
(
content
)))
return
osc_bundle
.
OscBundle
(
dgram
)
except
osc_types
.
BuildError
as
be
:
raise
BuildError
(
'Could not build the bundle {}'
.
format
(
be
))
Back
|
FazBrowse Home
|
New Git URL