Skip to content

only use msgpack in payload.py #25693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
derek0377 opened this issue Jul 24, 2015 · 2 comments
Closed

only use msgpack in payload.py #25693

derek0377 opened this issue Jul 24, 2015 · 2 comments
Labels
Question The issue is more of a question rather than a bug or a feature request stale
Milestone

Comments

@derek0377
Copy link

Here is the Serial Class in payload.py

class Serial(object):
    '''
    Create a serialization object, this object manages all message
    serialization in Salt
    '''
    def __init__(self, opts):
        if isinstance(opts, dict):
            self.serial = opts.get('serial', 'msgpack')
        elif isinstance(opts, str):
            self.serial = opts
        else:
            self.serial = 'msgpack'

    def loads(self, msg):
        '''
        Run the correct loads serialization format
        '''
        try:
            gc.disable()  # performance optimization for msgpack
            return msgpack.loads(msg, use_list=True)
        except Exception as exc:
            log.critical('Could not deserialize msgpack message: {0}'
                         'This often happens when trying to read a file not in binary mode.'
                         'Please open an issue and include the following error: {1}'.format(msg, exc))
            raise
        finally:
            gc.enable()

    def load(self, fn_):
        '''
        Run the correct serialization to load a file
        '''
        data = fn_.read()
        fn_.close()
        if data:
            return self.loads(data)

    def dumps(self, msg):
        '''
        Run the correct dumps serialization format
        '''
        try:
            return msgpack.dumps(msg)
        except (OverflowError, msgpack.exceptions.PackValueError):

Could you please tell me why only use msgpack? (optimization?)
In old version the serial way is set by config (opts.get('serial', 'msgpack'))
msgpack and pickle

bug msgpack way cause code error on windows:
#16751

Could I use the pickle way to serial, or may be other problem that only use msgpack ?

@jfindlay jfindlay added the Question The issue is more of a question rather than a bug or a feature request label Jul 24, 2015
@jfindlay jfindlay added this to the Blocked milestone Jul 24, 2015
@jfindlay
Copy link
Contributor

@derek0377, the choice of msgpack for serializing was made before I began working on salt, but I understand it is because msgpack offers many features that are needed by salt that pickle does not have.

Since #23740 and #24089 (2015.5.1), reading and writing of files on windows is done in binary mode. Do you encounter that error on 2015.5.1 or later?

@stale
Copy link

stale bot commented Dec 4, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Dec 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question The issue is more of a question rather than a bug or a feature request stale
Projects
None yet
Development

No branches or pull requests

2 participants