Helper function to encode the attachment for a message.
@param {Buffer} buffer
@param {Number} offset
@param {string} message
@returns {Number} New offset
@throws {Error}
345562
function encodeAttachmentMessage(buffer, offset, message) {
    if (message == undefined)
        throw Error('Specify message');
    offset += encodeString(buffer, message, offset);
    return offset;
}
1029916
function(target, targetOffset, offset, length) {
    return this.toBuffer().copy(target, targetOffset, offset, length);
  }
1021450
function onMessage(message) {
    if (message.type != "utf8") return

    DEBUGMSG("recv: " + message.utf8Data)
    message = JSON.parse(message.utf8Data)

    if      (message.type == "request")  session.onRequest(channel, message)
    else if (message.type == "response") session.onResponse(channel, message)
    else if (message.type == "event")    session.onEvent(channel, message)
  }
111849
private function attach_files(&$message) {
		foreach ($this->files as $file) {
			if (gettype($file) == 'string') {
				$message->attach(\Swift_Attachment::fromPath($file)->setFilename(basename($file)));
			} else {
				$message->attach(\Swift_Attachment::fromPath($file->get_path())->setFilename($file->name));
			}
		}
	}
76943
public void encodeTo(QualityFormat format, byte[] buffer, int offset) {
        byte vo = format.getOffset();
        for (int i = 0; i < data.length; ++i)
            buffer[offset++] = (byte) (data[i] + vo);
    }

    /**
     * Encodes current quality line with given offset. Common values for offset are 33 and 64.
     *
     * @param offset offset
     * @return bytes encoded quality values
     */
    public byte[] encode(int offset) {
        if (offset < 0 || offset > 70)
            throw new IllegalArgumentException();

        byte[] copy = new byte[data.length];
        for (int i = copy.length - 1; i >= 0; --i)
            copy[i] += data[i] + offset;
        return copy;
    }
189749
function AisEncode (msg) {
    this.payload = new Buffer(425); // make a buffer force it 6bit/zero
    this.payload.fill (0x0);        // init to 6bits encoded zero value
    this.payloadSize =0;            // Payload size depend on messages
    this.nmea =[];

    this.PutInt (msg.aistype  ,0,6);
    this.PutInt (msg.repeat   ,6,2);
    this.PutInt (msg.mmsi     ,8,30);
    var lat; var lon; var sog; var hdg; var accuracy; var rot;

    switch (msg.aistype) {
        case 1:
        case 2:
        case 3: // class A position report
            this.class      = 'A';
            this.PutInt(msg.navstatus, 38, 4 );

            // move lat to integer and take care of negative value
            lon = parseInt (msg.lon * 600000);
            if (lon < 0) lon |= 0x08000000;    // on 28 bits
            this.PutInt(lon, 61, 28 );

            lat = parseInt (msg.lat * 600000); // on 27 bits
            if (lat < 0) lat |= 0x04000000;
            this.PutInt(lat, 89, 27 );

            rot=parseInt (msg.rot);  //Rate of turn
            this.PutInt (rot,  42, 8 );

            sog=parseInt (msg.sog *10);  //speed over ground
            this.PutInt (sog,  50, 10 );

            cog=parseInt (msg.cog *10);  //course over ground
            this.PutInt (cog,  116, 12 );

            hdg=parseInt (msg.hdg) || parseInt (msg.cog); //magnetic heading
            this.PutInt (hdg,  128, 9 );

            this.PutInt  (60,  137, 6 );  // 60 if time stamp is not available
            this.PutInt  (msg.smi, 143, 2);

            this.payloadSize=168;   // pad with zero non used flags

            break;
        case 18: // class B position report
            this.class  = 'B';

            sog=parseInt (msg.sog *10);  //speed over ground
            this.PutInt (sog,  46, 10 );

            accuracy= parseInt (msg.accuracy);
            this.PutInt(accuracy, 56, 1 );

            // move lat to integer and take care of negative value
            lon = parseInt (msg.lon * 600000); //Long 1/10000 minute
            if (lon < 0) lon |= 0x08000000;
            this.PutInt(lon, 57, 28 );

            lat = parseInt (msg.lat * 600000); //Lat 1/10000 minute
            if (lat < 0) lat |= 0x04000000;
            this.PutInt(lat, 85, 27 );

            var cog=parseInt (msg.cog *10);  //course over ground
            this.PutInt (cog,  112, 12 );

            hdg=parseInt (msg.hdg)|| parseInt (msg.cog);      //magnetic heading
            this.PutInt (hdg,  124, 9 );

            this.PutInt  (60,  133, 6 );  // 60 [time stamp is not available]

            this.payloadSize=168;   // pad with zero non used flags
            break;
        case 5:
            this.class  = 'A';
//          Get the AIS Version indicator
//          0 = station compliant with Recommendation ITU-R M.1371-1
//          1 = station compliant with Recommendation ITU-R M.1371-3
//          2-3 = station compliant with future editions

            this.PutInt (1,38, 2); // version station =1
            this.PutInt (msg.imo     ,40, 30);
            this.PutStr (msg.callsign,70, 42);
            this.PutStr (msg.shipname,112, 120);
            this.PutInt (msg.cargo   ,232, 8);
            this.PutInt (msg.dimA    ,240, 9);
            this.PutInt (msg.dimB    ,249, 9);
            this.PutInt (msg.dimC    ,258, 6);
            this.PutInt (msg.dimD    ,264, 6);
            this.PutInt (msg.etaMo   ,274, 4);
            this.PutInt (msg.etaDay  ,278, 5);
            this.PutInt (msg.etaHr   ,283, 5);
            this.PutInt (msg.etaMin  ,288, 6);
            var draught = parseInt (msg.draught*10);
            this.PutInt((parseInt(draught*10)), 294, 8);
            this.PutStr(msg.destination,302,120);
            this.payloadSize=422;
            break;
      
        case 21:
            this.PutInt(msg.aid_type, 38, 5);
            this.PutStr(msg.atonname, 43, 120);
            accuracy= parseInt (msg.accuracy);
            this.PutInt(accuracy,     163, 1);
      
            lon = parseInt (msg.lon * 600000); //Long 1/10000 minute
            if (lon < 0) lon |= 0x08000000;
            this.PutInt(lon, 164, 28 );
      
            lat = parseInt (msg.lat * 600000); //Lat 1/10000 minute
            if (lat < 0) lat |= 0x04000000;
            this.PutInt(lat, 192, 27 );

            this.PutInt (msg.dimA     ,219, 9);
            this.PutInt (msg.dimB     ,228, 9);
            this.PutInt (msg.dimC     ,237, 6);
            this.PutInt (msg.dimD     ,243, 6);

            this.PutInt (60           ,253, 6 ); // 60 if time stamp is not available
            this.PutInt (msg.off_position, 259, 1);
            this.PutInt (msg.raim     ,268, 1);
            this.PutInt (msg.virtual_aid, 269, 1);
            this.PutInt (msg.assigned ,270, 1);
            break;
      
        case 24:  // Vesel static information
            this.class='B';
            this.PutInt(msg.part, 38, 2 );
            if (msg.part===0) {
                this.PutStr(msg.shipname, 40, 120);
                this.payloadSize=160;
            } else if ( msg.part === 1) {
                this.PutInt(msg.cargo   , 40, 8 );
                this.PutStr(msg.callsign, 90, 42);
                this.PutInt (msg.dimA, 132, 9 );
                this.PutInt (msg.dimB, 141, 9 );
                this.PutInt (msg.dimC, 150, 6 );
                this.PutInt (msg.dimD, 156, 6 );
                this.payloadSize=168; // ignore last flags
            } else {
                // message part missing
                this.valid=false;
            }
            break;
        case 25:  // single slot Binary message
            this.class='B';
            this.PutInt(1, 38, 1 ); // single destination
            this.PutInt(msg.mmsi   , 40, 20 ); // we self ping only
            this.payloadSize=168; // ignore last flags
            break;
        default:
            // not implemented
            this.valid=false;
            return;
    }

    // Make sure we finish on a byte boundary
    var size= parseInt(this.payloadSize/6);
    if (this.payloadSize%6 > 0) size++;
    for(var i = 0; i < size ; i++) {
        var chr = this.payload[i];

        // move to printable char from wacky AIS/IEC 6 bit representation
        if (chr < 40) {
            this.payload[i] = chr +48;
        } else {
            this.payload[i] = chr +56;
        }
    }

    // Finish nmea message !AIVDM,1,1,,B,B69>7mh0?J<:>05B0`0e;wq2PHI8,0*3D'
    // this.fragcnt = nmea[1];  // fragment total count for this message
    // this.fragnum = nmea[2];  // fragment number
    // this.fragid  = nmea[3];  // fragment sequential index for multipart message
    // this.pading  = nmea[6].split ('*')[0];
    var nmea=[];
    nmea [0] = '!AIVDM';  // ! is added after checksum
    nmea [1]  = '1';      // ignore multipart extention messages
    nmea [2]  = '1';
    nmea [3]  = '';
    nmea [4]  = 'A';     // this is VHF channel and not AIS class
    nmea [5]  = this.payload.toString("utf8", 0, size);
    nmea [6]  = 0;
    var paquet = nmea.toString();

    var checksum = 0; // http://rietman.wordpress.com/2008/09/25/how-to-calculate-the-nmea-checksum/
    for(var i = 1; i < paquet.length; i++) {
        checksum = checksum ^ paquet.charCodeAt(i);
    }

    var trailer;
    if (checksum < 16)  trailer= "*0" + checksum.toString(16).toUpperCase();
    else trailer= "*" + checksum.toString(16).toUpperCase();

    this.nmea =  paquet + trailer;
    this.valid=  true;
}
278482
def into_buffer(self, buf, offset):
    
    self.payload = containerize(exclude_fields(self))
    self.parser = MsgEphemerisGPSDepF._parser
    self.stream_payload.reset(buf, offset)
    return self.pack_into(buf, offset, self._build_payload)
826747
function encodeAttachmentCert(buffer, offset, attachment_data) {
    offset += encodeString(buffer, attachment_data.symbol, offset);
    offset += encodeString(buffer, attachment_data.owner, offset);
    offset += encodeString(buffer, attachment_data.address, offset);
    offset = buffer.writeUInt32LE(attachment_data.cert, offset);
    offset = buffer.writeUInt8(attachment_data.status, offset);
    if (attachment_data.content) {
        offset += encodeString(buffer, attachment_data.content, offset);
    }
    return offset;
}
261794
function encodeAttachmentMITRegister(buffer, offset, symbol, content, address) {
    offset = buffer.writeUInt8(Constants.MIT.STATUS.REGISTER, offset);
    offset += encodeString(buffer, symbol, offset);
    offset += encodeString(buffer, address, offset);
    offset += encodeString(buffer, content, offset);
    return offset;
}
569009
function encodeArray(array, proto, offset, buffer, protos){
    let i = 0;

    if(util.isSimpleType(proto.type)){
      offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
      offset = writeBytes(buffer, offset, codec.encodeUInt32(array.length));
      for(i = 0; i < array.length; i++){
        offset = encodeProp(array[i], proto.type, offset, buffer);
      }
    }else{
      for(i = 0; i < array.length; i++){
        offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
        offset = encodeProp(array[i], proto.type, offset, buffer, protos);
      }
    }

    return offset;
  }
581268
function appendPre(message) {
	var pre = document.getElementById('content');
	var textContent = document.createTextNode(message + '\n');
	pre.appendChild(textContent);
}
289903
function decrypt(message) {
  if (this.secure && this.cipher && this.secret) {
    if (this.secret === 'secret') {
      console.warn('PLEASE change default secret password!');
    }
    debug('%s decrypt message with %s', this.name, this.cipher);
    var decipher = crypto.createDecipher(this.cipher, this.secret);
    return Buffer.concat([decipher.update(message), decipher.final()]);
  }
  return message;
}
813028
function fromHex(hex, binary, offset) {
  if (binary) {
    binary.write(hex, offset, "hex");
    return binary;
  }
  return new Buffer(hex, 'hex');
}
1092072
function(message) {
    if (!_.isObject(message)) {
      message = {
        message: message
      };
    }

    try {
      message = JSON.stringify(_.defaultsDeep({}, message, this.config.defaultProps));
    } catch (e) {
      return this.logger.error('Logmatic - error while parsing log message. Not sending', e);
    }

    if (this.isConnected) {
      this.sendMessage(message);
    } else {
      this.messageBuffer.push(message);
    }
  }
1335272
function (message) {
    var objs = [], collector = '', chr, msglen, data;

    this.data += message;
    data = new Buffer(this.data, 'utf8');

    for (var i = 0; i < data.length; i += 1) {
        chr = data[i];
        if (chr > 47 && chr < 58) {
            collector += String.fromCharCode(chr);
        } else if (chr !== 10 && chr !== 13) {
            msglen = parseInt(collector, 10);

            if (msglen + i <= data.length) {
              objs.push(JSON.parse(data.toString('utf8', i, msglen + i)));
              data = data.slice(i + msglen);
              collector = '';
              i = 0;
            } else {
              break;
            }
        }
    }
    this.data = data.toString('utf8');
    return objs;
}
627401
public byte [] detached(byte [] message) {
            byte[] signedMsg = this.sign(message);
            byte[] sig = new byte[signatureLength];
            for (int i = 0; i < sig.length; i++)
                sig[i] = signedMsg[i];
            return sig;
        }
578296
function encodeBuffer(buf, options, cb) {
  if(typeof options === 'function') {
    cb = options;
    options = {};
  }

  try {
    buf = bufferUtils.toArrayLike(buf);

    if(!options.hasOwnProperty('width') || !options.hasOwnProperty('height')) {
      return cb(new Error('Provide width & height of the buffer'));
    }

    if(hasWorker) {
      const wr = require('webworkify')(encodeWorker);

      wr.onmessage = ({ data: msg }) => {
        const err = msg.err ? new Error(msg.err) : undefined;
        cb(err, msg.result);
      };

      const msg = {
        buf: buf,
        options: options
      };

      if (options.transferable) {
        wr.postMessage(msg, [ buf ]);
      } else {
        wr.postMessage(msg);
      }
    } else {
      encode(buf, options, cb);
    }
  } catch(err) {
    cb(err);
  }
}