java - how to refer part of an array? -


given object byte[], when want operate such object need pieces of it. in particular example byte[] wire first 4 bytes describe lenght of message 4 bytes type of message (an integer maps concrete protobuf class) remaining byte[] actual content of message... this

length|type|content 

in order parse message have pass content part specific class knows how parse instance it... problem there no methods provided specify where parser shall read array...

so end doing copying remaining chuks of array, not effective...

as far know in java not possible create byte[] reference refers original bigger byte[] array 2 indexes (this approach string led memory leaks)...

i wonder how solve situations this? suppose giving on protobuf because not provide parsefrom(byte[], int, int) not make sence... protobuf example, lack api...

so force write inefficient code or there can done? (appart adding method)...

in java, array not section of memory - object, have additional fields (at least - length). cannot link part of array - should:

  • use array-copy functions or
  • implement , use algorithm uses part of byte array.

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -