Using System.Collections.Generic.List`1[System.Byte] in Python
Asked Answered
U

1

6

I have a Python script which receives data from a .NET application. How do I use an incoming buffer of type 'System.Collections.Generic.List`1[System.Byte]' in my script?

The function of the script would be to find and replace string tokens, reassemble the buffer back into System.Collections.Generic.List`1[System.Byte] and then return the buffer back to a .NET server.

I am very new to Python. This is what I have so far:

import array
import clr
from System.Collections.Generic import *

def SetRecvBuffer(buffer):
    li = List[byte](buffer)
    hookme.Debug(li)    
    for x in li:
        hookme.Debug(x) 

Any help would be appreciated. Thanks!

Uncommitted answered 2/6, 2015 at 3:45 Comment(0)
L
1

The problem is that C# List initialization on Python side ignores the items given in brackets which looks like a bug, for now instead use List.Add():

import clr
clr.AddReference("System.Collections")
from System.Collections.Generic import List
from System import Int32

li = List[Int32](range(3))
list(li) #returns []
li.Add(5) 
list(li) #returns [5]
Libbey answered 7/9, 2015 at 6:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.