Pack the value as a binary representation.

        Returns:
            bytes: The binary representation.
179486
def pack(self, value=None):
        
        if isinstance(value, type(self)):
            return value.pack()

        if value is None:
            value = self
        else:
            container = type(self)(items=None)
            container.extend(value)
            value = container

        bin_message = b''
        try:
            for item in value:
                bin_message += item.pack()
            return bin_message
        except exceptions.PackException as err:
            msg = "{} pack error: {}".format(type(self).__name__, err)
            raise exceptions.PackException(msg)
298757
def pack(self):
        '''
        
        '''
        if six.PY3:
            return {'message': six.text_type(self), 'args': self.args}
        return dict(message=self.__unicode__(), args=self.args)
933444
def to_bytes(value):
    """"""
    if isinstance(value, unicode):
        return value.encode('utf8')
    elif not isinstance(value, str):
        return str(value)
    return value
55490
def to_bytes(self):
        '''
        
        '''
        hdr = struct.pack(RIPv2._PACKFMT, self.command.value, 2)
        routes = b''.join([r.to_bytes() for r in self._routes])
        return hdr + routes
647996
def to_bytes(self):
        """"""
        for tokens in self.tokens:
            assert len(tokens.shape) == 2, tokens.shape
        lengths = [len(tokens) for tokens in self.tokens]
        msg = {
            "attrs": self.attrs,
            "tokens": numpy.vstack(self.tokens).tobytes("C"),
            "spaces": numpy.vstack(self.spaces).tobytes("C"),
            "lengths": numpy.asarray(lengths, dtype="int32").tobytes("C"),
            "strings": list(self.strings),
        }
        return gzip.compress(srsly.msgpack_dumps(msg))
527911
def to_bytes(self, errors='strict'):
        ''''''
        return str(self).encode(self.encoding, errors=errors)
1310248
def _encode_binary(name, value, dummy0, dummy1):
    """"""
    subtype = value.subtype
    if subtype == 2:
        value = _PACK_INT(len(value)) + value
    return b"\x05" + name + _PACK_LENGTH_SUBTYPE(len(value), subtype) + value
42203
def pack(o, default=encode,
         encoding='utf-8', unicode_errors='strict', use_single_float=False,
         autoreset=1, use_bin_type=1):
    

    return Packer(default=default, encoding=encoding,
                  unicode_errors=unicode_errors,
                  use_single_float=use_single_float,
                  autoreset=autoreset,
                  use_bin_type=use_bin_type).pack(o)
299251
def to_bytes(self):
        '''
        
        '''
        return struct.pack(Arp._PACKFMT, self._hwtype.value, self._prototype.value, self._hwaddrlen, self._protoaddrlen, self._operation.value, self._senderhwaddr.packed, self._senderprotoaddr.packed, self._targethwaddr.packed, self._targetprotoaddr.packed)
515344
def as_bin(self, *args, **kwargs):
        
        f = io.BytesIO()
        self.stream(f, *args, **kwargs)
        return f.getvalue()
494205
def to_bytes(self):
        '''
        
        '''
        return struct.pack(UDP._PACKFMT, self._src, self._dst,
            self._len, self._checksum)
565375
def pack_list(from_, pack_type):
    
    # We need from_ to not be empty
    if len(from_) == 0:
        return bytes()

    if pack_type == 'c':
        if isinstance(from_, bytes):
            # Catch Python 3 bytes and Python 2 strings
            # PY3 is "helpful" in that when you do tuple(b'foo') you get
            # (102, 111, 111) instead of something more reasonable like
            # (b'f', b'o', b'o'), so we rebuild from_ as a tuple of bytes
            from_ = [six.int2byte(b) for b in six.iterbytes(from_)]
        elif isinstance(from_, six.string_types):
            # Catch Python 3 strings and Python 2 unicode strings, both of
            # which we encode to bytes as utf-8
            # Here we create the tuple of bytes from the encoded string
            from_ = [six.int2byte(b) for b in bytearray(from_, 'utf-8')]
        elif isinstance(from_[0], six.integer_types):
            # Pack from_ as char array, where from_ may be an array of ints
            # possibly greater than 256
            def to_bytes(v):
                for _ in range(4):
                    v, r = divmod(v, 256)
                    yield r
            from_ = [six.int2byte(b) for i in from_ for b in to_bytes(i)]

    if isinstance(pack_type, six.string_types):
        return struct.pack("=" + pack_type * len(from_), *from_)
    else:
        buf = six.BytesIO()
        for item in from_:
            # If we can't pack it, you'd better have packed it yourself. But
            # let's not confuse things which aren't our Probobjs for packable
            # things.
            if isinstance(item, Protobj) and hasattr(item, "pack"):
                buf.write(item.pack())
            else:
                buf.write(item)
        return buf.getvalue()
1024759
def bytes(self):
        
        if self._filename:
            with open(self._filename, "rb") as f:
                return f.read()
        else:
            return self._bytes
751341
def pack(self, value=None):
        
        if isinstance(value, type(self)):
            return value.pack()
        if value is None:
            value = self._value
        return struct.pack('!8B', *[int(v, 16) for v in value.split(':')])
1356548
def _convert_to_bytes(type_name, value):
    """"""

    int_types = {'uint8_t': 'B', 'int8_t': 'b', 'uint16_t': 'H', 'int16_t': 'h', 'uint32_t': 'L', 'int32_t': 'l'}

    type_name = type_name.lower()

    if type_name not in int_types and type_name not in ['string', 'binary']:
        raise ArgumentError('Type must be a known integer type, integer type array, string', known_integers=int_types.keys(), actual_type=type_name)

    if type_name == 'string':
        #value should be passed as a string
        bytevalue = bytes(value)
    elif type_name == 'binary':
        bytevalue = bytes(value)
    else:
        bytevalue = struct.pack("<%s" % int_types[type_name], value)

    return bytevalue
1082703
def pack(self):
        
        payload = io.BytesIO()
        # Advance num bytes equal to header size - the header is written later
        # after the payload of all segments and parts has been written:
        payload.seek(self.header_size, io.SEEK_CUR)

        # Write out payload of segments and parts:
        self.build_payload(payload)

        packet_length = len(payload.getvalue()) - self.header_size
        self.header = MessageHeader(self.session_id, self.packet_count, packet_length, constants.MAX_SEGMENT_SIZE,
                                    num_segments=len(self.segments), packet_options=0)
        packed_header = self.header_struct.pack(*self.header)

        # Go back to begining of payload for writing message header:
        payload.seek(0)
        payload.write(packed_header)
        payload.seek(0, io.SEEK_END)

        trace(self)

        return payload
51201
def _pack(self):
        """"""
        data = ByteBuffer()
        if not hasattr(self, '__fields__'):
            return data.array

        for field in self.__fields__:
            field.encode(self, data)
        return data.array