uaprotocol_auto_add.py
Go to the documentation of this file.
1 
3  """
4  Convert binary-coded ExtensionObject to a Python object.
5  Returns an object, or None if TypeId is zero
6  """
7  TypeId = NodeId.from_binary(data)
8  Encoding = ord(data.read(1))
9  body = None
10  if Encoding & (1 << 0):
11  length = uabin.Primitives.Int32.unpack(data)
12  if length < 1:
13  body = Buffer(b"")
14  else:
15  body = data.copy(length)
16  data.skip(length)
17  if TypeId.Identifier == 0:
18  return None
19  elif TypeId.Identifier not in ExtensionClasses:
20  e = ExtensionObject()
21  e.TypeId = TypeId
22  e.Encoding = Encoding
23  if body is not None:
24  e.Body = body.read(len(body))
25  return e
26  klass = ExtensionClasses[TypeId.Identifier]
27  if body is None:
28  raise UaError("parsing ExtensionObject {0} without data".format(klass.__name__))
29  return klass.from_binary(body)
30 
31 
33  """
34  Convert Python object to binary-coded ExtensionObject.
35  If obj is None, convert to empty ExtensionObject (TypeId = 0, no Body).
36  Returns a binary string
37  """
38  if isinstance(obj, ExtensionObject):
39  return obj.to_binary()
40  TypeId = NodeId()
41  Encoding = 0
42  Body = None
43  if obj is not None:
44  TypeId = FourByteNodeId(getattr(ObjectIds, "{0}_Encoding_DefaultBinary".format(obj.__class__.__name__)))
45  Encoding |= (1 << 0)
46  Body = obj.to_binary()
47  packet = []
48  packet.append(TypeId.to_binary())
49  packet.append(uabin.Primitives.UInt8.pack(Encoding))
50  if Body:
51  packet.append(uabin.Primitives.Bytes.pack(Body))
52  return b''.join(packet)
def extensionobject_from_binary(data)


ros_opcua_impl_python_opcua
Author(s): Denis Štogl , Daniel Draper
autogenerated on Tue Jan 19 2021 03:12:44