github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library@v0.2.0/Streams/Streams.go (about) 1 // Package Streams 2 // Dafny module Streams compiled into Go 3 4 package Streams 5 6 import ( 7 os "os" 8 9 m_BoundedInts "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/BoundedInts" 10 m_DivInternals "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/DivInternals" 11 m_DivInternalsNonlinear "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/DivInternalsNonlinear" 12 m_DivMod "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/DivMod" 13 m_FileIO "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/FileIO" 14 m_Functions "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Functions" 15 m_GeneralInternals "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/GeneralInternals" 16 m_Logarithm "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Logarithm" 17 m__Math "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Math_" 18 m_ModInternals "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/ModInternals" 19 m_ModInternalsNonlinear "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/ModInternalsNonlinear" 20 m_Mul "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Mul" 21 m_MulInternals "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/MulInternals" 22 m_MulInternalsNonlinear "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/MulInternalsNonlinear" 23 m_Power "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Power" 24 m_Relations "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Relations" 25 m_Seq "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Seq" 26 m_Seq_MergeSort "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Seq_MergeSort" 27 m_StandardLibrary "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibrary" 28 m_StandardLibraryInterop "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibraryInterop" 29 m_StandardLibrary_Sequence "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibrary_Sequence" 30 m_StandardLibrary_String "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibrary_String" 31 m_StandardLibrary_UInt "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibrary_UInt" 32 m_UnicodeStrings "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/UnicodeStrings" 33 m__Unicode "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Unicode_" 34 m_Utf16EncodingForm "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Utf16EncodingForm" 35 m_Utf8EncodingForm "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Utf8EncodingForm" 36 m_Wrappers "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Wrappers" 37 m__System "github.com/dafny-lang/DafnyRuntimeGo/v4/System_" 38 _dafny "github.com/dafny-lang/DafnyRuntimeGo/v4/dafny" 39 ) 40 41 var _ = os.Args 42 var _ _dafny.Dummy__ 43 var _ m__System.Dummy__ 44 var _ m_Wrappers.Dummy__ 45 var _ m_Relations.Dummy__ 46 var _ m_Seq_MergeSort.Dummy__ 47 var _ m__Math.Dummy__ 48 var _ m_Seq.Dummy__ 49 var _ m_BoundedInts.Dummy__ 50 var _ m__Unicode.Dummy__ 51 var _ m_Functions.Dummy__ 52 var _ m_Utf8EncodingForm.Dummy__ 53 var _ m_Utf16EncodingForm.Dummy__ 54 var _ m_UnicodeStrings.Dummy__ 55 var _ m_FileIO.Dummy__ 56 var _ m_GeneralInternals.Dummy__ 57 var _ m_MulInternalsNonlinear.Dummy__ 58 var _ m_MulInternals.Dummy__ 59 var _ m_Mul.Dummy__ 60 var _ m_ModInternalsNonlinear.Dummy__ 61 var _ m_DivInternalsNonlinear.Dummy__ 62 var _ m_ModInternals.Dummy__ 63 var _ m_DivInternals.Dummy__ 64 var _ m_DivMod.Dummy__ 65 var _ m_Power.Dummy__ 66 var _ m_Logarithm.Dummy__ 67 var _ m_StandardLibraryInterop.Dummy__ 68 var _ m_StandardLibrary_UInt.Dummy__ 69 var _ m_StandardLibrary_Sequence.Dummy__ 70 var _ m_StandardLibrary_String.Dummy__ 71 var _ m_StandardLibrary.Dummy__ 72 73 type Dummy__ struct{} 74 75 // Definition of class SeqReader 76 type SeqReader struct { 77 Pos _dafny.Int 78 _data _dafny.Sequence 79 } 80 81 func New_SeqReader_() *SeqReader { 82 _this := SeqReader{} 83 84 _this.Pos = _dafny.Zero 85 _this._data = _dafny.EmptySeq 86 return &_this 87 } 88 89 type CompanionStruct_SeqReader_ struct { 90 } 91 92 var Companion_SeqReader_ = CompanionStruct_SeqReader_{} 93 94 func (_this *SeqReader) Equals(other *SeqReader) bool { 95 return _this == other 96 } 97 98 func (_this *SeqReader) EqualsGeneric(x interface{}) bool { 99 other, ok := x.(*SeqReader) 100 return ok && _this.Equals(other) 101 } 102 103 func (*SeqReader) String() string { 104 return "Streams.SeqReader" 105 } 106 107 func Type_SeqReader_(Type_T_ _dafny.TypeDescriptor) _dafny.TypeDescriptor { 108 return type_SeqReader_{Type_T_} 109 } 110 111 type type_SeqReader_ struct { 112 Type_T_ _dafny.TypeDescriptor 113 } 114 115 func (_this type_SeqReader_) Default() interface{} { 116 return (*SeqReader)(nil) 117 } 118 119 func (_this type_SeqReader_) String() string { 120 return "Streams.SeqReader" 121 } 122 func (_this *SeqReader) ParentTraits_() []*_dafny.TraitID { 123 return [](*_dafny.TraitID){} 124 } 125 126 var _ _dafny.TraitOffspring = &SeqReader{} 127 128 func (_this *SeqReader) Ctor__(s _dafny.Sequence) { 129 { 130 (_this)._data = s 131 (_this).Pos = _dafny.Zero 132 } 133 } 134 func (_this *SeqReader) ReadElements(n _dafny.Int) _dafny.Sequence { 135 { 136 var elems _dafny.Sequence = _dafny.EmptySeq 137 _ = elems 138 elems = (((_this).Data()).Drop((_this.Pos).Uint32())).Take((n).Uint32()) 139 (_this).Pos = (_this.Pos).Plus(n) 140 elems = elems 141 return elems 142 return elems 143 } 144 } 145 func (_this *SeqReader) ReadExact(n _dafny.Int) m_Wrappers.Result { 146 { 147 var res m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 148 _ = res 149 if (n).Cmp((_dafny.IntOfUint32(((_this).Data()).Cardinality())).Minus(_this.Pos)) > 0 { 150 res = m_Wrappers.Companion_Result_.Create_Failure_(_dafny.SeqOfString("IO Error: Not enough elements left on stream.")) 151 return res 152 } else { 153 var _0_elements _dafny.Sequence 154 _ = _0_elements 155 var _out0 _dafny.Sequence 156 _ = _out0 157 _out0 = (_this).ReadElements(n) 158 _0_elements = _out0 159 res = m_Wrappers.Companion_Result_.Create_Success_(_0_elements) 160 return res 161 } 162 return res 163 } 164 } 165 func (_this *SeqReader) Data() _dafny.Sequence { 166 { 167 return _this._data 168 } 169 } 170 171 // End of class SeqReader 172 173 // Definition of class ByteReader 174 type ByteReader struct { 175 _reader *SeqReader 176 } 177 178 func New_ByteReader_() *ByteReader { 179 _this := ByteReader{} 180 181 _this._reader = (*SeqReader)(nil) 182 return &_this 183 } 184 185 type CompanionStruct_ByteReader_ struct { 186 } 187 188 var Companion_ByteReader_ = CompanionStruct_ByteReader_{} 189 190 func (_this *ByteReader) Equals(other *ByteReader) bool { 191 return _this == other 192 } 193 194 func (_this *ByteReader) EqualsGeneric(x interface{}) bool { 195 other, ok := x.(*ByteReader) 196 return ok && _this.Equals(other) 197 } 198 199 func (*ByteReader) String() string { 200 return "Streams.ByteReader" 201 } 202 203 func Type_ByteReader_() _dafny.TypeDescriptor { 204 return type_ByteReader_{} 205 } 206 207 type type_ByteReader_ struct { 208 } 209 210 func (_this type_ByteReader_) Default() interface{} { 211 return (*ByteReader)(nil) 212 } 213 214 func (_this type_ByteReader_) String() string { 215 return "Streams.ByteReader" 216 } 217 func (_this *ByteReader) ParentTraits_() []*_dafny.TraitID { 218 return [](*_dafny.TraitID){} 219 } 220 221 var _ _dafny.TraitOffspring = &ByteReader{} 222 223 func (_this *ByteReader) Ctor__(s _dafny.Sequence) { 224 { 225 var _0_mr *SeqReader 226 _ = _0_mr 227 var _nw0 *SeqReader = New_SeqReader_() 228 _ = _nw0 229 _nw0.Ctor__(s) 230 _0_mr = _nw0 231 (_this)._reader = _0_mr 232 } 233 } 234 func (_this *ByteReader) ReadByte() m_Wrappers.Result { 235 { 236 var res m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(uint8(0)) 237 _ = res 238 var _0_valueOrError0 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 239 _ = _0_valueOrError0 240 var _out0 m_Wrappers.Result 241 _ = _out0 242 _out0 = ((_this).Reader()).ReadExact(_dafny.One) 243 _0_valueOrError0 = _out0 244 if (_0_valueOrError0).IsFailure() { 245 res = (_0_valueOrError0).PropagateFailure() 246 return res 247 } 248 var _1_bytes _dafny.Sequence 249 _ = _1_bytes 250 _1_bytes = (_0_valueOrError0).Extract().(_dafny.Sequence) 251 res = m_Wrappers.Companion_Result_.Create_Success_((_1_bytes).Select(0).(uint8)) 252 return res 253 return res 254 } 255 } 256 func (_this *ByteReader) ReadBytes(n _dafny.Int) m_Wrappers.Result { 257 { 258 var res m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 259 _ = res 260 var _0_valueOrError0 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 261 _ = _0_valueOrError0 262 var _out0 m_Wrappers.Result 263 _ = _out0 264 _out0 = ((_this).Reader()).ReadExact(n) 265 _0_valueOrError0 = _out0 266 if (_0_valueOrError0).IsFailure() { 267 res = (_0_valueOrError0).PropagateFailure() 268 return res 269 } 270 var _1_bytes _dafny.Sequence 271 _ = _1_bytes 272 _1_bytes = (_0_valueOrError0).Extract().(_dafny.Sequence) 273 res = m_Wrappers.Companion_Result_.Create_Success_(_1_bytes) 274 return res 275 return res 276 } 277 } 278 func (_this *ByteReader) ReadUInt16() m_Wrappers.Result { 279 { 280 var res m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(uint16(0)) 281 _ = res 282 var _0_valueOrError0 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 283 _ = _0_valueOrError0 284 var _out0 m_Wrappers.Result 285 _ = _out0 286 _out0 = ((_this).Reader()).ReadExact(_dafny.IntOfInt64(2)) 287 _0_valueOrError0 = _out0 288 if (_0_valueOrError0).IsFailure() { 289 res = (_0_valueOrError0).PropagateFailure() 290 return res 291 } 292 var _1_bytes _dafny.Sequence 293 _ = _1_bytes 294 _1_bytes = (_0_valueOrError0).Extract().(_dafny.Sequence) 295 var _2_n uint16 296 _ = _2_n 297 _2_n = m_StandardLibrary_UInt.Companion_Default___.SeqToUInt16(_1_bytes) 298 res = m_Wrappers.Companion_Result_.Create_Success_(_2_n) 299 return res 300 return res 301 } 302 } 303 func (_this *ByteReader) ReadUInt32() m_Wrappers.Result { 304 { 305 var res m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(uint32(0)) 306 _ = res 307 var _0_valueOrError0 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 308 _ = _0_valueOrError0 309 var _out0 m_Wrappers.Result 310 _ = _out0 311 _out0 = ((_this).Reader()).ReadExact(_dafny.IntOfInt64(4)) 312 _0_valueOrError0 = _out0 313 if (_0_valueOrError0).IsFailure() { 314 res = (_0_valueOrError0).PropagateFailure() 315 return res 316 } 317 var _1_bytes _dafny.Sequence 318 _ = _1_bytes 319 _1_bytes = (_0_valueOrError0).Extract().(_dafny.Sequence) 320 var _2_n uint32 321 _ = _2_n 322 _2_n = m_StandardLibrary_UInt.Companion_Default___.SeqToUInt32(_1_bytes) 323 res = m_Wrappers.Companion_Result_.Create_Success_(_2_n) 324 return res 325 return res 326 } 327 } 328 func (_this *ByteReader) ReadUInt64() m_Wrappers.Result { 329 { 330 var res m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(uint64(0)) 331 _ = res 332 var _0_valueOrError0 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq) 333 _ = _0_valueOrError0 334 var _out0 m_Wrappers.Result 335 _ = _out0 336 _out0 = ((_this).Reader()).ReadExact(_dafny.IntOfInt64(8)) 337 _0_valueOrError0 = _out0 338 if (_0_valueOrError0).IsFailure() { 339 res = (_0_valueOrError0).PropagateFailure() 340 return res 341 } 342 var _1_bytes _dafny.Sequence 343 _ = _1_bytes 344 _1_bytes = (_0_valueOrError0).Extract().(_dafny.Sequence) 345 var _2_n uint64 346 _ = _2_n 347 _2_n = m_StandardLibrary_UInt.Companion_Default___.SeqToUInt64(_1_bytes) 348 res = m_Wrappers.Companion_Result_.Create_Success_(_2_n) 349 return res 350 return res 351 } 352 } 353 func (_this *ByteReader) IsDoneReading() bool { 354 { 355 var b bool = false 356 _ = b 357 b = (_dafny.IntOfUint32((((_this).Reader()).Data()).Cardinality())).Cmp((_this).Reader().Pos) == 0 358 return b 359 return b 360 } 361 } 362 func (_this *ByteReader) GetSizeRead() _dafny.Int { 363 { 364 var n _dafny.Int = _dafny.Zero 365 _ = n 366 n = (_this).Reader().Pos 367 return n 368 return n 369 } 370 } 371 func (_this *ByteReader) Reader() *SeqReader { 372 { 373 return _this._reader 374 } 375 } 376 377 // End of class ByteReader 378 379 // Definition of class SeqWriter 380 type SeqWriter struct { 381 Data _dafny.Sequence 382 } 383 384 func New_SeqWriter_() *SeqWriter { 385 _this := SeqWriter{} 386 387 _this.Data = _dafny.EmptySeq 388 return &_this 389 } 390 391 type CompanionStruct_SeqWriter_ struct { 392 } 393 394 var Companion_SeqWriter_ = CompanionStruct_SeqWriter_{} 395 396 func (_this *SeqWriter) Equals(other *SeqWriter) bool { 397 return _this == other 398 } 399 400 func (_this *SeqWriter) EqualsGeneric(x interface{}) bool { 401 other, ok := x.(*SeqWriter) 402 return ok && _this.Equals(other) 403 } 404 405 func (*SeqWriter) String() string { 406 return "Streams.SeqWriter" 407 } 408 409 func Type_SeqWriter_(Type_T_ _dafny.TypeDescriptor) _dafny.TypeDescriptor { 410 return type_SeqWriter_{Type_T_} 411 } 412 413 type type_SeqWriter_ struct { 414 Type_T_ _dafny.TypeDescriptor 415 } 416 417 func (_this type_SeqWriter_) Default() interface{} { 418 return (*SeqWriter)(nil) 419 } 420 421 func (_this type_SeqWriter_) String() string { 422 return "Streams.SeqWriter" 423 } 424 func (_this *SeqWriter) ParentTraits_() []*_dafny.TraitID { 425 return [](*_dafny.TraitID){} 426 } 427 428 var _ _dafny.TraitOffspring = &SeqWriter{} 429 430 func (_this *SeqWriter) Ctor__() { 431 { 432 (_this).Data = _dafny.SeqOf() 433 } 434 } 435 func (_this *SeqWriter) WriteElements(elems _dafny.Sequence) _dafny.Int { 436 { 437 var n _dafny.Int = _dafny.Zero 438 _ = n 439 (_this).Data = _dafny.Companion_Sequence_.Concatenate(_this.Data, elems) 440 n = _dafny.IntOfUint32((elems).Cardinality()) 441 return n 442 return n 443 } 444 } 445 446 // End of class SeqWriter 447 448 // Definition of class ByteWriter 449 type ByteWriter struct { 450 _writer *SeqWriter 451 } 452 453 func New_ByteWriter_() *ByteWriter { 454 _this := ByteWriter{} 455 456 _this._writer = (*SeqWriter)(nil) 457 return &_this 458 } 459 460 type CompanionStruct_ByteWriter_ struct { 461 } 462 463 var Companion_ByteWriter_ = CompanionStruct_ByteWriter_{} 464 465 func (_this *ByteWriter) Equals(other *ByteWriter) bool { 466 return _this == other 467 } 468 469 func (_this *ByteWriter) EqualsGeneric(x interface{}) bool { 470 other, ok := x.(*ByteWriter) 471 return ok && _this.Equals(other) 472 } 473 474 func (*ByteWriter) String() string { 475 return "Streams.ByteWriter" 476 } 477 478 func Type_ByteWriter_() _dafny.TypeDescriptor { 479 return type_ByteWriter_{} 480 } 481 482 type type_ByteWriter_ struct { 483 } 484 485 func (_this type_ByteWriter_) Default() interface{} { 486 return (*ByteWriter)(nil) 487 } 488 489 func (_this type_ByteWriter_) String() string { 490 return "Streams.ByteWriter" 491 } 492 func (_this *ByteWriter) ParentTraits_() []*_dafny.TraitID { 493 return [](*_dafny.TraitID){} 494 } 495 496 var _ _dafny.TraitOffspring = &ByteWriter{} 497 498 func (_this *ByteWriter) Ctor__() { 499 { 500 var _0_mw *SeqWriter 501 _ = _0_mw 502 var _nw0 *SeqWriter = New_SeqWriter_() 503 _ = _nw0 504 _nw0.Ctor__() 505 _0_mw = _nw0 506 (_this)._writer = _0_mw 507 } 508 } 509 func (_this *ByteWriter) WriteByte(n uint8) _dafny.Int { 510 { 511 var r _dafny.Int = _dafny.Zero 512 _ = r 513 var _out0 _dafny.Int 514 _ = _out0 515 _out0 = ((_this).Writer()).WriteElements(_dafny.SeqOf(n)) 516 r = _out0 517 return r 518 } 519 } 520 func (_this *ByteWriter) WriteBytes(s _dafny.Sequence) _dafny.Int { 521 { 522 var r _dafny.Int = _dafny.Zero 523 _ = r 524 var _out0 _dafny.Int 525 _ = _out0 526 _out0 = ((_this).Writer()).WriteElements(s) 527 r = _out0 528 return r 529 } 530 } 531 func (_this *ByteWriter) WriteUInt16(n uint16) _dafny.Int { 532 { 533 var r _dafny.Int = _dafny.Zero 534 _ = r 535 var _out0 _dafny.Int 536 _ = _out0 537 _out0 = ((_this).Writer()).WriteElements(m_StandardLibrary_UInt.Companion_Default___.UInt16ToSeq(n)) 538 r = _out0 539 return r 540 } 541 } 542 func (_this *ByteWriter) WriteUInt32(n uint32) _dafny.Int { 543 { 544 var r _dafny.Int = _dafny.Zero 545 _ = r 546 var _out0 _dafny.Int 547 _ = _out0 548 _out0 = ((_this).Writer()).WriteElements(m_StandardLibrary_UInt.Companion_Default___.UInt32ToSeq(n)) 549 r = _out0 550 return r 551 } 552 } 553 func (_this *ByteWriter) GetDataWritten() _dafny.Sequence { 554 { 555 return (_this).Writer().Data 556 } 557 } 558 func (_this *ByteWriter) GetSizeWritten() _dafny.Int { 559 { 560 return _dafny.IntOfUint32(((_this).Writer().Data).Cardinality()) 561 } 562 } 563 func (_this *ByteWriter) Writer() *SeqWriter { 564 { 565 return _this._writer 566 } 567 } 568 569 // End of class ByteWriter