void InitializePayloadHandlers() { payloadHandlers = new Dictionary <GatewayOPCode, PayloadCallback>(); Type taskType = typeof(Task); Type gatewaySocketType = typeof(GatewaySocket); Type payloadSynchronousType = typeof(PayloadSynchronousCallback); Type payloadAsynchronousType = typeof(PayloadAsynchronousCallback); foreach (MethodInfo method in gatewaySocketType.GetTypeInfo().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)) { PayloadAttribute attr = method.GetCustomAttribute <PayloadAttribute>(); if (attr != null) { PayloadCallback payloadCallback; if (method.ReturnType == taskType) { Delegate callback = method.CreateDelegate(payloadAsynchronousType, this); payloadCallback = new PayloadCallback((PayloadAsynchronousCallback)callback); } else { Delegate callback = method.CreateDelegate(payloadSynchronousType, this); payloadCallback = new PayloadCallback((PayloadSynchronousCallback)callback); } payloadHandlers[attr.OPCode] = payloadCallback; } } }
public BoostingTokenFilter(TokenStream input, int[] startOffsets, float[] boosts) : base(input) { _startOffsets = startOffsets; _boosts = boosts; _offsetAttr = (OffsetAttribute)base.addAttribute(typeof(OffsetAttribute)); _payloadAttr = (PayloadAttribute)base.addAttribute(typeof(PayloadAttribute)); }
public PayloadSetter(TokenStream input) : base(input) { if (!InstanceFieldsInitialized) { InitializeInstanceFields(); InstanceFieldsInitialized = true; } payloadAtt = addAttribute(typeof(PayloadAttribute)); }
public SectionTokenStream(TokenStream tokenStream, int sectionId) : base(tokenStream) { // NOTE: Calling the AddAttribute<T> method failed, so // switched to using AddAttributeImpl. _payloadAtt = new PayloadAttribute(); AddAttributeImpl(_payloadAtt); _payload = EncodeIntPayload(sectionId); }
public IntMetaDataTokenStream(string tokenText) { _tokenText = tokenText; // NOTE: Calling the AddAttribute<T> method failed, so // switched to using AddAttributeImpl. _termAttribute = new TermAttribute(); _offsetAttribute = new OffsetAttribute(); _payloadAtt = new PayloadAttribute(); base.AddAttributeImpl(_termAttribute); base.AddAttributeImpl(_offsetAttribute); base.AddAttributeImpl(_payloadAtt); }
void InitializePayloadHandlers() { payloadHandlers = new Dictionary <VoiceOPCode, PayloadCallback>(); Type gatewayType = typeof(VoiceWebSocket); Type payloadType = typeof(PayloadCallback); foreach (MethodInfo method in gatewayType.GetTypeInfo().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)) { PayloadAttribute attr = method.GetCustomAttribute <PayloadAttribute>(); if (attr != null) { payloadHandlers[attr.OPCode] = (PayloadCallback)method.CreateDelegate(payloadType, this); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: void verifyPayload(TokenStream ts) throws java.io.IOException internal virtual void verifyPayload(TokenStream ts) { PayloadAttribute payloadAtt = ts.getAttribute(typeof(PayloadAttribute)); ts.reset(); for (sbyte b = 1;; b++) { bool hasNext = ts.incrementToken(); if (!hasNext) { break; } // System.out.println("id="+System.identityHashCode(nextToken) + " " + t); // System.out.println("payload=" + (int)nextToken.getPayload().toByteArray()[0]); assertEquals(b, payloadAtt.Payload.bytes[0]); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void testFilterTokens() throws Exception public virtual void testFilterTokens() { SnowballFilter filter = new SnowballFilter(new TestTokenStream(this), "English"); CharTermAttribute termAtt = filter.getAttribute(typeof(CharTermAttribute)); OffsetAttribute offsetAtt = filter.getAttribute(typeof(OffsetAttribute)); TypeAttribute typeAtt = filter.getAttribute(typeof(TypeAttribute)); PayloadAttribute payloadAtt = filter.getAttribute(typeof(PayloadAttribute)); PositionIncrementAttribute posIncAtt = filter.getAttribute(typeof(PositionIncrementAttribute)); FlagsAttribute flagsAtt = filter.getAttribute(typeof(FlagsAttribute)); filter.incrementToken(); assertEquals("accent", termAtt.ToString()); assertEquals(2, offsetAtt.startOffset()); assertEquals(7, offsetAtt.endOffset()); assertEquals("wrd", typeAtt.type()); assertEquals(3, posIncAtt.PositionIncrement); assertEquals(77, flagsAtt.Flags); assertEquals(new BytesRef(new sbyte[] { 0, 1, 2, 3 }), payloadAtt.Payload); }
private static void ConsumeStreamNewAPI(TokenStream stream) { stream.Reset(); PayloadAttribute payloadAtt = (PayloadAttribute)stream.AddAttribute(typeof(PayloadAttribute)); TermAttribute termAtt = (TermAttribute)stream.AddAttribute(typeof(TermAttribute)); int i = 0; while (stream.IncrementToken()) { System.String term = termAtt.Term(); Payload p = payloadAtt.GetPayload(); if (p != null && p.GetData().Length == 1 && p.GetData()[0] == PartOfSpeechAnnotatingFilter.PROPER_NOUN_ANNOTATION) { Assert.IsTrue("tokenstream".Equals(term), "only TokenStream is a proper noun"); } else { Assert.IsFalse("tokenstream".Equals(term), "all other tokens (if this test fails, the special POSToken subclass is not correctly passed through the chain)"); } Assert.AreEqual(results[i], term); i++; } }
public void ReadWrite(BitcoinStream stream) { if ((this.Payload == null) && stream.Serializing) { throw new InvalidOperationException("Payload not affected"); } if (stream.Serializing || (!stream.Serializing && !this.skipMagic)) { stream.ReadWrite(ref this.magic); } stream.ReadWrite(ref this.command); int length = 0; uint checksum = 0; bool hasChecksum = false; byte[] payloadBytes = stream.Serializing ? this.GetPayloadBytes(stream.ProtocolVersion, out length) : null; length = payloadBytes == null ? 0 : length; stream.ReadWrite(ref length); if (stream.ProtocolVersion >= ProtocolVersion.MEMPOOL_GD_VERSION) { if (stream.Serializing) { checksum = Hashes.Hash256(payloadBytes, 0, length).GetLow32(); } stream.ReadWrite(ref checksum); hasChecksum = true; } if (stream.Serializing) { stream.ReadWrite(ref payloadBytes, 0, length); } else { // MAX_SIZE 0x02000000 Serialize.h. if (length > 0x02000000) { throw new FormatException("Message payload too big ( > 0x02000000 bytes)"); } payloadBytes = (this.buffer == null) || (this.buffer.Length < length) ? new byte[length] : this.buffer; stream.ReadWrite(ref payloadBytes, 0, length); if (hasChecksum) { if (!VerifyChecksum(checksum, payloadBytes, length)) { if (NodeServerTrace.Trace.Switch.ShouldTrace(TraceEventType.Verbose)) { NodeServerTrace.Trace.TraceEvent(TraceEventType.Verbose, 0, "Invalid message checksum bytes"); } throw new FormatException("Message checksum invalid"); } } BitcoinStream payloadStream = new BitcoinStream(payloadBytes); payloadStream.CopyParameters(stream); Type payloadType = PayloadAttribute.GetCommandType(this.Command); bool unknown = payloadType == typeof(UnknowPayload); if (unknown) { NodeServerTrace.Trace.TraceEvent(TraceEventType.Warning, 0, "Unknown command received : " + this.Command); } object payload = this.payloadObject; payloadStream.ReadWrite(payloadType, ref payload); if (unknown) { ((UnknowPayload)payload).command = this.Command; } this.Payload = (Payload)payload; } }
public override void CopyTo(AttributeImpl target) { PayloadAttribute t = (PayloadAttribute)target; t.SetPayload((payload == null)?null:(Payload)payload.Clone()); }