# SegmentBuilder Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.streaming/orleans.providers.streams.common.segmentbuilder/)

## Append(ArraySegment&lt;byte&gt;, int, ReadOnlySpan&lt;byte&gt;) {#append-system-arraysegment-byte-ref-int-system-readonlyspan-byte-30377f1b}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.streaming/orleans.providers.streams.common.segmentbuilder/methods/append-system-arraysegment-byte-ref-int-system-readonlyspan-byte-30377f1b/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Streaming/Common/SegmentBuilder.cs#L33-L47)

```csharp
public static void Append(ArraySegment<byte> segment, ref int writerOffset, ReadOnlySpan<byte> bytes)
```

Appends a `System.ReadOnlyMemory-1` of bytes to the end of the segment

### Parameters

- `segment` (`ArraySegment<byte>`)
- `writerOffset` (`int`)
- `bytes` (`ReadOnlySpan<byte>`)

## Append(ArraySegment&lt;byte&gt;, int, string) {#append-system-arraysegment-byte-ref-int-string-f4f26612}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.streaming/orleans.providers.streams.common.segmentbuilder/methods/append-system-arraysegment-byte-ref-int-string-f4f26612/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Streaming/Common/SegmentBuilder.cs#L57-L71)

```csharp
public static void Append(ArraySegment<byte> segment, ref int writerOffset, string str)
```

Appends a string to the end of the segment

### Parameters

- `segment` (`ArraySegment<byte>`)
- `writerOffset` (`int`)
- `str` (`string`)

## CalculateAppendSize(ReadOnlySpan&lt;byte&gt;) {#calculateappendsize-system-readonlyspan-byte-99120bf6}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.streaming/orleans.providers.streams.common.segmentbuilder/methods/calculateappendsize-system-readonlyspan-byte-99120bf6/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Streaming/Common/SegmentBuilder.cs#L16)

```csharp
public static int CalculateAppendSize(ReadOnlySpan<byte> memory)
```

Calculates how much space will be needed to append the provided bytes into the segment.

### Parameters

- `memory` (`ReadOnlySpan<byte>`)

## CalculateAppendSize(string) {#calculateappendsize-string-42b7f44b}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.streaming/orleans.providers.streams.common.segmentbuilder/methods/calculateappendsize-string-42b7f44b/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Streaming/Common/SegmentBuilder.cs#L23)

```csharp
public static int CalculateAppendSize(string str)
```

Calculates how much space will be needed to append the provided string into the segment.

### Parameters

- `str` (`string`)

## ReadNextBytes(ArraySegment&lt;byte&gt;, int) {#readnextbytes-system-arraysegment-byte-ref-int-04059880}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.streaming/orleans.providers.streams.common.segmentbuilder/methods/readnextbytes-system-arraysegment-byte-ref-int-04059880/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Streaming/Common/SegmentBuilder.cs#L79-L87)

```csharp
public static ArraySegment<byte> ReadNextBytes(ArraySegment<byte> segment, ref int readerOffset)
```

Reads the next item in the segment as a byte array. For performance, this is returned as a sub-segment of the original segment.

### Parameters

- `segment` (`ArraySegment<byte>`)
- `readerOffset` (`int`)

## ReadNextString(ArraySegment&lt;byte&gt;, int) {#readnextstring-system-arraysegment-byte-ref-int-f4503a87}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.streaming/orleans.providers.streams.common.segmentbuilder/methods/readnextstring-system-arraysegment-byte-ref-int-f4503a87/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Streaming/Common/SegmentBuilder.cs#L96-L112)

```csharp
public static string ReadNextString(ArraySegment<byte> segment, ref int readerOffset)
```

Reads the next item in the segment as a string.

### Parameters

- `segment` (`ArraySegment<byte>`)
- `readerOffset` (`int`)
