EncodeInt() public static method

public static EncodeInt ( int payload ) : byte[]
payload int
return byte[]
 public override sealed bool IncrementToken()
 {
     if (input.IncrementToken())
     {
         byte[] data = new byte[8];
         PayloadHelper.EncodeInt(offsetAtt.StartOffset(), data, 0);
         PayloadHelper.EncodeInt(offsetAtt.EndOffset(), data, 4);
         BytesRef payload = new BytesRef(data);
         payAtt.Payload = payload;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #2
0
        public virtual void TestIntEncoding()
        {
            string test = "The quick|1 red|2 fox|3 jumped over the lazy|5 brown|99 dogs|83";
            DelimitedPayloadTokenFilter filter  = new DelimitedPayloadTokenFilter(new MockTokenizer(new StringReader(test), MockTokenizer.WHITESPACE, false), '|', new IntegerEncoder());
            ICharTermAttribute          termAtt = filter.GetAttribute <ICharTermAttribute>();
            IPayloadAttribute           payAtt  = filter.GetAttribute <IPayloadAttribute>();

            filter.Reset();
            AssertTermEquals("The", filter, termAtt, payAtt, null);
            AssertTermEquals("quick", filter, termAtt, payAtt, PayloadHelper.EncodeInt(1));
            AssertTermEquals("red", filter, termAtt, payAtt, PayloadHelper.EncodeInt(2));
            AssertTermEquals("fox", filter, termAtt, payAtt, PayloadHelper.EncodeInt(3));
            AssertTermEquals("jumped", filter, termAtt, payAtt, null);
            AssertTermEquals("over", filter, termAtt, payAtt, null);
            AssertTermEquals("the", filter, termAtt, payAtt, null);
            AssertTermEquals("lazy", filter, termAtt, payAtt, PayloadHelper.EncodeInt(5));
            AssertTermEquals("brown", filter, termAtt, payAtt, PayloadHelper.EncodeInt(99));
            AssertTermEquals("dogs", filter, termAtt, payAtt, PayloadHelper.EncodeInt(83));
            assertFalse(filter.IncrementToken());
            filter.End();
            filter.Dispose();
        }