def serialize(self, sock: BinarySocketWriter): """ Serialize message """ super().serialize(sock) sock.writeInt32(self.objectId) sock.writeString(self.property) CLRMessage.write(sock, CLRMessage.createByObj(self.setval))
def test_create(self): import pydotnet.clr.CLRInitialization ## ints o1 = CLRMessage.createByObj(2) self.assertTrue(isinstance(o1, pydotnet.clr.data.CLRInt32)) ## floats o2 = CLRMessage.createByObj(3.14) self.assertTrue(isinstance(o2, pydotnet.clr.data.CLRFloat64)) ## boolean b1 = CLRMessage.createByObj(True) self.assertTrue(isinstance(b1, pydotnet.clr.data.CLRBool)) ## string s1 = CLRMessage.createByObj("this is a test") self.assertTrue(isinstance(s1, pydotnet.clr.data.CLRString)) ## vectors o2l = CLRMessage.createByObj([3.14, 1.34]) self.assertTrue(isinstance(o2l, pydotnet.clr.data.CLRVector)) o3l = CLRMessage.createByObj(np.array([3.14, 1.34])) self.assertTrue(isinstance(o3l, pydotnet.clr.data.CLRVector)) o4l = CLRMessage.createByObj(np.array([[3.14], [1.34]])) self.assertTrue(isinstance(o4l, pydotnet.clr.data.CLRVector)) o5l = CLRMessage.createByObj( pd.DataFrame([3.14, 1.34], index=['a', 'b'])) self.assertTrue(isinstance(o5l, pydotnet.clr.data.CLRVector)) o6l = CLRMessage.createByObj(pd.DataFrame([3.14, 1.34]).as_matrix()) self.assertTrue(isinstance(o6l, pydotnet.clr.data.CLRVector)) ## matrices m1 = CLRMessage.createByObj( pd.DataFrame([[2.0, 0, 0], [0, 3.0, 0], [0, 0, 23.0]], index=['a', 'b', 'c'], columns=['a', 'b', 'c'])) self.assertTrue(isinstance(m1, pydotnet.clr.data.CLRMatrix)) ## arrays a1 = CLRMessage.createByObj(np.array([1, 3, 5, 7], dtype=np.int32)) self.assertTrue(isinstance(a1, pydotnet.clr.data.CLRInt32Array)) a2 = CLRMessage.createByObj(np.array([1, 3, 5, 7], dtype=np.int64)) self.assertTrue(isinstance(a2, pydotnet.clr.data.CLRInt64Array)) a3 = CLRMessage.createByObj(["this", "that"]) self.assertTrue(isinstance(a3, pydotnet.clr.data.CLRStringArray)) a4 = CLRMessage.createByObj( pd.DataFrame([3.14, 1.34], index=['a', 'b']).index.values) self.assertTrue(isinstance(a4, pydotnet.clr.data.CLRStringArray))