Couchbase .NET SDK __CB_SDK_VERSION__

Show / Hide Table of Contents

Class RawByteArraySerializer

An ITypeSerializer decorator that treats byte[] as a raw pass-through in both directions and delegates every other type to an inner serializer.

Inheritance
object
RawByteArraySerializer
Implements
ITypeSerializer
Inherited Members
object.GetType()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: Couchbase.Core.IO.Serializers
Assembly: Couchbase.NetClient.dll
Syntax
public sealed class RawByteArraySerializer : ITypeSerializer
Remarks

The default serializers (Newtonsoft and System.Text.Json) encode a byte[] as a Base64 JSON string, so a plain ContentAs<byte[]>() Base64-decodes. That is required for round-tripping arbitrary binary through data structures such as PersistentQueue<byte[]>. When you instead want the raw encoded bytes of a value (for example, the raw JSON of a sub-document fragment), wrap the configured serializer in this decorator and supply it via a per-operation transcoder. This matches the behaviour of the Java SDK's default serializer, where byte[] is always raw pass-through.

Because non-byte[] types are delegated to the inner serializer, its JSON semantics (converters, naming policy, AOT source generation, etc.) are preserved. This type implements only ITypeSerializer; it does not forward the extended serializer interfaces (projections, streaming), so it is intended for per-operation use (e.g. a raw byte[] sub-document read) rather than as a cluster-wide serializer.

Constructors

View Source

RawByteArraySerializer(ITypeSerializer)

Creates a RawByteArraySerializer wrapping the serializer that should handle all non-byte[] types.

Declaration
public RawByteArraySerializer(ITypeSerializer inner)
Parameters
Type Name Description
ITypeSerializer inner

The serializer to delegate to for non-byte[] types.

Methods

View Source

DeserializeAsync<T>(Stream, CancellationToken)

Deserializes the specified stream into the Type T specified as a generic parameter.

Declaration
public ValueTask<T?> DeserializeAsync<T>(Stream stream, CancellationToken cancellationToken = default)
Parameters
Type Name Description
Stream stream

The stream.

CancellationToken cancellationToken

Cancellation token.

Returns
Type Description
ValueTask<T>

The Type instance representing the value of the key.

Type Parameters
Name Description
T

The Type specified as the type of the value.

View Source

Deserialize<T>(Stream)

Deserializes the specified stream into the Type T specified as a generic parameter.

Declaration
public T? Deserialize<T>(Stream stream)
Parameters
Type Name Description
Stream stream

The stream.

Returns
Type Description
T

The Type instance representing the value of the key.

Type Parameters
Name Description
T

The Type specified as the type of the value.

View Source

Deserialize<T>(ReadOnlyMemory<byte>)

Deserializes the specified buffer into the Type T specified as a generic parameter.

Declaration
public T? Deserialize<T>(ReadOnlyMemory<byte> buffer)
Parameters
Type Name Description
ReadOnlyMemory<byte> buffer

The buffer to deserialize from.

Returns
Type Description
T

The Type instance representing the value of the key.

Type Parameters
Name Description
T

The Type specified as the type of the value.

View Source

Serialize(Stream, object?)

Serializes the specified object onto a stream.

Declaration
public void Serialize(Stream stream, object? obj)
Parameters
Type Name Description
Stream stream

The stream to receive the serialized object.

object obj

The object to serialize.

View Source

SerializeAsync(Stream, object?, CancellationToken)

Serializes the specified object onto a stream.

Declaration
public ValueTask SerializeAsync(Stream stream, object? obj, CancellationToken cancellationToken = default)
Parameters
Type Name Description
Stream stream

The stream to receive the serialized object.

object obj

The object to serialize.

CancellationToken cancellationToken

Cancellation token.

Returns
Type Description
ValueTask

Implements

ITypeSerializer

Extension Methods

TypeSerializerExtensions.Deserialize<T>(ITypeSerializer, byte[], int, int)
TypeSerializerExtensions.Serialize(ITypeSerializer, object?)
  • View Source
In this article
Back to top Copyright © 2020 Couchbase, Inc. All rights reserved.