예제 #1
0
 public static ISegmentBuildDefinition WithOptions(this ISegmentBuildDefinition builder, SegmentionOptions options)
 {
     if (!(builder is SegmentBuildDefinition def))
     {
         throw new NotSupportedException($"{builder.GetType()} is not supported");
     }
     def.Options = options;
     return(builder);
 }
예제 #2
0
 public static ISegmentBuildDefinition WithMaxLength(this ISegmentBuildDefinition builder, long maxLength)
 {
     if (!(builder is SegmentBuildDefinition def))
     {
         throw new NotSupportedException($"{builder.GetType()} is not supported");
     }
     if (def.Length.HasValue)
     {
         throw new NotSupportedException("May not set end byte if using length");
     }
     def.MaxLength = maxLength == 0 ? (long?)null : maxLength;
     return(builder);
 }
예제 #3
0
 public static ISegmentBuildDefinition AndEndsWith(this ISegmentBuildDefinition builder, byte end)
 {
     if (!(builder is SegmentBuildDefinition def))
     {
         throw new NotSupportedException($"{builder.GetType()} is not supported");
     }
     if (def.Length.HasValue)
     {
         throw new NotSupportedException("May not set end byte if using length");
     }
     def.EndsWith = end;
     return(builder);
 }
예제 #4
0
        public static ISegmentBuildDefinition ExtendedWithLengthAt <TOfType>(this ISegmentBuildDefinition builder, long position, Endianness endianness)
            where TOfType : unmanaged
        {
            if (!(builder is SegmentBuildDefinition def))
            {
                throw new NotSupportedException($"{builder.GetType()} is not supported");
            }
            if (!def.Length.HasValue)
            {
                throw new NotSupportedException("Must start with fixed length");
            }

            unsafe
            {
                def.ExtensionDefinition = new SegmentExtensionDefinition(type: typeof(TOfType), length: sizeof(TOfType), postion: position, endianness: endianness);
            }
            return(builder);
        }
예제 #5
0
        public static ISegmenter ThenDo(this ISegmentBuildDefinition builder, OnSegmentReceived onSegmentReceived)
        {
            if (!(builder is SegmentBuildDefinition def))
            {
                throw new NotSupportedException($"{builder.GetType()} is not supported");
            }

            ISegmenter?built =
                def.EndsWith.HasValue ? (ISegmenter) new BetweenSegmenter(onSegmentReceived, def.StartsWith, def.EndsWith.Value, def.MaxLength, def.Options) :
                def.Length.HasValue ? new StartAndFixLengthSegmenter(onSegmentReceived, def.StartsWith, def.Length.Value, def.Options, def.ExtensionDefinition) :
                null;

            if (built == null)
            {
                throw new NotSupportedException("Unable to Build Segmenter");
            }

            return(built);
        }