last day (14 days later) » 

2:10 AM
hey
 
Hey David
 
So I will go with first way as you suggested
byte[] b = new byte[data_record_value.remaining()];
record_value.get(b);

// this will be in bytes right?
System.out.println("Byte Array Length: " + b.length);
 
That's fine. If you need the amount more often then you could store the return value of remaining() in an int variable of course.
 
Is there any way I can cross check total bytes I get from my first way by comparing with unpacking individual fields from data_record_value?
Just to make sure they both are same?
 
int returned = data_record_value.remaining();
new byte[returned]; etc.
If you have got a length encoded in there, sure.
 
2:14 AM
yeah I was saying about this
// clientId (of two bytes by using short)
short extractClientId = data_record_value.getShort();

// lastModifiedDate ( of 8 bytes which can be long )
long extractLastModifiedDate = data_record_value.getLong();

int extractAvroBinaryValueLength = data_record_value.getInt();

byte[] extractAvroBinaryValue = new byte[extractAvroBinaryValueLength];

bb.get(extractAvroBinaryValue); // read attributeValue from the remaining buffer
Bcoz my data_record_value is made up of this
Offset   Length (in bytes)          Purpose

0           2                       - clientId byte array
2           8                       - value of lastModifiedDate
2+8         4                       - length of avroBinaryValue array
2+8+4       Y                       - avroBinaryValue array
so any way to extract individual fields and calculate the total bytes and then compare with what data_record_value.remaining(); is returning? And see whether they both are same?
 
Yeah, so avroBinaryValue should be 14 bytes less than the size of the data returned.
That's a fine check to make, if there is any reason to mistrust the output. Never hurts to check I guess.
I mean, performance is not an issue for such a check, so why not.
One catch: I presume avroBinaryValue cannot contain a value equal or higher than 0x80000000....
Never mind, the buffer cannot hold that much ... sorry, getting late
Hey, I'm off to bed, unless you've any other questions?
 
yeah one last question
so how will I do the comparsion
silly question I guess
ByteBuffer data_record_value = r.getBytes("data_record_value");

byte[] b = new byte[data_record_value.remaining()];
record_value.get(b);

System.out.println("Byte Array Length: " + b.length);

// clientId (of two bytes by using short)
short extractSchemaId = data_record_value.getShort();

// lastModifiedDate ( of 8 bytes which can be long )
long extractLastModifiedDate = data_record_value.getLong();

int extractAvroBinaryValueLength = data_record_value.getInt();

byte[] extractAvroBinaryValue = new byte[extractAvroBinaryValueLength];
something like this?
so that means extractAvroBinaryValue.length should be same as b.length?
 
if (avroBinaryVallueLength != b.length - 14) { // do something horrible }
 
sure
 
Note that I would name my variables differently...
 
2:21 AM
yeah makes sense
but the code above I have is correct?
that's what I wanted to make sure
 
Looks like it at first glance. If you're unsure: codereview.stackexchange.com
Just a second...
Nope, wait, you first get all the bytes in b and then continue reading....
That's not right....
 
hmmm that's what I thought
 
You don't need to use b at all...
Just store data_record_value.remaining() in an int as suggested.
 
okk
 
If you need all the bytes for a record separately, use mark(), get b, reset() and start getting again.
Or use an absolute get()
 
2:27 AM
ByteBuffer data_record_value = r.getBytes("data_record_value");

int returned = data_record_value.remaining();

// clientId (of two bytes by using short)
short extractClientId = data_record_value.getShort();

// lastModifiedDate ( of 8 bytes which can be long )
long extractLastModifiedDate = data_record_value.getLong();

int extractAvroBinaryValueLength = data_record_value.getInt();

byte[] extractAvroBinaryValue = new byte[extractAvroBinaryValueLength];

data_record_value.get(extractAvroBinaryValue); // read attributeValue from the remaining buffer
so this should work now I guess
I can compare returned with extractAvroBinaryValue.length
 
Yep, it will probably differ 2 + 8 + 4 = 14 bytes.
 
Also, can you explain why it will differ 14 bytes?
I know what is 2, 8 and 4 here
but why it should differ 14 bytes
 
The size of the header ?
0 2 - clientId byte array
2 8 - value of lastModifiedDate
2+8 4 - length of avroBinaryValue array
2+8+4 Y - avroBinaryValue array
 
but my data_record_value is made up of all the above fields
 
avroBinaryValue does not incldue cleintID, the date and the length itself
 
2:30 AM
yeah it differs by 14 bytes when I ran the code
 
It reads: "length of avroBinaryValue array", not "length of data_record_value".
 
understood now
 
This form of encoding is called length | value.
 
sure got it now
 
OK, now I'm really off to bed, it's rather late here, almost early.
 
2:32 AM
sure thanks for the help Maarten. Appreciated your help.
 
You;re welcome, over & out
 

last day (14 days later) »