Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public byte[] encodeDataFields(List<FieldDefinition> fieldDefinitions, Map<String, Object> fieldValues) {
- // TODO Exercise 3 add code here
- ArrayList<byte[]> turboGazariOOD = new ArrayList<byte[]>();
- for(int i=0; i<fieldDefinitions.size(); i++) {
- if(fieldDefinitions.get(i).getType().getByteLength()!=-1) {
- ByteBuffer byteBuffer = ByteBuffer.allocate(fieldDefinitions.get(i).getType().getByteLength());
- Object currentFieldValue = fieldValues.get(fieldDefinitions.get(i).getName());
- switch(fieldDefinitions.get(i).getType()) {
- case Byte:
- turboGazariOOD.add(byteBuffer.put((byte) currentFieldValue).array());
- break;
- case Short:
- turboGazariOOD.add(byteBuffer.putShort((short) currentFieldValue).array());
- break;
- case Int:
- turboGazariOOD.add(byteBuffer.putInt((int) currentFieldValue).array());
- break;
- case Long:
- turboGazariOOD.add(byteBuffer.putLong((long) currentFieldValue).array());
- break;
- case Float:
- turboGazariOOD.add(byteBuffer.putFloat((float) currentFieldValue).array());
- break;
- case Double:
- turboGazariOOD.add(byteBuffer.putDouble((double) currentFieldValue).array());
- break;
- }
- }
- }
- int length = 0;
- for(byte[] b : turboGazariOOD) length+=b.length;
- if(length!=0)
- {
- byte[] masivche = new byte[length];
- int counter = 0;
- for(byte[] b : turboGazariOOD) {
- for(int i=0; i<b.length; i++) {
- masivche[counter++] = b[i];
- }
- }
- return masivche;
- }
- else
- {
- return null;
- }
- }
Add Comment
Please, Sign In to add comment