Old 05-27-2018, 11:47 AM   #1
Levitanus
Human being with feelings
 
Join Date: Nov 2015
Location: Novosibirsk, Russia
Posts: 40
Default how to use python pickle with RPR_GetProjExtState

Yep, I know, python is not the best choice for reascript, but I know it more that eel or lua...

here is first try to use serialization of something more complex than value, and I generally, can't get why len of original pickle is smaller than got from project.
Also I poorly understand concept of valOutNeedBig_sz
from RPR_GetProjExtState. Why and how to use it?
Code:
from reaper_python import *
from misc import pr
import pickle

obj = {"one": 123, "two": [1, 2, 3]}
output = pickle.dumps(obj)
pr(output)

RPR_SetProjExtState(0, 'Levitanus_sample_editing_pack', 'test', output)


retval = RPR_GetProjExtState(0, 'Levitanus_sample_editing_pack', 'test',
                             1, 100)
pr(retval[4])
pr('len of output = %s, length of return = %s' %
   (len(output), len(bytes(retval[4].strip(), 'utf-8'))))
serialized = pickle.loads(bytes(retval[4], 'ASCII'))
pr(serialized)
Levitanus is offline   Reply With Quote
Old 05-27-2018, 12:05 PM   #2
Levitanus
Human being with feelings
 
Join Date: Nov 2015
Location: Novosibirsk, Russia
Posts: 40
Default

OK I used 0 protocol and it works.
Code:
from reaper_python import *
from misc import pr
import pickle

obj = {"one": 123, "two": [1, 2, 3]}
output = pickle.dumps(obj, 0).decode()
pr(output)

RPR_SetProjExtState(0, 'Levitanus_sample_editing_pack', 'test', output)


retval = RPR_GetProjExtState(0, 'Levitanus_sample_editing_pack', 'test',
                             1, 100)
pr(retval[4])
serialized = pickle.loads(bytes(retval[4], 'ASCII'))
pr(serialized)
But json made it better)
Code:
from reaper_python import *
from misc import pr
import json

obj = {"one": 123, "two": [1, 2, 3]}
output = json.dumps(obj)
pr(output)

RPR_SetProjExtState(0, 'Levitanus_sample_editing_pack', 'test', output)


retval = RPR_GetProjExtState(0, 'Levitanus_sample_editing_pack', 'test',
                             1, 100)
pr(retval[4])
serialized = json.loads(retval[4])
pr(serialized)
Levitanus is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:43 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.