Code Duplication    Length = 22-28 lines in 2 locations

opcua/ua/uatypes.py 1 location

@@ 973-1000 (lines=28) @@
970
        self.ServerPicoseconds = None
971
        self._freeze = True
972
973
    def to_binary(self):
974
        packet = []
975
        if self.Value:
976
            self.Encoding |= (1 << 0)
977
        if self.StatusCode:
978
            self.Encoding |= (1 << 1)
979
        if self.SourceTimestamp:
980
            self.Encoding |= (1 << 2)
981
        if self.ServerTimestamp:
982
            self.Encoding |= (1 << 3)
983
        if self.SourcePicoseconds:
984
            self.Encoding |= (1 << 4)
985
        if self.ServerPicoseconds:
986
            self.Encoding |= (1 << 5)
987
        packet.append(uabin.Primitives.UInt8.pack(self.Encoding))
988
        if self.Value:
989
            packet.append(self.Value.to_binary())
990
        if self.StatusCode:
991
            packet.append(self.StatusCode.to_binary())
992
        if self.SourceTimestamp:
993
            packet.append(uabin.Primitives.DateTime.pack(self.SourceTimestamp))  # self.SourceTimestamp.to_binary())
994
        if self.ServerTimestamp:
995
            packet.append(uabin.Primitives.DateTime.pack(self.ServerTimestamp))  # self.ServerTimestamp.to_binary())
996
        if self.SourcePicoseconds:
997
            packet.append(uabin.Primitives.UInt16.pack(self.SourcePicoseconds))
998
        if self.ServerPicoseconds:
999
            packet.append(uabin.Primitives.UInt16.pack(self.ServerPicoseconds))
1000
        return b''.join(packet)
1001
1002
    @staticmethod
1003
    def from_binary(data):

opcua/ua/uaprotocol_auto.py 1 location

@@ 1016-1037 (lines=22) @@
1013
            packet.append(uabin.Primitives.UInt16.pack(self.SourcePicoseconds))
1014
        if self.ServerTimestamp: 
1015
            packet.append(uabin.Primitives.DateTime.pack(self.ServerTimestamp))
1016
        if self.ServerPicoseconds: 
1017
            packet.append(uabin.Primitives.UInt16.pack(self.ServerPicoseconds))
1018
        return b''.join(packet)
1019
1020
    @staticmethod
1021
    def from_binary(data):
1022
        obj = DataValue()
1023
        self.Encoding = uabin.Primitives.UInt8.unpack(data)
1024
        if obj.Encoding & (1 << 0):
1025
            obj.Value = Variant.from_binary(data)
1026
        else:
1027
            obj.Value = Variant()
1028
        if obj.Encoding & (1 << 1):
1029
            obj.StatusCode = StatusCode.from_binary(data)
1030
        else:
1031
            obj.StatusCode = StatusCode()
1032
        if obj.Encoding & (1 << 2):
1033
            self.SourceTimestamp = uabin.Primitives.DateTime.unpack(data)
1034
        else:
1035
            obj.SourceTimestamp = datetime.utcnow()
1036
        if obj.Encoding & (1 << 3):
1037
            self.SourcePicoseconds = uabin.Primitives.UInt16.unpack(data)
1038
        else:
1039
            obj.SourcePicoseconds = 0
1040
        if obj.Encoding & (1 << 4):