// Path: src/main/java/jmockmongo/wire/MessageDecoder.java
// static final int readInt32(ChannelBuffer buffer, byte[] fourBytes) {
// 	buffer.readBytes(fourBytes);
// 	return Bits.readInt(fourBytes);
// }


import static jmockmongo.wire.MessageDecoder.readInt32;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
/**
 * Copyright (c) 2012, Thilo Planz. All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the Apache License, Version 2.0
 * as published by the Apache Software Foundation (the "License").
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 * You should have received a copy of the License along with this program.
 * If not, see <http://www.apache.org/licenses/LICENSE-2.0>.
 */

package jmockmongo.wire;



abstract class Message {

	// struct MsgHeader {
	// int32 messageLength; // total message size, including this
	// int32 requestID; // identifier for this message
	// int32 responseTo; // requestID from the original request
	// // (used in reponses from db)
	// int32 opCode; // request type - see table below
	// }

	private final int messageLength;

	private final int requestId;

	private final int responseTo;

	protected final int opCode;

	protected final ChannelBuffer data;

	Message(ChannelBuffer data, int expectedOpCode) {
		byte[] fourBytes = new byte[4];

		int check = data.readableBytes();
// Path: src/main/java/jmockmongo/wire/MessageDecoder.java
// static final int readInt32(ChannelBuffer buffer, byte[] fourBytes) {
// 	buffer.readBytes(fourBytes);
// 	return Bits.readInt(fourBytes);
// }


// Path: src/main/java/jmockmongo/wire/Message.java
import static jmockmongo.wire.MessageDecoder.readInt32;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;

/**
 * Copyright (c) 2012, Thilo Planz. All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the Apache License, Version 2.0
 * as published by the Apache Software Foundation (the "License").
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 * You should have received a copy of the License along with this program.
 * If not, see <http://www.apache.org/licenses/LICENSE-2.0>.
 */

package jmockmongo.wire;



abstract class Message {

	// struct MsgHeader {
	// int32 messageLength; // total message size, including this
	// int32 requestID; // identifier for this message
	// int32 responseTo; // requestID from the original request
	// // (used in reponses from db)
	// int32 opCode; // request type - see table below
	// }

	private final int messageLength;

	private final int requestId;

	private final int responseTo;

	protected final int opCode;

	protected final ChannelBuffer data;

	Message(ChannelBuffer data, int expectedOpCode) {
		byte[] fourBytes = new byte[4];

		int check = data.readableBytes();
		this.messageLength = readInt32(data, fourBytes);