C
C#2y ago
wfsec

❔ Python equilavent

help
18 Replies
wfsec
wfsec2y ago
{
var packetData = new byte[data.Length + 5];
Array.Copy(BitConverter.GetBytes(type), packetData, 4);
Array.Copy(data, 0, packetData, 4, data.Length);
SendData(packetData);
}
{
var packetData = new byte[data.Length + 5];
Array.Copy(BitConverter.GetBytes(type), packetData, 4);
Array.Copy(data, 0, packetData, 4, data.Length);
SendData(packetData);
}
What Array.Copy does? BitConverter,GetBytes? Can someone make that but in Python? i already tried googling
Starlk
Starlk2y ago
the first line creates an empty array with the size of data's length plus 5 bytes. then copies the bytes of type into that array and specifies the length to be 4 is this a Minecraft server software? the second array copy copies data from index 0 to packet data from index 4 with data's length
wfsec
wfsec2y ago
so its:
A = []
A.insert(type)
SendData(A)
A = []
A.insert(type)
SendData(A)
huh no
Starlk
Starlk2y ago
it has been quite a while since I did anything in python
wfsec
wfsec2y ago
frick
Starlk
Starlk2y ago
does .insert convert type into bytes?
wfsec
wfsec2y ago
a.insert(bytes(type)) ?
Starlk
Starlk2y ago
dynamic typed languages confuse me ;-; ¯\_(ツ)_/¯
wfsec
wfsec2y ago
ok frick
john
john2y ago
we arent gonna write your whole code for you. Array.Copy copies from first array to second, optionally with a start point and a length
wfsec
wfsec2y ago
a = ['okay', 'smh'] c sharp magic b = a print(b)
['okay', 'smh']
gerard
gerard2y ago
Well, now I know why I'm not doing any Python It would be something like this:
type = 1
data = bytes([1, 2, 3])

array = bytearray(len(data) + 5)
array[0:4] = type.to_bytes(4)
array[4:] = data

print(array)
type = 1
data = bytes([1, 2, 3])

array = bytearray(len(data) + 5)
array[0:4] = type.to_bytes(4)
array[4:] = data

print(array)
to_bytes can also accept little and big endian, see https://docs.python.org/3/library/stdtypes.html#int.to_bytes. Good luck.
wfsec
wfsec2y ago
oke im creating unofficial api for a game and i dont want someone to steal my idea so i wont tell what game api/lib works ty
gerard
gerard2y ago
unofficial api
I hope their ToS allow you to do this?
wfsec
wfsec2y ago
yes i asked the devs
gerard
gerard2y ago
Aight 👍
wfsec
wfsec2y ago
they didnt even start egoing for being a small dev lol unlike other
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.