// streamPartialHandler returns a streaming handler that has the following contract:
// read a byte, write N bytes where N = the byte that was read.
// The results are be written as soon as the byte is read.
streamPartialHandler returns a streaming handler that has the following contract:
read a byte, write N bytes where N = the byte that was read.
The results are be written as soon as the byte is read.
// streamPartialHandler returns a streaming handler that has the following contract : // read a byte write N bytes where N = the byte that was read . // The results are be written as soon as the byte is read .
func streamPartialHandler(t testing.TB, reportErrors bool) HandlerFunc {
	return func(ctx context.Context, call *InboundCall) {
		response := call.Response()
		onError := func(err error) {
			if reportErrors {
				t.Errorf("Handler error: %v", err)
			}
			response.SendSystemError(fmt.Errorf("failed to read arg2"))
		}
		var arg2 []byte
		if err := NewArgReader(call.Arg2Reader()).Read(&arg2); err != nil {
			onError(fmt.Errorf("failed to read arg2"))
			return
		}
		if err := NewArgWriter(response.Arg2Writer()).Write(nil); err != nil {
			onError(fmt.Errorf(""))
			return
		}
		argReader, err := call.Arg3Reader()
		if err != nil {
			onError(fmt.Errorf("failed to read arg3"))
			return
		}
		argWriter, err := response.Arg3Writer()
		if err != nil {
			onError(fmt.Errorf("arg3 writer failed"))
			return
		}
		if err := argWriter.Flush(); err != nil {
			onError(fmt.Errorf("arg3 flush failed"))
			return
		}
		arg3 := make([]byte, 1)
		for {
			n, err := argReader.Read(arg3)
			if err == io.EOF {
				break
			}
			if n == 0 && err == nil {
				err = fmt.Errorf("read 0 bytes")
			}
			if err != nil {
				onError(fmt.Errorf("arg3 Read failed: %v", err))
				return
			}
			if arg3[0] == streamRequestError {
				if err := argReader.Close(); err != nil {
					onError(fmt.Errorf("request error failed to close argReader: %v", err))
					return
				}
				response.SendSystemError(errors.New("intentional failure"))
				return
			}
			if arg3[0] == streamRequestClose {
				if err := argWriter.Close(); err != nil {
					onError(err)
				}
				return
			}
			if _, err := argWriter.Write(makeRepeatedBytes(arg3[0])); err != nil {
				onError(fmt.Errorf("argWriter Write failed: %v", err))
				return
			}
			if err := argWriter.Flush(); err != nil {
				onError(fmt.Errorf("argWriter flush failed: %v", err))
				return
			}
		}
		if err := argReader.Close(); err != nil {
			onError(fmt.Errorf("argReader Close failed: %v", err))
			return
		}
		if err := argWriter.Close(); err != nil {
			onError(fmt.Errorf("arg3writer Close failed: %v", err))
			return
		}
	}
}
func streamPartialHandler ( t testing . TB , reportErrors bool ) HandlerFunc { return func ( ctx context . Context , call * InboundCall ) { response := call . Response ( ) onError := func ( err error ) { if reportErrors { t . Errorf ( " " , err ) } response . SendSystemError ( fmt . Errorf ( " " ) ) } var arg2 [ ] byte if err := NewArgReader ( call . Arg2Reader ( ) ) . Read ( & arg2 ) ; err != nil { onError ( fmt . Errorf ( " " ) ) return } if err := NewArgWriter ( response . Arg2Writer ( ) ) . Write ( nil ) ; err != nil { onError ( fmt . Errorf ( " " ) ) return } argReader , err := call . Arg3Reader ( ) if err != nil { onError ( fmt . Errorf ( " " ) ) return } argWriter , err := response . Arg3Writer ( ) if err != nil { onError ( fmt . Errorf ( " " ) ) return } if err := argWriter . Flush ( ) ; err != nil { onError ( fmt . Errorf ( " " ) ) return } arg3 := make ( [ ] byte , 1 ) for { n , err := argReader . Read ( arg3 ) if err == io . EOF { break } if n == 0 && err == nil { err = fmt . Errorf ( " " ) } if err != nil { onError ( fmt . Errorf ( " " , err ) ) return } if arg3 [ 0 ] == streamRequestError { if err := argReader . Close ( ) ; err != nil { onError ( fmt . Errorf ( " " , err ) ) return } response . SendSystemError ( errors . New ( " " ) ) return } if arg3 [ 0 ] == streamRequestClose { if err := argWriter . Close ( ) ; err != nil { onError ( err ) } return } if _ , err := argWriter . Write ( makeRepeatedBytes ( arg3 [ 0 ] ) ) ; err != nil { onError ( fmt . Errorf ( " " , err ) ) return } if err := argWriter . Flush ( ) ; err != nil { onError ( fmt . Errorf ( " " , err ) ) return } } if err := argReader . Close ( ) ; err != nil { onError ( fmt . Errorf ( " " , err ) ) return } if err := argWriter . Close ( ) ; err != nil { onError ( fmt . Errorf ( " " , err ) ) return } } }
streamPartialHandler returns a streaming handler that has the following contract:
read a byte, write N bytes where N = the byte that was read.
streamPartialHandler returns a streaming handler that has the following contract : read a byte write N bytes where N = the byte that was read .
// Flush arg3 which will force a frame with just arg2 to be sent. // The test reads arg2 before arg3 has been sent. // Magic number to cause a failure // Make sure that the reader is closed. // Write the number of bytes as specified by arg3[0]