Akka.Remote.Transport.AkkaPduProtobuffCodec.DecodePdu C# (CSharp) Method

DecodePdu() public method

public DecodePdu ( ByteString raw ) : IAkkaPdu
raw ByteString
return IAkkaPdu
        public override IAkkaPdu DecodePdu(ByteString raw)
        {
            try
            {
                var pdu = AkkaProtocolMessage.ParseFrom(raw);
                if(pdu.HasPayload) return new Payload(pdu.Payload);
                else if (pdu.HasInstruction) return DecodeControlPdu(pdu.Instruction);
                else throw new PduCodecException("Error decoding Akka PDU: Neither message nor control message were contained");
            }
            catch (InvalidProtocolBufferException ex)
            {
                throw new PduCodecException("Decoding PDU failed", ex);
            }
        }

Usage Example

 /// <summary>
 /// This method captures ASSOCIATE packets and extracts the origin <see cref="Address"/>.
 /// </summary>
 /// <param name="b">Inbound <see cref="ByteString"/> received from network.</param>
 /// <returns></returns>
 private Address PeekOrigin(ByteString b)
 {
     try
     {
         var pdu = Codec.DecodePdu(b);
         if (pdu is Associate)
         {
             return(pdu.AsInstanceOf <Associate>().Info.Origin);
         }
         return(null);
     }
     catch
     {
         // This layer should not care about malformed packets. Also, this also useful for testing, because
         // arbitrary payload could be passed in
         return(null);
     }
 }