1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
//------------------------------------------------------------------------------
// <copyright file="SmiGettersStream.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
// <owner current="true" primary="false">Microsoft</owner>
//------------------------------------------------------------------------------
namespace Microsoft.SqlServer.Server {
using System;
using System.Data.Common;
using System.Data.SqlClient;
using System.IO;
using System.Diagnostics;
internal class SmiGettersStream : Stream {
private SmiEventSink_Default _sink;
private ITypedGettersV3 _getters;
private int _ordinal;
private long _readPosition;
private SmiMetaData _metaData;
internal SmiGettersStream( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData ) {
Debug.Assert( null != sink );
Debug.Assert( null != getters );
Debug.Assert( 0 <= ordinal );
Debug.Assert( null != metaData );
_sink = sink;
_getters = getters;
_ordinal = ordinal;
_readPosition = 0;
_metaData = metaData;
}
public override bool CanRead {
get {
return true;
}
}
// If CanSeek is false, Position, Seek, Length, and SetLength should throw.
public override bool CanSeek {
get {
return false;
}
}
public override bool CanWrite {
get {
return false;
}
}
public override long Length {
get {
return ValueUtilsSmi.GetBytesInternal( _sink, _getters, _ordinal, _metaData, 0, null, 0, 0, false );
}
}
public override long Position {
get {
return _readPosition;
}
set {
throw SQL.StreamSeekNotSupported();
}
}
public override void Flush() {
throw SQL.StreamWriteNotSupported();
}
public override long Seek(long offset, SeekOrigin origin) {
throw SQL.StreamSeekNotSupported();
}
public override void SetLength(long value) {
throw SQL.StreamWriteNotSupported();
}
public override int Read( byte[] buffer, int offset, int count ) {
long bytesRead = ValueUtilsSmi.GetBytesInternal( _sink, _getters, _ordinal, _metaData, _readPosition, buffer, offset, count, false );
_readPosition += bytesRead;
return checked( (int) bytesRead );
}
public override void Write( byte[] buffer, int offset, int count ) {
throw SQL.StreamWriteNotSupported();
}
}
}
|