1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT License.
3
3
4
+ using System ;
4
5
using System . IO ;
5
6
using System . Text ;
6
7
using Azure . Core ;
11
12
12
13
namespace Azure . Storage . DataMovement . Blobs
13
14
{
14
- internal class BlobDestinationCheckpointData : StorageResourceCheckpointData
15
+ internal class BlobDestinationCheckpointData : BlobCheckpointData
15
16
{
16
- /// <summary>
17
- /// Schema version.
18
- /// </summary>
19
- public int Version ;
20
-
21
- /// <summary>
22
- /// The type of the destination blob.
23
- /// </summary>
24
- public BlobType BlobType ;
25
-
26
17
/// <summary>
27
18
/// The content headers for the destination blob.
28
19
/// </summary>
@@ -65,29 +56,28 @@ public BlobDestinationCheckpointData(
65
56
Metadata metadata ,
66
57
Tags blobTags ,
67
58
string cpkScope )
59
+ : base ( DataMovementBlobConstants . DestinationCheckpointData . SchemaVersion , blobType )
68
60
{
69
- Version = DataMovementBlobConstants . DestinationJobPartHeader . SchemaVersion ;
70
- BlobType = blobType ;
71
61
ContentHeaders = contentHeaders ;
72
- _contentTypeBytes = ContentHeaders ? . ContentType != default ? Encoding . UTF8 . GetBytes ( ContentHeaders . ContentType ) : new byte [ 0 ] ;
73
- _contentEncodingBytes = ContentHeaders ? . ContentEncoding != default ? Encoding . UTF8 . GetBytes ( ContentHeaders . ContentEncoding ) : new byte [ 0 ] ;
74
- _contentLanguageBytes = ContentHeaders ? . ContentLanguage != default ? Encoding . UTF8 . GetBytes ( ContentHeaders . ContentLanguage ) : new byte [ 0 ] ;
75
- _contentDispositionBytes = ContentHeaders ? . ContentDisposition != default ? Encoding . UTF8 . GetBytes ( ContentHeaders . ContentDisposition ) : new byte [ 0 ] ;
76
- _cacheControlBytes = ContentHeaders ? . CacheControl != default ? Encoding . UTF8 . GetBytes ( ContentHeaders . CacheControl ) : new byte [ 0 ] ;
62
+ _contentTypeBytes = ContentHeaders ? . ContentType != default ? Encoding . UTF8 . GetBytes ( ContentHeaders . ContentType ) : Array . Empty < byte > ( ) ;
63
+ _contentEncodingBytes = ContentHeaders ? . ContentEncoding != default ? Encoding . UTF8 . GetBytes ( ContentHeaders . ContentEncoding ) : Array . Empty < byte > ( ) ;
64
+ _contentLanguageBytes = ContentHeaders ? . ContentLanguage != default ? Encoding . UTF8 . GetBytes ( ContentHeaders . ContentLanguage ) : Array . Empty < byte > ( ) ;
65
+ _contentDispositionBytes = ContentHeaders ? . ContentDisposition != default ? Encoding . UTF8 . GetBytes ( ContentHeaders . ContentDisposition ) : Array . Empty < byte > ( ) ;
66
+ _cacheControlBytes = ContentHeaders ? . CacheControl != default ? Encoding . UTF8 . GetBytes ( ContentHeaders . CacheControl ) : Array . Empty < byte > ( ) ;
77
67
AccessTier = accessTier ;
78
68
Metadata = metadata ;
79
- _metadataBytes = Metadata != default ? Encoding . UTF8 . GetBytes ( Metadata . DictionaryToString ( ) ) : new byte [ 0 ] ;
69
+ _metadataBytes = Metadata != default ? Encoding . UTF8 . GetBytes ( Metadata . DictionaryToString ( ) ) : Array . Empty < byte > ( ) ;
80
70
Tags = blobTags ;
81
- _tagsBytes = Tags != default ? Encoding . UTF8 . GetBytes ( Tags . DictionaryToString ( ) ) : new byte [ 0 ] ;
71
+ _tagsBytes = Tags != default ? Encoding . UTF8 . GetBytes ( Tags . DictionaryToString ( ) ) : Array . Empty < byte > ( ) ;
82
72
CpkScope = cpkScope ;
83
- _cpkScopeBytes = CpkScope != default ? Encoding . UTF8 . GetBytes ( CpkScope ) : new byte [ 0 ] ;
73
+ _cpkScopeBytes = CpkScope != default ? Encoding . UTF8 . GetBytes ( CpkScope ) : Array . Empty < byte > ( ) ;
84
74
}
85
75
86
- protected override void Serialize ( Stream stream )
76
+ public override void Serialize ( Stream stream )
87
77
{
88
78
Argument . AssertNotNull ( stream , nameof ( stream ) ) ;
89
79
90
- int currentVariableLengthIndex = DataMovementBlobConstants . DestinationJobPartHeader . VariableLengthStartIndex ;
80
+ int currentVariableLengthIndex = DataMovementBlobConstants . DestinationCheckpointData . VariableLengthStartIndex ;
91
81
BinaryWriter writer = new BinaryWriter ( stream ) ;
92
82
93
83
// Version
@@ -97,31 +87,31 @@ protected override void Serialize(Stream stream)
97
87
writer . Write ( ( byte ) BlobType ) ;
98
88
99
89
// ContentType offset/length
100
- WriteVariableLengthFieldInfo ( writer , _contentTypeBytes , ref currentVariableLengthIndex ) ;
90
+ WriteVariableLengthFieldInfo ( writer , _contentTypeBytes . Length , ref currentVariableLengthIndex ) ;
101
91
102
92
// ContentEncoding offset/length
103
- WriteVariableLengthFieldInfo ( writer , _contentEncodingBytes , ref currentVariableLengthIndex ) ;
93
+ WriteVariableLengthFieldInfo ( writer , _contentEncodingBytes . Length , ref currentVariableLengthIndex ) ;
104
94
105
95
// ContentLanguage offset/length
106
- WriteVariableLengthFieldInfo ( writer , _contentLanguageBytes , ref currentVariableLengthIndex ) ;
96
+ WriteVariableLengthFieldInfo ( writer , _contentLanguageBytes . Length , ref currentVariableLengthIndex ) ;
107
97
108
98
// ContentDisposition offset/length
109
- WriteVariableLengthFieldInfo ( writer , _contentDispositionBytes , ref currentVariableLengthIndex ) ;
99
+ WriteVariableLengthFieldInfo ( writer , _contentDispositionBytes . Length , ref currentVariableLengthIndex ) ;
110
100
111
101
// CacheControl offset/length
112
- WriteVariableLengthFieldInfo ( writer , _cacheControlBytes , ref currentVariableLengthIndex ) ;
102
+ WriteVariableLengthFieldInfo ( writer , _cacheControlBytes . Length , ref currentVariableLengthIndex ) ;
113
103
114
104
// AccessTier
115
105
writer . Write ( ( byte ) AccessTier . ToJobPlanAccessTier ( ) ) ;
116
106
117
107
// Metadata offset/length
118
- WriteVariableLengthFieldInfo ( writer , _metadataBytes , ref currentVariableLengthIndex ) ;
108
+ WriteVariableLengthFieldInfo ( writer , _metadataBytes . Length , ref currentVariableLengthIndex ) ;
119
109
120
110
// Tags offset/length
121
- WriteVariableLengthFieldInfo ( writer , _tagsBytes , ref currentVariableLengthIndex ) ;
111
+ WriteVariableLengthFieldInfo ( writer , _tagsBytes . Length , ref currentVariableLengthIndex ) ;
122
112
123
113
// CpkScope offset/length
124
- WriteVariableLengthFieldInfo ( writer , _cpkScopeBytes , ref currentVariableLengthIndex ) ;
114
+ WriteVariableLengthFieldInfo ( writer , _cpkScopeBytes . Length , ref currentVariableLengthIndex ) ;
125
115
126
116
writer . Write ( _contentTypeBytes ) ;
127
117
writer . Write ( _contentEncodingBytes ) ;
@@ -141,7 +131,10 @@ internal static BlobDestinationCheckpointData Deserialize(Stream stream)
141
131
142
132
// Version
143
133
int version = reader . ReadInt32 ( ) ;
144
- CheckSchemaVersion ( version ) ;
134
+ if ( version != DataMovementBlobConstants . DestinationCheckpointData . SchemaVersion )
135
+ {
136
+ throw Errors . UnsupportedJobSchemaVersionHeader ( version . ToString ( ) ) ;
137
+ }
145
138
146
139
// BlobType
147
140
BlobType blobType = ( BlobType ) reader . ReadByte ( ) ;
@@ -168,7 +161,11 @@ internal static BlobDestinationCheckpointData Deserialize(Stream stream)
168
161
169
162
// AccessTier
170
163
JobPlanAccessTier jobPlanAccessTier = ( JobPlanAccessTier ) reader . ReadByte ( ) ;
171
- AccessTier accessTier = new AccessTier ( jobPlanAccessTier . ToString ( ) ) ;
164
+ AccessTier ? accessTier = default ;
165
+ if ( ! jobPlanAccessTier . Equals ( JobPlanAccessTier . None ) )
166
+ {
167
+ accessTier = new AccessTier ( jobPlanAccessTier . ToString ( ) ) ;
168
+ }
172
169
173
170
// Metadata offset/length
174
171
int metadataOffset = reader . ReadInt32 ( ) ;
@@ -267,7 +264,7 @@ internal static BlobDestinationCheckpointData Deserialize(Stream stream)
267
264
private int CalculateLength ( )
268
265
{
269
266
// Length is fixed size fields plus length of each variable length field
270
- int length = DataMovementBlobConstants . DestinationJobPartHeader . VariableLengthStartIndex ;
267
+ int length = DataMovementBlobConstants . DestinationCheckpointData . VariableLengthStartIndex ;
271
268
length += _contentTypeBytes . Length ;
272
269
length += _contentEncodingBytes . Length ;
273
270
length += _contentLanguageBytes . Length ;
@@ -278,13 +275,5 @@ private int CalculateLength()
278
275
length += _cpkScopeBytes . Length ;
279
276
return length ;
280
277
}
281
-
282
- private static void CheckSchemaVersion ( int version )
283
- {
284
- if ( version != DataMovementBlobConstants . DestinationJobPartHeader . SchemaVersion )
285
- {
286
- throw Errors . UnsupportedJobSchemaVersionHeader ( version . ToString ( ) ) ;
287
- }
288
- }
289
278
}
290
279
}
0 commit comments