protected void encode(ByteSequencesWriter writer,ByteArrayDataOutput output,byte[] buffer,BytesRef spare,BytesRef payload,Set<BytesRef> contexts,long weight) throws IOException {
  int requiredLength=spare.length + 8 + ((hasPayloads) ? 2 + payload.length : 0);
  if (hasContexts) {
    for (    BytesRef ctx : contexts) {
      requiredLength+=2 + ctx.length;
    }
    requiredLength+=2;
  }
  if (requiredLength >= buffer.length) {
    buffer=ArrayUtil.grow(buffer,requiredLength);
  }
  output.reset(buffer);
  output.writeBytes(spare.bytes,spare.offset,spare.length);
  if (hasContexts) {
    for (    BytesRef ctx : contexts) {
      output.writeBytes(ctx.bytes,ctx.offset,ctx.length);
      output.writeShort((short)ctx.length);
    }
    output.writeShort((short)contexts.size());
  }
  if (hasPayloads) {
    output.writeBytes(payload.bytes,payload.offset,payload.length);
    output.writeShort((short)payload.length);
  }
  output.writeLong(weight);
  writer.write(buffer,0,output.getPosition());
}

protected void encode ( ByteSequencesWriter writer , ByteArrayDataOutput output , byte [ ] buffer , BytesRef spare , BytesRef payload , Set < BytesRef > contexts , long weight ) throws IOException { int requiredLength = spare . length + 8 + ( ( hasPayloads ) ? 2 + payload . length : 0 ) ; if ( hasContexts ) { for ( BytesRef ctx : contexts ) { requiredLength += 2 + ctx . length ; } requiredLength += 2 ; } if ( requiredLength >= buffer . length ) { buffer = ArrayUtil . grow ( buffer , requiredLength ) ; } output . reset ( buffer ) ; output . writeBytes ( spare . bytes , spare . offset , spare . length ) ; if ( hasContexts ) { for ( BytesRef ctx : contexts ) { output . writeBytes ( ctx . bytes , ctx . offset , ctx . length ) ; output . writeShort ( ( short ) ctx . length ) ; } output . writeShort ( ( short ) contexts . size ( ) ) ; } if ( hasPayloads ) { output . writeBytes ( payload . bytes , payload . offset , payload . length ) ; output . writeShort ( ( short ) payload . length ) ; } output . writeLong ( weight ) ; writer . write ( buffer , 0 , output . getPosition ( ) ) ; }
encodes an entry ( bytes + ( contexts ) + ( payload ) + weight ) to the provided writer
