Create a message set using the given codec.

    If codec is CODEC_NONE, return a list of raw Kafka messages. Otherwise,
    return a list containing a single codec-encoded message.
7220
def create_message_set(messages, codec=CODEC_NONE, key=None, compresslevel=None):
    
    if codec == CODEC_NONE:
        return [create_message(m, k) for m, k in messages]
    elif codec == CODEC_GZIP:
        return [create_gzip_message(messages, key, compresslevel)]
    elif codec == CODEC_SNAPPY:
        return [create_snappy_message(messages, key)]
    else:
        raise UnsupportedCodecError("Codec 0x%02x unsupported" % (codec,))
151532
def _create_batch_message(self):
        
        return Message(body=[],
                       properties=self.properties,
                       annotations=self.annotations,
                       msg_format=self.batch_format,
                       header=self.header,
                       encoding=self._encoding)
352946
def get_codec(data):
    
    try:
        key = ensure_bytes(data[:CODE_LENGTH], 'utf8')
        codec = ENCODINGS_LOOKUP[key]
    except KeyError:
        raise ValueError('Can not determine encoding for {}'.format(data))
    else:
        return codec
621977
def encode_consumermetadata_request(cls, client_id, correlation_id,
                                        consumer_group):
        
        message = cls._encode_message_header(client_id, correlation_id,
                                             KafkaCodec.CONSUMER_METADATA_KEY)
        message += write_short_ascii(consumer_group)
        return message
598425
function Message(payload, checksum, magic, compression){
  // note: payload should be a Buffer
  var _compression = COMPRESSION_DEFAULT;

  // compression:
  // 0 = none; 1 = gzip; 2 = snappy;
  // Only exists at all if MAGIC == 1
  if (!!magic && magic == 1){
    if (_.include([0,1,2], compression)){
      _compression = compression;
    } else {
      throw "InvalidCompressionType: " + compression;
    }
  }
  this.compression = _compression;
  this.MAGIC_IDENTIFIER_DEFAULT = 1;
  if (magic === undefined){ 
    this.magic = this.MAGIC_IDENTIFIER_DEFAULT;
  } else { 
    this.magic = magic;
  }
  if (this.magic !== 0 && this.magic !== 1){
    throw "Unsupported Kafka message version: " + this.magic;
  }
  if (!payload && payload !== ''){
    throw "payload is a required argument";
  }
  this.payload = payload;
  this.checksum = checksum || this.calculateChecksum();
}
898796
def decode_message(self, message, is_key=False):
        

        if message is None:
            return None

        if len(message) <= 5:
            raise SerializerError("message is too small to decode")

        with ContextStringIO(message) as payload:
            magic, schema_id = struct.unpack('>bI', payload.read(5))
            if magic != MAGIC_BYTE:
                raise SerializerError("message does not start with magic byte")
            decoder_func = self._get_decoder_func(schema_id, payload, is_key)
            return decoder_func(payload)
16853
@SuppressWarnings("unchecked")
    @Sensitive
    public static X509Certificate[] decodeCertChain(Codec codec, @Sensitive byte[] encodedCertChain) throws SASException {
        X509Certificate[] certificateChain = null;

        try {
            Any any = codec.decode_value(encodedCertChain, X509CertificateChainHelper.type());
            byte[] decodedCertificateChain = X509CertificateChainHelper.extract(any);

            CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
            ByteArrayInputStream bais = new ByteArrayInputStream(decodedCertificateChain);
            CertPath certPath = certificateFactory.generateCertPath(bais);
            List<X509Certificate> certificates = (List<X509Certificate>) certPath.getCertificates();

            certificateChain = new X509Certificate[certificates.size()];
            for (int i = 0; i < certificates.size(); i++) {
                certificateChain[i] = certificates.get(i);
            }
        } catch (Exception e) {
            throw new SASException(1, e);
        }
        return certificateChain;
    }
986969
private String buildMessage( String rawMessage ){
        StringBuilder msg = new StringBuilder();
        if( changeLogName != null ){
            msg.append( changeLogName ).append( ": " );
        }
        if( changeSetName != null ){
            msg.append( changeSetName.replace( changeLogName + "::", "" ) ).append( ": " );
        }
        msg.append( rawMessage );
        return msg.toString();
    }
1103430
def schnorr_generate_nonce_pair(self, msg, raw=False,
                                    digest=hashlib.sha256):
        
        if not HAS_SCHNORR:
            raise Exception("secp256k1_schnorr not enabled")

        msg32 = _hash32(msg, raw, digest)
        pubnonce = ffi.new('secp256k1_pubkey *')
        privnonce = ffi.new('char [32]')

        valid = lib.secp256k1_schnorr_generate_nonce_pair(
            self.ctx, pubnonce, privnonce, msg32, self.private_key,
            ffi.NULL, ffi.NULL)
        assert valid == 1

        return pubnonce, privnonce
552693
public final List<DataSlice> encodeFast(Object conn) throws MessageEncodeFailedException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "encodeFast");

    // ControlMessages are always single part small messages, so we encode them
    // to a single DataSlice.
    List<DataSlice> slices = new ArrayList<DataSlice>(1);
    slices.add(jmo.encodeSinglePartMessage(conn));

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "encodeFast");
    return slices;
  }
208096
public static <T> Codec<T> create(Class<T> cls, boolean debug) {
        return create(cls, debug, null);
    }
1015161
function DecodeMessage (raw) {
  if (!(raw instanceof BufferList)) {
    raw = new BufferList(raw)
  }

  var version = msgpack.decode(raw)
  var messageType = msgpack.decode(raw)
  var MessageClass = messageTypeToFunction[messageType]

  if (!MessageClass) {
    throw new DxlError('Unknown message type: ' + messageType)
  }

  var message = new MessageClass()
  message.version = version
  message._unpackMessage(raw)
  if (version > 0) {
    message._unpackMessagev1(raw)
  }
  if (version > 1) {
    message._unpackMessagev2(raw)
  }

  return message
}
223248
def _CreateDictReader(self, line_reader):
    
    for line in line_reader:
      if isinstance(line, py2to3.BYTES_TYPE):
        try:
          line = codecs.decode(line, self._encoding)
        except UnicodeDecodeError as exception:
          raise errors.UnableToParseFile(
              'Unable decode line with error: {0!s}'.format(exception))

      stripped_line = line.strip()
      values = stripped_line.split(self.DELIMITER)
      number_of_values = len(values)
      number_of_columns = len(self.COLUMNS)

      if number_of_values < self.MIN_COLUMNS:
        raise errors.UnableToParseFile(
            'Expected at least {0:d} values, found {1:d}'.format(
                self.MIN_COLUMNS, number_of_values))

      if number_of_values > number_of_columns:
        raise errors.UnableToParseFile(
            'Expected at most {0:d} values, found {1:d}'.format(
                number_of_columns, number_of_values))

      yield dict(zip(self.COLUMNS, values))
537071
def buildMessage(headers, parts):
    
    message = multipart.MIMEMultipart('alternative')

    for name, value in headers.iteritems():
        name = name.title()
        if name == "From":
            multipart[name] = _encodeAddress(value)
        elif name in ["To", "Cc", "Bcc"]:
            multipart[name] = _encodeAddresses(value)
        else:
            multipart[name] = _encodeHeader(value)

    for partType, part in parts.iteritems():
        mimeText = text.MIMEText(part.encode("utf-8"), partType, "UTF-8")
        message.attach(mimeText.encode())

    return message
967179
static Codec<NamingMessage> createFullCodec(final IdentifierFactory factory) {
    final Map<Class<? extends NamingMessage>, Codec<? extends NamingMessage>> clazzToCodecMap
        = new HashMap<>();
    clazzToCodecMap.put(NamingLookupRequest.class, new NamingLookupRequestCodec(factory));
    clazzToCodecMap.put(NamingLookupResponse.class, new NamingLookupResponseCodec(factory));
    clazzToCodecMap.put(NamingRegisterRequest.class, new NamingRegisterRequestCodec(factory));
    clazzToCodecMap.put(NamingRegisterResponse.class,
        new NamingRegisterResponseCodec(new NamingRegisterRequestCodec(factory)));
    clazzToCodecMap.put(NamingUnregisterRequest.class, new NamingUnregisterRequestCodec(factory));
    final Codec<NamingMessage> codec = new MultiCodec<>(clazzToCodecMap);
    return codec;
  }
475332
public static SockJsFrame messageFrame(SockJsMessageCodec codec, String... messages) {
        String encoded = codec.encode(messages);
        return new SockJsFrame(encoded);
    }
92418
def new_encoded_stream(args, stream):
    ''''''
    if args.ascii_print:
        return wpull.util.ASCIIStreamWriter(stream)
    else:
        return stream