Is there a equivalent of python's struct.pack in C#?

318 Views Asked by At

Is there a more or less equivalent of Pythons' struct pack in C# ? What i basically need to do is 'rewriting' a part of a python-script in C#. The following functions are required to prepare some text, so that it can be send via a socket...

def PrepString(text):
return struct.pack('>h', len(text)) + text.encode('utf_16_be')

def PrepStringMed(text):
return struct.pack('>h', len(text)) + '\x00' + '\x00'.join(list(text))

def PrepStringOld(text):
msg = '\x00' + '\x00'.join(list(text))
return chr(len(text)) + msg

I already tried some methods with some MemoryStream etc. but the remoteapplication (local server) yust spammed the log with errors... It would be nice to get this working with "Onboard"-resources of VS, yust for simplicity and whenever I would need that e.g at work, i would know how to solve it without extra-libraries

0

There are 0 best solutions below