Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
opcua-asyncio
Commits
727de76a
Commit
727de76a
authored
Dec 16, 2015
by
Zhang, Hua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't truncate Buffer.data in every read
parent
b98292a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
11 deletions
+25
-11
opcua/utils.py
opcua/utils.py
+25
-11
No files found.
opcua/utils.py
View file @
727de76a
...
...
@@ -26,25 +26,29 @@ class Buffer(object):
"""
def
__init__
(
self
,
data
):
self
.
logger
=
logging
.
getLogger
(
__name__
)
self
.
data
=
data
# self.logger = logging.getLogger(__name__)
self
.
_data
=
data
self
.
rsize
=
0
def
__str__
(
self
):
return
"Buffer(size:{}, data:{})"
.
format
(
len
(
self
.
data
),
self
.
data
)
return
"Buffer(size:{}, data:{})"
.
format
(
len
(
self
),
self
.
data
)
__repr__
=
__str__
def
__len__
(
self
):
return
len
(
self
.
data
)
return
len
(
self
.
_data
)
-
self
.
rsize
def
read
(
self
,
size
):
"""
read and pop number of bytes for buffer
"""
if
size
>
len
(
self
.
data
):
rsize
=
self
.
rsize
nrsize
=
rsize
+
size
mydata
=
self
.
_data
if
nrsize
>
len
(
mydata
):
raise
Exception
(
"Not enough data left in buffer, request for {}, we have {}"
.
format
(
size
,
self
))
#self.logger.debug("Request for %s bytes, from %s", size, self)
data
=
self
.
data
[:
size
]
self
.
data
=
self
.
data
[
size
:]
data
=
mydata
[
rsize
:
nr
size
]
self
.
rsize
=
nrsize
#self.logger.debug("Returning: %s ", data)
return
data
...
...
@@ -53,17 +57,27 @@ class Buffer(object):
return a copy, optionnaly only copy 'size' bytes
"""
if
size
is
None
:
return
Buffer
(
self
.
data
)
return
Buffer
(
self
.
_data
[
self
.
rsize
:]
)
else
:
return
Buffer
(
self
.
data
[:
size
])
return
Buffer
(
self
.
_data
[
self
.
rsize
:
self
.
rsize
+
size
])
def
test_read
(
self
,
size
):
"""
read 'size' bytes from buffer, without removing them from buffer
"""
if
s
ize
>
len
(
self
.
data
):
if
s
elf
.
rsize
+
size
>
len
(
self
.
_
data
):
raise
Exception
(
"Not enough data left in buffer, request for {}, we have {}"
.
format
(
size
,
self
))
return
self
.
data
[:
size
]
return
self
.
_data
[
self
.
rsize
:
self
.
rsize
+
size
]
def
get_data
(
self
):
return
self
.
_data
[
self
.
rsize
:]
def
set_data
(
self
,
v
):
self
.
_data
=
v
self
.
rsize
=
0
data
=
property
(
get_data
,
set_data
)
class
SocketClosedException
(
Exception
):
pass
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment