Microsoft Interview Question
Software Engineer / DevelopersMy guess is this was part of the phone/email screen and the candidate was given enough time to code this up. I say this mostly because of the line: "Pls include a paragraph of how you will test this" and the fact the we seem to have a complete writeup from the original poster in which the question makes sense!
btw, it looks intimidating, but it actually isn't. You only have to implement one method. Try it.
I don't agree with hatethisone. I think this is a nice question. You are actually being tested on how you will be writing real code, not just some handwaving pseudo code.
Hi All,
the solution can be::::::
HRESULT ProcessData(PBYTE pDataBuffer, IN ULONG cbBufferSize)//
typedef struct tag_HEADER
{
ULONG cbTotalPacketLen;
ULONG cbThisChunkLen;
#define FLAG_FIRST_CHUNK_IN_PACKET 1
#define FLAG_LAST_CHUNK_IN_PACKET 2
ULONG flags;
} CHUNK_HEADER;
HRESULT ProcessData(PBYTE pDataBuffer, IN ULONG cbBufferSize) {
CHUNK_HEADER *header = (CHUNK_HEADER *) malloc(sizeof(CHUNK_HEADER));
static PBYTE *packet;
static int length;
header = (CHUNK_HEADER *)pDataBuffer;
if (header->flags == FLAG_FIRST_CHUNK_IN_PACKET) {
packet = NULL;
packet = (char *) malloc(header->cbTotalPacketLen);
length = header->cbThisChunkLen;
}
elseif(header->flags == FLAG_LAST_CHUNK_IN_PACKET) {
memcpy(packet+length, pDataBuffer+sizeof(CHUNK_HEADER), header->cbThisChunkLen);
ProcessPacket(packet);
packet = NULL;
length = 0;
}
else {
memcpy(packet+length, pDataBuffer+sizeof(CHUNK_HEADER), header->cbThisChunkLen);
}
}
I'd better not try Microsoft
- karate August 11, 2009