Encoder ----------------------------------------------------------------
163718
function _encode(value, top) {

        // Numbers
        if (typeof value === 'number') {

            var type = value !== (value | 0) ? 1 : 0,
                sign = 0;

            if (value < 0) {
                value = -value;
                sign = 1;
            }

            write(1 + type, 3);

            // Float
            if (type) {

                var shift = 0,
                    step = 10,
                    m = value,
                    tmp = 0;

                // Figure out the exponent
                do {
                    m = value * step;
                    step *= 10;
                    shift++;
                    tmp = m | 0;

                } while(m - tmp > 1 / step && shift < 8 && m < 214748364);

                // Correct if we overshoot
                step = tmp / 10;
                if (step === (step | 0)) {
                    tmp = step;
                    shift--;
                }

                value = tmp;

            }

            // 2 size 0-3: 0 = < 16 1 = < 256 2 = < 65536 3 >=
            if (value < 2) {
                write(value, 4);

            } else if (value < 16) {
                write(1, 3);
                write(value, 4);

            } else if (value < 256) {
                write(2, 3);
                write(value, 8);

            } else if (value < 4096) {
                write(3, 3);
                write(value >> 8 & 0xff, 4);
                write(value & 0xff, 8);

            } else if (value < 65536) {
                write(4, 3);
                write(value >> 8 & 0xff, 8);
                write(value & 0xff, 8);

            } else if (value < 1048576) {
                write(5, 3);
                write(value >> 16 & 0xff, 4);
                write(value >> 8 & 0xff, 8);
                write(value & 0xff, 8);

            } else if (value < 16777216) {
                write(6, 3);
                write(value >> 16 & 0xff, 8);
                write(value >> 8 & 0xff, 8);
                write(value & 0xff, 8);

            } else {
                write(7, 3);
                write(value >> 24 & 0xff, 8);
                write(value >> 16 & 0xff, 8);
                write(value >> 8 & 0xff, 8);
                write(value & 0xff, 8);
            }

            write(sign, 1);

            if (type) {
                write(shift, 4);
            }

        // Strings
        } else if (typeof value === 'string') {

            var len = value.length;
            write(3, 3);

            if (len > 65535) {
                write(31, 5);
                write(len >> 24 & 0xff, 8);
                write(len >> 16 & 0xff, 8);
                write(len >> 8 & 0xff, 8);
                write(len & 0xff, 8);

            } else if (len > 255) {
                write(30, 5);
                write(len >> 8 & 0xff, 8);
                write(len & 0xff, 8);

            } else if (len > 28) {
                write(29, 5);
                write(len, 8);

            } else {
                write(len, 5);
            }

            // Write a raw string to the stream
            if (bitsLeft !== 8) {
                bitStream += chrTable[bitValue];
                bitValue = 0;
                bitsLeft = 8;
            }

            bitStream += value;

        // Booleans
        } else if (typeof value === 'boolean') {
            write(+value, 4);

        // Null
        } else if (value === null) {
            write(7, 3);
            write(0, 1);

        // Arrays
        } else if (value instanceof Array) {

            write(4, 3);
            for(var i = 0, l = value.length; i < l; i++) {
                _encode(value[i]);
            }

            if (!top) {
                write(6, 3);
            }

        // Object
        } else {

            write(5, 3);
            for(var e in value) {
                _encode(e);
                _encode(value[e]);
            }

            if (!top) {
                write(6, 3);
            }

        }

    }
707259
public T encoder(Encoder e) {
        if (!encoders.contains(e)) {
            encoders.add(e);
        }
        return derived.cast(this);
    }
1320915
def get_convolutional_encoder(config: ConvolutionalEncoderConfig, prefix: str) -> 'Encoder':
    
    encoder_seq = EncoderSequence([], dtype=config.dtype)
    cls, encoder_params = _get_positional_embedding_params(config.positional_embedding_type,
                                                           config.num_embed,
                                                           max_seq_len=config.max_seq_len_source,
                                                           fixed_pos_embed_scale_up_input=False,
                                                           fixed_pos_embed_scale_down_positions=True,
                                                           prefix=prefix + C.SOURCE_POSITIONAL_EMBEDDING_PREFIX)
    encoder_seq.append(cls, **encoder_params)
    encoder_seq.append(ConvolutionalEncoder, config=config)
    return encoder_seq
1024078
def encode(encoder, pcm, frame_size, max_data_bytes):
    

    pcm = ctypes.cast(pcm, c_int16_pointer)
    data = (ctypes.c_char * max_data_bytes)()

    result = _encode(encoder, pcm, frame_size, data, max_data_bytes)
    if result < 0:
        raise OpusError(result)

    return array.array('c', data[:result]).tostring()
915763
function encodePrimitive( encoder, data ) {

	// ===============================
	//  Plain Objects
	// ===============================

	if (data === false) {

		// Write simple primitive
		encoder.log(LOG.PRM, "simple[false]");
		encoder.stream8.write( pack1b( PRIM_OP.SIMPLE | PRIM_SIMPLE.FALSE ) );
		encoder.counters.op_prm+=1;

	} else if (data === true) {

		// Write simple primitive
		encoder.log(LOG.PRM, "simple[true]");
		encoder.stream8.write( pack1b( PRIM_OP.SIMPLE | PRIM_SIMPLE.TRUE ) );
		encoder.counters.op_prm+=1;

	} else if (data === undefined) {

		// Write simple primitive
		encoder.log(LOG.PRM, "simple[undefined]");
		encoder.stream8.write( pack1b( PRIM_OP.SIMPLE | PRIM_SIMPLE.UNDEFINED ) );
		encoder.counters.op_prm+=1;

	} else if (data === null) {

		// Write simple primitive
		encoder.log(LOG.PRM, "simple[null]");
		encoder.stream8.write( pack1b( PRIM_OP.SIMPLE | PRIM_SIMPLE.NULL ) );
		encoder.counters.op_prm+=1;

	// ===============================
	//  Number
	// ===============================

	} else if (typeof data === "number") {

		if (isNaN(data)) {

			// Write extended simple primitive
			encoder.log(LOG.PRM, "simple[NaN]");
			encoder.stream8.write( pack1b( PRIM_OP.SIMPLE_EX | PRIM_SIMPLE_EX.NAN ));
			encoder.counters.op_prm+=1;

		} else {

			// Get type
			var numType = getNumType( data, data, (data % 1) !== 0 );
			if (numType > NUMTYPE.FLOAT64) {
				throw new Errors.AssertError('A primitive was identified as number but getNumType failed!');
			}

			// Write header
			encoder.log(LOG.PRM, "number, type="+_NUMTYPE[numType]+", n="+data);
			encoder.stream8.write( pack1b( PRIM_OP.NUMBER | numType ) );
			encoder.counters.op_prm+=1;

			// Write data
			pickStream( encoder, numType )
				.write( packByNumType[numType]( data ) );

		}

	// ===============================
	//  Array
	// ===============================

	} else if  ((data instanceof Uint8Array) || (data instanceof Int8Array) ||
				(data instanceof Uint16Array) || (data instanceof Int16Array) ||
				(data instanceof Uint32Array) || (data instanceof Int32Array) ||
				(data instanceof Float32Array) || (data instanceof Float64Array) ||
				(data instanceof Array)) {

		// Write array
		encodeArray( encoder, data );

	// ===============================
	//  Buffers
	// ===============================

	} else if (typeof data === "string") {

		// Write a string buffer primitive
		encoder.log(LOG.PRM, "buffer[string], len="+data.length);
		encodeStringBuffer( encoder, data );

	} else if (data instanceof FileResource) {

		// Embed file resource
		encoder.log(LOG.PRM, "buffer[resource], file="+data.src+", mime="+data.mime);
		encodeEmbeddedFileBuffer( encoder, PRIM_BUFFER_TYPE.RESOURCE, data.src, data.mime );

	} else if (data instanceof BlobResource) {

		// Embed file resource
		encoder.log(LOG.PRM, "buffer[blob], mime="+data.mime);
		encodeEmbeddedBlobBuffer( encoder, PRIM_BUFFER_TYPE.RESOURCE, data.buffer, data.mime );

	} else if (data instanceof ImageElement) {

		// Create a buffer from image
		encoder.log(LOG.PRM, "buffer[image], file="+data.src);
		encodeEmbeddedFileBuffer( encoder, PRIM_BUFFER_TYPE.BUF_IMAGE, data.src );

	} else if (data instanceof ScriptElement) {

		// Create a buffer from image
		encoder.log(LOG.PRM, "buffer[script], file="+data.src);
		encodeEmbeddedFileBuffer( encoder, PRIM_BUFFER_TYPE.BUF_SCRIPT, data.src );

	} else if (data instanceof VideoElement) {

		// Create a buffer from video
		encoder.log(LOG.PRM, "buffer[video], file="+data.src);
		encodeEmbeddedFileBuffer( encoder, PRIM_BUFFER_TYPE.BUF_VIDEO, data.src, data.type );

	} else if (data instanceof AudioElement) {

		// Create a buffer from audio
		encoder.log(LOG.PRM, "buffer[audio], file="+data.src);
		encodeEmbeddedFileBuffer( encoder, PRIM_BUFFER_TYPE.BUF_AUDIO, data.src, data.type );

	// ===============================
	//  Objects
	// ===============================

	} else if (data.constructor === ({}).constructor) {

		// Encode plain object
		encoder.log(LOG.PRM, "object[plain]");
		encodePlainObject( encoder, data );

	} else if (data instanceof Date) {

		// Encode plain object
		encoder.log(LOG.PRM, "object[date]");
		encodePrimitiveDate( encoder, data );

	} else {

		// Encode object
		encoder.log(LOG.PRM, "object[entity]");
		encodeObject( encoder, data );

	}

}
4219
function encodeOutputs(outputs) {

    //Initialize buffer and offset
    let offset = 0;
    var buffer = Buffer.allocUnsafe(100000);
    //Write number of inputs
    offset += bufferutils.writeVarInt(buffer, outputs.length, offset);

    outputs.forEach((output) => {
        //Write value as 8byte integer
        offset = bufferutils.writeUInt64LE(buffer, output.value, offset);
        //Output script
        if (output.script_type) {
            switch (output.script_type) {
                case 'p2sh':
                    offset = writeScriptPayToScriptHash(output.address, buffer, offset);
                    break;
                case 'pubkeyhash':
                    offset = writeScriptPayToPubKeyHash(output.address, buffer, offset);
                    break;
                case 'lock':
                    let locktime_le_string = parseInt(output.locktime).toString(16).replace(/^(.(..)*)$/, "0$1").match(/../g).reverse().join("");
                    offset = writeScriptLockedPayToPubKeyHash(output.address, locktime_le_string, buffer, offset);
                    break;
                case 'attenuation':
                    let model = Script.deserializeAttenuationModel(output.attenuation.model);
                    if (output.attenuation.height_delta > 0)
                        model = Script.adjustAttenuationModel(model, output.attenuation.height_delta);
                    offset = writeAttenuationScript(Script.serializeAttenuationModel(model), output.attenuation.from_tx, output.attenuation.from_index, output.address, buffer, offset);
                    break;
                default:
                    throw 'Unknown script type: ' + output.script_type;
            }
        } else if (output.script) {
            let script = Script.fromASM(output.script).buffer;
            offset += bufferutils.writeVarInt(buffer, script.length, offset);
            offset += script.copy(buffer, offset);
        } else {
            throw 'Neither script not script type present';
        }

        // attachment
        offset = buffer.writeUInt32LE(output.attachment.version, offset);
        offset = buffer.writeUInt32LE(output.attachment.type, offset);

        if (output.attachment.version === Constants.ATTACHMENT.VERSION.DID) {
            offset += encodeString(buffer, output.attachment.to_did, offset);
            offset += encodeString(buffer, output.attachment.from_did, offset);
        }

        switch (output.attachment.type) {
            case Constants.ATTACHMENT.TYPE.ETP_TRANSFER:
                break;
            case Constants.ATTACHMENT.TYPE.MST:
                switch (output.attachment.status) {
                    case Constants.MST.STATUS.REGISTER:
                        offset = encodeAttachmentAssetIssue(buffer, offset, output.attachment);
                        break;
                    case Constants.MST.STATUS.TRANSFER:
                        offset = encodeAttachmentMSTTransfer(buffer, offset, output.attachment.symbol, output.attachment.quantity);
                        break;
                    default:
                        throw Error("Asset status unknown");
                }
                break;
            case Constants.ATTACHMENT.TYPE.MESSAGE:
                offset = encodeAttachmentMessage(buffer, offset, output.attachment.message);
                break;
            case Constants.ATTACHMENT.TYPE.AVATAR:
                offset = encodeAttachmentDid(buffer, offset, output.attachment);
                break;
            case Constants.ATTACHMENT.TYPE.CERT:
                offset = encodeAttachmentCert(buffer, offset, output.attachment);
                break;
            case Constants.ATTACHMENT.TYPE.MIT:
                switch (output.attachment.status) {
                    case Constants.MIT.STATUS.REGISTER:
                        offset = encodeAttachmentMITRegister(buffer, offset, output.attachment.symbol, output.attachment.content, output.attachment.address);
                        break;
                    case Constants.MIT.STATUS.TRANSFER:
                        offset = encodeAttachmentMITTransfer(buffer, offset, output.attachment.symbol, output.attachment.address);
                        break;
                    default:
                        throw Error("Asset status unknown");
                }
                break;
            default:
                throw Error("What kind of an output is that?!");
        }
    });

    return buffer.slice(0, offset);
}
156529
def encode(input)
      input_encoding = input.encoding
      input = input.encode(Encoding::UTF_8).codepoints.to_a
      output = []

      # Initialize the state:
      n = INITIAL_N
      delta = 0
      bias = INITIAL_BIAS

      # Handle the basic code points:
      output = input.select { |char| char <= ASCII_MAX }

      h = b = output.length

      # h is the number of code points that have been handled, b is the
      # number of basic code points

      output << DELIMITER if b > 0

      # Main encoding loop:
      while h < input.length
        # All non-basic code points < n have been
        # handled already. Find the next larger one:

        m = MAXINT

        input.each do |char|
          m = char if char >= n && char < m
        end

        # Increase delta enough to advance the decoder's
        # <n,i> state to <m,0>, but guard against overflow:

        raise(ConversionError, "punycode_overflow (1)") if m - n > ((MAXINT - delta) / (h + 1)).floor

        delta += (m - n) * (h + 1)
        n = m

        input.each_with_index do |char, _|
          if char < n
            delta += 1
            raise(ConversionError, "punycode_overflow(2)") if delta > MAXINT
          end

          next unless char == n

          # Represent delta as a generalized variable-length integer:
          q = delta
          k = BASE
          loop do
            t = k <= bias ? TMIN : k >= bias + TMAX ? TMAX : k - bias
            break if q < t
            output << encode_digit(t + (q - t) % (BASE - t))
            q = ((q - t) / (BASE - t)).floor
            k += BASE
          end
          output << encode_digit(q)
          bias = adapt(delta, h + 1, h == b)
          delta = 0
          h += 1
        end

        delta += 1
        n += 1
      end
      output.collect {|c| c.chr(Encoding::UTF_8)}.join(EMPTY).encode(input_encoding)
    end
128045
public void binmode() {
        Transcoder[] transcoders = new Transcoder[3];
        int n = 0;
        if ((flags & UNIVERSAL_NEWLINE_DECORATOR) != 0) {
            TranscoderDB.Entry entry = TranscoderDB.getEntry(NULL_STRING, "universal_newline".getBytes());
            if (entry.getTranscoder() != null) transcoders[n++] = entry.getTranscoder();
        }

        if ((flags & CRLF_NEWLINE_DECORATOR) != 0) {
            TranscoderDB.Entry entry = TranscoderDB.getEntry(NULL_STRING, "crlf_newline".getBytes());
            if (entry.getTranscoder() != null) transcoders[n++] = entry.getTranscoder();
        }

        if ((flags & CR_NEWLINE_DECORATOR) != 0) {
            TranscoderDB.Entry entry = TranscoderDB.getEntry(NULL_STRING, "cr_newline".getBytes());
            if (entry.getTranscoder() != null) transcoders[n++] = entry.getTranscoder();
        }

        int nTrans = numTranscoders;
        int j = 0;
        for (int i = 0; i < nTrans; i++) {
            int k;
            for (k = 0; k < n; k++) {
                if (transcoders[k] == elements[i].transcoding.transcoder) break;
            }

            if (k == n) {
                elements[j] = elements[i];
                j++;
            } else {
                elements[i].transcoding.close();
                numTranscoders--;
            }

        }
        flags &= ~NEWLINE_DECORATOR_MASK;
    }
68108
private void encodeEnum(GeneratorAdapter mg, TypeToken<?> outputType,
                          int value, int encoder, int schemaLocal) {

    // encoder.writeInt(this.schema.getEnumIndex(value.name()));
    mg.loadArg(encoder);
    mg.loadArg(schemaLocal);
    mg.loadArg(value);
    mg.invokeVirtual(Type.getType(outputType.getRawType()), getMethod(String.class, "name"));
    mg.invokeVirtual(Type.getType(Schema.class), getMethod(int.class, "getEnumIndex", String.class));
    mg.invokeInterface(Type.getType(Encoder.class), getMethod(Encoder.class, "writeInt", int.class));
    mg.pop();
  }
1330987
void HuffmanBlockEncoder(BufferedOutputStream outStream, int zigzag[], int prec, int DCcode, int ACcode) throws IOException {
        int temp, temp2, nbits, k, r, i;

// The DC portion

        temp = temp2 = zigzag[0] - prec;
        if (temp < 0) {
            temp = -temp;
            temp2--;
        }
        nbits = 0;
        while (temp != 0) {
            nbits++;
            temp >>= 1;
        }
//        if (nbits > 11) nbits = 11;
        bufferIt(outStream, (DC_matrix[DCcode])[nbits][0], (DC_matrix[DCcode])[nbits][1]);
        // The arguments in bufferIt are code and size.
        if (nbits != 0) {
            bufferIt(outStream, temp2, nbits);
        }

// The AC portion

        r = 0;

        for (k = 1; k < 64; k++) {
            if ((temp = zigzag[jpegNaturalOrder[k]]) == 0) {
                r++;
            } else {
                while (r > 15) {
                    bufferIt(outStream, (AC_matrix[ACcode])[0xF0][0], (AC_matrix[ACcode])[0xF0][1]);
                    r -= 16;
                }
                temp2 = temp;
                if (temp < 0) {
                    temp = -temp;
                    temp2--;
                }
                nbits = 1;
                while ((temp >>= 1) != 0) {
                    nbits++;
                }
                i = (r << 4) + nbits;
                bufferIt(outStream, (AC_matrix[ACcode])[i][0], (AC_matrix[ACcode])[i][1]);
                bufferIt(outStream, temp2, nbits);

                r = 0;
            }
        }

        if (r > 0) {
            bufferIt(outStream, (AC_matrix[ACcode])[0][0], (AC_matrix[ACcode])[0][1]);
        }

    }
1240320
function normalizeEncoding(enc) {
  var nenc = _normalizeEncoding(enc);
  if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
  return nenc || enc;
}
165755
void addTranscoderAt(Transcoder transcoder, int i) {
        if (numTranscoders == elements.length) {
            EConvElement[] tmp = new EConvElement[elements.length * 2];
            System.arraycopy(elements, 0, tmp, 0, i);
            System.arraycopy(elements, i, tmp, i + 1, elements.length - i);
            elements = tmp;
        } else {
            System.arraycopy(elements, i, elements, i + 1, elements.length - i - 1);
        }

        elements[i] = new EConvElement(transcoder.transcoding(0));
        elements[i].allocate(4096);
        numTranscoders++;

        if (!decorator(transcoder.source, transcoder.destination)) {
            for (int j = numTranscoders - 1; i <= j; j--) {
                Transcoding tc = elements[j].transcoding;
                Transcoder tr = tc.transcoder;
                if (!decorator(tr.source, tr.destination)) {
                    lastTranscoding = tc;
                    break;
                }
            }
        }
    }
971271
function TextEncoder(label, options) {
    // Web IDL conventions
    if (!(this instanceof TextEncoder))
      throw TypeError('Called as a function. Did you forget \'new\'?');
    options = ToDictionary(options);

    // A TextEncoder object has an associated encoding and encoder.

    /** @private */
    this._encoding = null;
    /** @private @type {?Encoder} */
    this._encoder = null;

    // Non-standard
    /** @private @type {boolean} */
    this._do_not_flush = false;
    /** @private @type {string} */
    this._fatal = Boolean(options['fatal']) ? 'fatal' : 'replacement';

    // 1. Let enc be a new TextEncoder object.
    var enc = this;

    // 2. Set enc's encoding to UTF-8's encoder.
    if (Boolean(options['NONSTANDARD_allowLegacyEncoding'])) {
      // NONSTANDARD behavior.
      label = label !== undefined ? String(label) : DEFAULT_ENCODING;
      var encoding = getEncoding(label);
      if (encoding === null || encoding.name === 'replacement')
        throw RangeError('Unknown encoding: ' + label);
      if (!encoders[encoding.name]) {
        throw Error('Encoder not present.' +
                    ' Did you forget to include encoding-indexes.js?');
      }
      enc._encoding = encoding;
    } else {
      // Standard behavior.
      enc._encoding = getEncoding('utf-8');

      if (label !== undefined && 'console' in global) {
        console.warn('TextEncoder constructor called with encoding label, '
                     + 'which is ignored.');
      }
    }

    // For pre-ES5 runtimes:
    if (!Object.defineProperty)
      this.encoding = enc._encoding.name.toLowerCase();

    // 3. Return enc.
    return enc;
  }
308058
function encode(buff) {
  const len = buff.byteLength;
  let off = 0;
  const stra = [];

  while (off < len) {
    let c1 = buff[off++] & 0xff;
    stra.push(BASE64_CODE[(c1 >> 2) & 0x3f]);
    c1 = (c1 & 0x03) << 4;
    if (off >= len) {
      stra.push(BASE64_CODE[c1 & 0x3f]);
      break;
    }
    let c2 = buff[off++] & 0xff;
    c1 |= (c2 >> 4) & 0x0f;
    stra.push(BASE64_CODE[c1 & 0x3f]);
    c1 = (c2 & 0x0f) << 2;
    if (off >= len) {
      stra.push(BASE64_CODE[c1 & 0x3f]);
      break;
    }
    c2 = buff[off++] & 0xff;
    c1 |= (c2 >> 6) & 0x03;
    stra.push(BASE64_CODE[c1 & 0x3f]);
    stra.push(BASE64_CODE[c2 & 0x3f]);
  }
  return stra.join('');
}
8560
function encodeStringBuffer( encoder, str, utf8 ) {

	// If we do not have an explicit utf8 or not decision, pick one now
	if (utf8 === undefined) {
		utf8 = false; // Assume false
		for (var i=0, strLen=str.length; i<strLen; ++i) {
			if (str.charCodeAt(i) > 255) {
				utf8 = true; break;
			}
		}
	}

	// Allocate buffer
	var buf, bufView, bufType;
	if (utf8) {
		buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
		bufView = new Uint16Array(buf);
		bufType = PRIM_BUFFER_TYPE.STRING_UTF8;
		encoder.log(LOG.STR,"string='"+str+"', encoding=utf-8, len="+str.length);
	} else {
		buf = new ArrayBuffer(str.length); // 1 byte for each char
		bufView = new Uint8Array(buf);
		bufType = PRIM_BUFFER_TYPE.STRING_LATIN;
		encoder.log(LOG.STR,"string='"+str+"', encoding=latin, len="+str.length);
	}

	// Copy into buffer
	for (var i=0, strLen=str.length; i<strLen; ++i) {
		bufView[i] = str.charCodeAt(i);
	}

	// Write down
	encodeBuffer( encoder, bufType, null, bufView );

}
528307
function detectEncoding(label, input_stream) {
      if (input_stream.match([0xFF, 0xFE])) {
        input_stream.offset(2);
        return 'utf-16';
      }
      if (input_stream.match([0xFE, 0xFF])) {
        input_stream.offset(2);
        return 'utf-16be';
      }
      if (input_stream.match([0xEF, 0xBB, 0xBF])) {
        input_stream.offset(3);
        return 'utf-8';
      }
      return label;
    }
709100
def _VarintEncoder():
  """"""

  local_chr = chr
  def EncodeVarint(write, value):
    bits = value & 0x7f
    value >>= 7
    while value:
      write(0x80|bits)
      bits = value & 0x7f
      value >>= 7
    return write(bits)

  return EncodeVarint