Encode this slot identifier into a binary descriptor.

        Returns:
            bytes: The 8-byte encoded slot identifier
358178
def encode(self):
        

        slot = 0
        match_op = self.KNOWN_MATCH_NAMES['match_controller']

        if not self.controller:
            slot = self.slot
            match_op = self.KNOWN_MATCH_NAMES['match_slot']

        return struct.pack("<B6xB", slot, match_op)
92578
def to_bytes(self):
        '''
        
        '''
        # Verify that the properties make sense
        self.sanitize()

        # Write the version
        bitstream = BitStream('uint:4=%d' % self.version)

        # Write the traffic class
        bitstream += BitStream('uint:8=%d' % self.traffic_class)

        # Write the flow label
        bitstream += BitStream('uint:20=%d' % self.flow_label)

        # Write the payload length
        payload_bytes = bytes(self.payload)
        payload_length = len(payload_bytes)
        bitstream += BitStream('uint:16=%d' % payload_length)

        # Write the next header type
        bitstream += BitStream('uint:8=%d' % self.next_header)

        # Write the hop limit
        bitstream += BitStream('uint:8=%d' % self.hop_limit)

        # Write the source and destination addresses
        bitstream += BitStream('uint:128=%d, '
                               'uint:128=%d' % (int(self.source),
                                                int(self.destination)))

        return bitstream.bytes + payload_bytes
782438
def data_from_bytes(self, byte_representation):
        
        text = byte_representation.decode(self.encoding)
        return self.data_from_string(text)
819045
def encode_int(n):
    
    global ENCODED_INT_CACHE

    try:
        return ENCODED_INT_CACHE[n]
    except KeyError:
        pass

    if n < MIN_29B_INT or n > MAX_29B_INT:
        raise OverflowError("Out of range")

    if n < 0:
        n += 0x20000000

    bytes = ''
    real_value = None

    if n > 0x1fffff:
        real_value = n
        n >>= 1
        bytes += chr(0x80 | ((n >> 21) & 0xff))

    if n > 0x3fff:
        bytes += chr(0x80 | ((n >> 14) & 0xff))

    if n > 0x7f:
        bytes += chr(0x80 | ((n >> 7) & 0xff))

    if real_value is not None:
        n = real_value

    if n > 0x1fffff:
        bytes += chr(n & 0xff)
    else:
        bytes += chr(n & 0x7f)

    ENCODED_INT_CACHE[n] = bytes

    return bytes
1234126
def binary_size(self):
        ''''''
        return (
            1 + # group_id
            2 + # next offset marker
            1 + len(self.name.encode('utf-8')) + # size of name and name bytes
            1 + # data size
            1 + len(self.dimensions) + # size of dimensions and dimension bytes
            self.total_bytes + # data
            1 + len(self.desc.encode('utf-8')) # size of desc and desc bytes
            )
1043398
def to_bytes(self):
        '''
        
        '''
        # Verify that the properties make sense
        self.sanitize()

        # Write the next header type
        bitstream = BitStream('uint:8=%d' % self.next_header)

        # Add the reserved bits
        bitstream += BitStream(8)

        # Add the fragment offset
        bitstream += BitStream('uint:13=%d' % self.fragment_offset)

        # Add the reserved bits
        bitstream += BitStream(2)

        # Add the flags
        bitstream += BitStream('bool=%d' % self.more_fragments)

        # Add the identification
        bitstream += BitStream('uint:32=%d' % self.identification)

        return bitstream.bytes + bytes(self.payload)
618770
def binary_tlv_to_python(binary_string, result=None):
    
    result = {} if result is None else result

    if not binary_string:
        return result

    byte = binary_string[0]
    kind = byte & type_mask
    id_length = get_id_length(byte)
    payload_length = get_value_length(byte)

    # start after the type indicator
    offset = 1
    item_id = str(combine_bytes(binary_string[offset:offset + id_length]))
    offset += id_length

    # get length of payload from specifier
    value_length = payload_length
    if byte & length_type_mask != LengthTypes.SET_BYTE:
        value_length = combine_bytes(binary_string[offset:offset + payload_length])
        offset += payload_length

    if kind == Types.MULTI:
        binary_tlv_to_python(
            binary_string[offset:offset + value_length],
            result.setdefault(item_id, {})
        )
    else:
        value_binary = binary_string[offset: offset + value_length]
        result[item_id] = (
            combine_bytes(value_binary) if not all(value_binary) else value_binary.decode('utf8')
        )

    offset += value_length
    binary_tlv_to_python(binary_string[offset:], result)
    return result
159559
def toUnicode(s):
    
    if isinstance(s, six.binary_type):
        s = s.decode('utf-8')
    return s
715378
def encode(self):
        
        buf = bytearray()
        for typ in sorted(self.format.keys()):
            encoded = None
            if typ != 0xFFFF: # end of block
                (name, marshall) = self.format[typ]
                value = getattr(self, name, None)
                if value is not None:
                    try:
                        encoded = marshall.encode(value)
                        self.log.debug("Encoded field [{0}] to value {1!r}".format(name, encoded))
                    except:
                        self.log.exception("Error encoding key/value: key={0}, value={1!r}".format(name, value))
                        raise
            
            # Note, there is an assumption here that encode() func is returning
            # a byte string (so len = num bytes).  That should be a safe assumption.
            size = len(encoded) if encoded is not None else 0
            packed = struct.pack('<H', typ)
            packed += struct.pack('<I', size)
            if encoded is not None:
                if isinstance(encoded, bytearray):
                    encoded = str(encoded)
                elif isinstance(encoded, unicode):
                    encoded = encoded.encode('utf-8')
                packed += struct.pack('<%ds' % size, encoded)
                
            buf += packed
            
        return buf
146001
def FromEncoded(self, encoded):
        

        stream_type = (encoded >> 12) & 0b1111
        stream_system = bool(encoded & (1 << 11))
        stream_id = (encoded & ((1 << 11) - 1))

        return DataStream(stream_type, stream_id, stream_system)
169257
def value(self):
        
        binary = UBInt8(self.sub_type).pack() + self.sub_value.pack()
        return BinaryData(binary)
495857
def to_ansi_8bit(self):
        
        res = []
        for i in self.parts:
            res.append(i.to_ansi_8bit())
        return ''.join(res).encode('utf8')
932215
def to_bytes(self):
        '''
        
        '''
        # Verify that the properties make sense
        self.sanitize()

        # Write the next header type
        bitstream = BitStream('uint:8=%d' % self.next_header)

        # Write the header length
        header_length_unpadded = len(self.options) + 2
        header_length = math.ceil(header_length_unpadded / 8.0)
        bitstream += BitStream('uint:8=%d' % (header_length - 1))

        # Add the options
        bitstream += BitStream(bytes=self.options)
        padding_len = (8 - (header_length_unpadded % 8)) % 8
        bitstream += BitStream(padding_len * 8)

        return bitstream.bytes + bytes(self.payload)
1059837
function extractIdentifier(packet) {
  let identifier = identifiers.REELYACTIVE_OUI36 + packet.substr(0,7);

  return {
      identifier: identifier,
      identifierType: identifiers.TYPE_EUI64
  }
}
522694
private byte encodeTargetDiscriminator() {
        byte result = 0;
        if (Positions.isReadable(targetPosition)) {
            result |= 1;
        }
        if (Positions.isWritable(targetPosition)) {
            result |= 2;
        }
        return result;
    }
124502
def decode(self, descriptor):
        
        i = iter(descriptor)
        n = len(self._schema)

        # Add the name key to our schema
        schema = self._schema + ('name',)
        # For each dimensions, generator takes n items off iterator
        # wrapping the descriptor, making a tuple with the dimension
        # name appended
        tuple_gen = (tuple(itertools.islice(i, n)) + (d, )
            for d in self._dimensions)

        # Generate dictionary by mapping schema keys to generated tuples
        return [{ k: v for k, v in zip(schema, t) } for t in tuple_gen]
494494
def encode(self):
		

		buff = _GNTPBuffer()

		buff.writeln(self._format_info())

		#Headers
		for k, v in self.headers.items():
			buff.writeheader(k, v)
		buff.writeln()

		#Notifications
		if len(self.notifications) > 0:
			for notice in self.notifications:
				for k, v in notice.items():
					buff.writeheader(k, v)
				buff.writeln()

		#Resources
		for resource, data in self.resources.items():
			buff.writeheader('Identifier', resource)
			buff.writeheader('Length', len(data))
			buff.writeln()
			buff.write(data)
			buff.writeln()
			buff.writeln()

		return buff.getvalue()