classes 
Represents a frame header that could be used to read from a Buffer or to write to a Buffer
511644
function FrameHeader(values) {
  if (values) {
    if (values instanceof Buffer) {
      this.fromBuffer(values);
    }
    else {
      for (var prop in values) {
        this[prop] = values[prop];
      }
    }
  }
}
1229282
private void readHeaderFromBuffer(final ByteBuffer buffer) {
    int toRead = MIN_RECV_PACKET - headerOffset;
    int available = buffer.remaining();
    toRead = Math.min(toRead, available);
    getLogger().debug("Reading %d header bytes", toRead);
    buffer.get(header, headerOffset, toRead);
    headerOffset += toRead;
  }
622118
public void writeRecordClassDetail(String strRecordClass)
    {
        ClassInfo recClassInfo = (ClassInfo)this.getMainRecord();
        try   {
            this.readRecordClass(strRecordClass);
            if (m_MethodNameList.size() != 0)
                m_MethodNameList.removeAllElements();
            this.writeClassInterface();
        
            m_StreamOut.writeit("private static final long serialVersionUID = 1L;\n");

            Record recFieldData = this.getRecord(FieldData.FIELD_DATA_FILE);
            Record recFileHdr = this.getRecord(FileHdr.FILE_HDR_FILE);
            FieldIterator fieldIterator = new FieldIterator(recFileHdr, recClassInfo, recFieldData, true);
        	this.writeFieldOffsets(fieldIterator, CodeType.THICK); // Write the BaseField offsets
            this.writeKeyOffsets(CodeType.THICK);   // Write the Key offsets
        
            this.writeClassFields(CodeType.THICK);
            this.writeDefaultConstructor(strRecordClass);
            
            this.writeRecordInit();
            this.writeInit();   // Special case... zero all class fields!
        
            recFileHdr.getField(FileHdr.FILE_NAME).setString(strRecordClass);
            recFileHdr.setKeyArea(FileHdr.FILE_NAME_KEY);
            boolean bFileType = (recFileHdr.seek("="));
            if (bFileType) // Is there a file with this name?
            {
                String dBFileName = recFileHdr.getField(FileHdr.FILE_MAIN_FILENAME).getString();
                if (dBFileName.length() != 0)
                {
                    dBFileName = this.fixSQLName(dBFileName);
                    if (dBFileName.equalsIgnoreCase("NONE"))
                        dBFileName = null;
                }
                else if (recFileHdr.getField(FileHdr.TYPE).toString().indexOf("MAPPED") == -1)
                    dBFileName = strRecordClass;  // Default file name (unless mapped)

                if ((dBFileName != null) && (dBFileName.length() > 0))
                    if (!this.readThisMethod("getTableNames"))
                {
                	this.writeMethodInterface(null, "getTableNames", "String", "boolean bAddQuotes", "", "Get the table name.", null);
                	m_StreamOut.writeit("\treturn (m_tableName == null) ? Record.formatTableNames(" + this.convertNameToConstant(strRecordClass + "File") + ", bAddQuotes) : super.getTableNames(bAddQuotes);\n}\n");
                }

                String recordName = recFileHdr.getField(FileHdr.FILE_REC_CALLED).getString();    // Description of a record
                String databaseName = recFileHdr.getField(FileHdr.DATABASE_NAME).getString(); // Database name
                String strDBType = recFileHdr.getField(FileHdr.TYPE).getString(); // Is Remote file?
                if (recordName.length() != 0)   // Valid Name
                {
                    if (!this.readThisMethod("getRecordName"))
                    {
                    	this.writeMethodInterface(null, "getRecordName", "String", "void", "", "Get the name of a single record.", null);
                    	m_StreamOut.writeit("\treturn \"" + recordName + "\";\n}\n");
                    }
                }
                if (databaseName.length() > 0)
                {   // If you don't supply a database name, you better supply your own method (See DatabaseInfo).
                    if (!this.readThisMethod("getDatabaseName"))
                    {
                    	this.writeMethodInterface(null, "getDatabaseName", "String", "void", "", "Get the Database Name.", null);
                    	m_StreamOut.writeit("\treturn \"" + databaseName + "\";\n}\n");
                    }
                }
                if (strDBType.length() > 0)
                {
                    if (!this.readThisMethod("getDatabaseType"))
                    {
                    	this.writeMethodInterface(null, "getDatabaseType", "int", "void", "", "Is this a local (vs remote) file?", null);
                    	strDBType = this.fixDBType(strDBType, "DBConstants.");
                    	m_StreamOut.writeit("\treturn " + strDBType + ";\n}\n");
                    }
                }
                this.writeFileMakeViews();
            }
            else
                if (recClassInfo.getField(ClassInfo.CLASS_TYPE).getString().equalsIgnoreCase("Record"))
                    m_StreamOut.writeit("\npublic static final String " + this.convertNameToConstant(strRecordClass + "File") + " = null;\t// Screen field\n");    // Screen fields
                    

            this.writeSetupField();
            this.readRecordClass(strRecordClass); // Must re-read this record class

            if (bFileType) // Is there a file with this name?
                this.writeSetupKey(CodeType.THICK, true);
            this.writeClassMethods(CodeType.THICK);       // Write the remaining methods
            this.writeEndCode(true);
        } catch (DBException ex)   {
            ex.printStackTrace();
        }
    }
1088940
static void handleWriteToChunk(ByteChannel sock, AutoBuffer ab) throws IOException {
        String frameKey = ab.getStr();
        byte[] expectedTypes = ab.getA1();
        if( expectedTypes == null){
          throw new RuntimeException("Expected types can't be null.");
        }
        int[] maxVecSizes = ab.getA4();

        int[] elemSizes = ExternalFrameUtils.getElemSizes(expectedTypes, maxVecSizes != null ? maxVecSizes : EMPTY_ARI);
        int[] startPos = ExternalFrameUtils.getStartPositions(elemSizes);
        byte[] vecTypes = vecTypesFromExpectedTypes(expectedTypes, maxVecSizes != null ? maxVecSizes : EMPTY_ARI);
        int expectedNumRows = ab.getInt();
        int currentRowIdx = 0;
        int chunk_id = ab.getInt();
        NewChunk[] nchnk = ChunkUtils.createNewChunks(frameKey, vecTypes, chunk_id);
        assert nchnk != null;
        while (currentRowIdx < expectedNumRows) {
            for(int typeIdx = 0; typeIdx < expectedTypes.length; typeIdx++){
                switch (expectedTypes[typeIdx]) {
                    case EXPECTED_BOOL: // fall through to byte since BOOL is internally stored in frame as number (byte)
                    case EXPECTED_BYTE:
                        store(ab, nchnk[startPos[typeIdx]], ab.get1());
                        break;
                    case EXPECTED_CHAR:
                        store(ab, nchnk[startPos[typeIdx]], ab.get2());
                        break;
                    case EXPECTED_SHORT:
                        store(ab, nchnk[startPos[typeIdx]], ab.get2s());
                        break;
                    case EXPECTED_INT:
                        store(ab, nchnk[startPos[typeIdx]], ab.getInt());
                        break;
                    case EXPECTED_TIMESTAMP: // fall through to long since TIMESTAMP is internally stored in frame as long
                    case EXPECTED_LONG:
                        store(ab, nchnk[startPos[typeIdx]], ab.get8());
                        break;
                    case EXPECTED_FLOAT:
                        store(nchnk[startPos[typeIdx]], ab.get4f());
                        break;
                    case EXPECTED_DOUBLE:
                        store(nchnk[startPos[typeIdx]], ab.get8d());
                        break;
                    case EXPECTED_STRING:
                        store(ab, nchnk[startPos[typeIdx]], ab.getStr());
                        break;
                    case EXPECTED_VECTOR:
                        storeVector(ab, nchnk, elemSizes[typeIdx], startPos[typeIdx]);
                        break;
                    default:
                        throw new IllegalArgumentException("Unknown expected type: " + expectedTypes[typeIdx]);
                }
            }
            currentRowIdx++;
        }
        // close chunks at the end
        ChunkUtils.closeNewChunks(nchnk);

        // Flag informing sender that all work is done and
        // chunks are ready to be finalized.
        //
        // This also needs to be sent because in the sender we have to
        // wait for all chunks to be written to DKV; otherwise we get race during finalizing and
        // it happens that we try to finalize frame with chunks not ready yet
        AutoBuffer outputAb = new AutoBuffer();
        outputAb.put1(ExternalFrameHandler.CONFIRM_WRITING_DONE);
        writeToChannel(outputAb, sock);
    }
1354076
@Override
   public void writeClassBody(Definition def, Writer out) throws IOException
   {

      out.write("public class " + getClassName(def) + " implements " +
            def.getMcfDefs().get(getNumOfMcf()).getConnInterfaceClass());
      writeLeftCurlyBracket(out, 0);
      int indent = 1;
      writeWithIndent(out, indent, "/** The logger */\n");
      writeWithIndent(out, indent, "private static Logger log = Logger.getLogger(" + getSelfClassName(def) + ");\n\n");

      writeWithIndent(out, indent, "/** ManagedConnection */\n");
      writeWithIndent(out, indent, "private " + def.getMcfDefs().get(getNumOfMcf()).getMcClass() + " mc;\n\n");

      writeWithIndent(out, indent, "/** ManagedConnectionFactory */\n");
      writeWithIndent(out, indent, "private " + def.getMcfDefs().get(getNumOfMcf()).getMcfClass() + " mcf;\n\n");

      //constructor
      writeWithIndent(out, indent, "/**\n");
      writeWithIndent(out, indent, " * Default constructor\n");
      writeWithIndent(out, indent, " * @param mc " + def.getMcfDefs().get(getNumOfMcf()).getMcClass());
      writeEol(out);
      writeWithIndent(out, indent, " * @param mcf " + def.getMcfDefs().get(getNumOfMcf()).getMcfClass());
      writeEol(out);
      writeWithIndent(out, indent, " */\n");

      writeWithIndent(out, indent, "public " + getClassName(def) + "(" +
            def.getMcfDefs().get(getNumOfMcf()).getMcClass() + " mc, " +
            def.getMcfDefs().get(getNumOfMcf()).getMcfClass() + " mcf)");
      writeLeftCurlyBracket(out, indent);
      writeWithIndent(out, indent + 1, "this.mc = mc;\n");
      writeWithIndent(out, indent + 1, "this.mcf = mcf;");
      writeRightCurlyBracket(out, indent);
      writeEol(out);

      writeMethod(def, out, indent);
      writeRightCurlyBracket(out, 0);
   }
221132
def decode_header(cls, stream):
        
        read = stream.read
        data = read(2)
        if len(data) != 2:
            raise WebSocketError("Unexpected EOF while decoding header")
        first_byte, second_byte = struct.unpack('!BB', data)
        header = cls(
            fin=first_byte & cls.FIN_MASK == cls.FIN_MASK,
            opcode=first_byte & cls.OPCODE_MASK,
            flags=first_byte & cls.HEADER_FLAG_MASK,
            length=second_byte & cls.LENGTH_MASK)
        has_mask = second_byte & cls.MASK_MASK == cls.MASK_MASK
        if header.opcode > 0x07:
            if not header.fin:
                raise WebSocketError('Received fragmented control frame: {0!r}'.format(data))
            # Control frames MUST have a payload length of 125 bytes or less
            if header.length > 125:
                raise FrameTooLargeException('Control frame cannot be larger than 125 bytes: {0!r}'.format(data))
        if header.length == 126:
            # 16 bit length
            data = read(2)
            if len(data) != 2:
                raise WebSocketError('Unexpected EOF while decoding header')
            header.length = struct.unpack('!H', data)[0]
        elif header.length == 127:
            # 64 bit length
            data = read(8)
            if len(data) != 8:
                raise WebSocketError('Unexpected EOF while decoding header')
            header.length = struct.unpack('!Q', data)[0]
        if has_mask:
            mask = read(4)
            if len(mask) != 4:
                raise WebSocketError('Unexpected EOF while decoding header')
            header.mask = mask
        return header
926732
def pack_into(self, buf, offset, write_payload):
    
    return self._get_framed(buf, offset, write_payload)
622553
def process_frame(self):
        
        input_name = self.inputs[0]
        output_name = self.outputs[0]
        in_frame = self.input_buffer[input_name].get()
        out_frame = self.outframe_pool[output_name].get()
        out_frame.initialise(in_frame)
        if self.transform(in_frame, out_frame):
            self.send(output_name, out_frame)
        else:
            raise StopIteration()
840514
function headers(buffer) {
    var head = {};
    if (buffer[0] === 0x89 && buffer[1] === 0x50 && buffer[2] === 0x4E &&
        buffer[3] === 0x47 && buffer[4] === 0x0D && buffer[5] === 0x0A &&
        buffer[6] === 0x1A && buffer[7] === 0x0A) {
        head['Content-Type'] = 'image/png';
    } else if (buffer[0] === 0xFF && buffer[1] === 0xD8 &&
        buffer[buffer.length - 2] === 0xFF && buffer[buffer.length - 1] === 0xD9) {
        head['Content-Type'] = 'image/jpeg';
    } else if (buffer[0] === 0x47 && buffer[1] === 0x49 && buffer[2] === 0x46 &&
        buffer[3] === 0x38 && (buffer[4] === 0x39 || buffer[4] === 0x37) &&
        buffer[5] === 0x61) {
        head['Content-Type'] = 'image/gif';
    } else if (buffer[0] === 0x52 && buffer[1] === 0x49 && buffer[2] === 0x46 && buffer[3] === 0x46 &&
        buffer[8] === 0x57 && buffer[9] === 0x45 && buffer[10] === 0x42 && buffer[11] === 0x50) {
        head['Content-Type'] = 'image/webp';
    // deflate: recklessly assumes contents are PBF.
    } else if (buffer[0] === 0x78 && buffer[1] === 0x9C) {
        head['Content-Type'] = 'application/x-protobuf';
        head['Content-Encoding'] = 'deflate';
    // gzip: recklessly assumes contents are PBF.
    } else if (buffer[0] === 0x1F && buffer[1] === 0x8B) {
        head['Content-Type'] = 'application/x-protobuf';
        head['Content-Encoding'] = 'gzip';
    }
    return head;
}
783527
def from_frame(klass, frame, connection):
        
        event = frame.headers['new']
        data = json.loads(frame.body)
        info = data['info']
        build = Build.fromDict(info)
        build.connection = connection
        return klass(build, event)
27649
@Override
   public void writeClassBody(Definition def, Writer out) throws IOException
   {
      int indent = 1;
      out.write("public interface " + getClassName(def));
      writeLeftCurlyBracket(out, 0);
      writeWithIndent(out, indent, "/**\n");
      writeWithIndent(out, indent, " * Receive message\n");
      writeWithIndent(out, indent, " * @param msg String.\n");
      writeWithIndent(out, indent, " */\n");

      writeWithIndent(out, indent, "public void onMessage(String msg);");

      writeRightCurlyBracket(out, 0);
   }
942804
private ByteBuf writeResponse(ByteBuf buffer, Object request, ThreadContext context) {
    context.serializer().writeObject(request, OUTPUT.get().setByteBuf(buffer));
    return buffer;
  }
997125
def buffer(self, frame):
        """"""
        frame.buffer = self.temporary_identifier()
        self.writeline('%s = []' % frame.buffer)
976214
def _read_frame(cls, reader):
        '''
        
        '''
        frame_type = reader.read_octet()
        channel_id = reader.read_short()
        size = reader.read_long()

        payload = Reader(reader, reader.tell(), size)

        # Seek to end of payload
        reader.seek(size, 1)

        ch = reader.read_octet()  # footer
        if ch != 0xce:
            raise Frame.FormatError(
                'Framing error, unexpected byte: %x.  frame type %x. channel %d, payload size %d',
                ch, frame_type, channel_id, size)

        frame_class = cls._frame_type_map.get(frame_type)
        if not frame_class:
            raise Frame.InvalidFrameType("Unknown frame type %x", frame_type)
        return frame_class.parse(channel_id, payload)
594907
function sendFrame(socket, _frame) {
  var frame = _frame;

  if (!_frame.hasOwnProperty('toString')) {
    frame = new Frame({
      'command': _frame.command,
      'headers': _frame.headers,
      'body': _frame.body
    });
  }

  socket.send(frame.toStringOrBuffer());
  return true;
}
866759
def __read_frame(self):
        

        if self.__frame_header_cache is None:
            _logger.debug("Reading frame header.")
            (length, frame_type) = struct.unpack('!II', self.__read(8))
            self.__frame_header_cache = (length, frame_type)
        else:
            (length, frame_type) = self.__frame_header_cache

        try:
            data = self.__read(length - 4)
        except errno.EAGAIN:
            self.__frame_header_cache = (length, frame_type)
            raise

        self.__frame_header_cache = None
        self.__process_message(frame_type, data)
99334
private void getHeadersFromFrame() {
        byte[] hbf = null;
        if (currentFrame.getFrameType() == FrameTypes.HEADERS || currentFrame.getFrameType() == FrameTypes.PUSHPROMISEHEADERS) {
            hbf = ((FrameHeaders) currentFrame).getHeaderBlockFragment();
        } else if (currentFrame.getFrameType() == FrameTypes.CONTINUATION) {
            hbf = ((FrameContinuation) currentFrame).getHeaderBlockFragment();
        }

        if (hbf != null) {
            if (headerBlock == null) {
                headerBlock = new ArrayList<byte[]>();
            }
            headerBlock.add(hbf);
        }
    }