I have a byte array, for example:
(def g (byte-array (map byte [0 1 2 3])))
How do I get the size of it and how do I prepend this size to the g byte array?
The prepending part can be done like this (probably not the best solution):
(def g (byte-array (apply #(cons (byte (count %)) %) [(map byte [0 1 2 3])])))
It returns:
[4, 0, 1, 2, 3]
I think that you should use (alength g) for the length of a Java array.
Of course if your byte array is longer than 255 you will have problems with adding the length as a single byte.
Not sure what you mean about prepending the size, but you can get the size using count
user=> (def g (byte-array (map byte [0 1 2 3])))
#'user/g
user=> (count g)
4