github.com/datastax/go-cassandra-native-protocol@v0.0.0-20220706104457-5e8aad05cf90/primitive/constants.go (about) 1 // Copyright 2020 DataStax 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package primitive 16 17 import "fmt" 18 19 type ProtocolVersion uint8 20 21 // Supported OSS versions 22 const ( 23 ProtocolVersion2 = ProtocolVersion(0x2) 24 ProtocolVersion3 = ProtocolVersion(0x3) 25 ProtocolVersion4 = ProtocolVersion(0x4) 26 ProtocolVersion5 = ProtocolVersion(0x5) 27 ) 28 29 // Supported DSE versions 30 // Note: all DSE versions have the 7th bit set to 1 31 const ( 32 ProtocolVersionDse1 = ProtocolVersion(0b_1_000001) // 1 + DSE bit = 65 33 ProtocolVersionDse2 = ProtocolVersion(0b_1_000010) // 2 + DSE bit = 66 34 ) 35 36 func (v ProtocolVersion) IsSupported() bool { 37 for _, supported := range SupportedProtocolVersions() { 38 if v == supported { 39 return true 40 } 41 } 42 return false 43 } 44 45 func (v ProtocolVersion) IsOss() bool { 46 switch v { 47 case ProtocolVersion2: 48 case ProtocolVersion3: 49 case ProtocolVersion4: 50 case ProtocolVersion5: 51 default: 52 return false 53 } 54 return true 55 } 56 57 func (v ProtocolVersion) IsDse() bool { 58 switch v { 59 case ProtocolVersionDse1: 60 case ProtocolVersionDse2: 61 default: 62 return false 63 } 64 return true 65 } 66 67 func (v ProtocolVersion) IsBeta() bool { 68 return false // no beta version supported currently 69 } 70 71 func (v ProtocolVersion) String() string { 72 switch v { 73 case ProtocolVersion2: 74 return "ProtocolVersion OSS 2" 75 case ProtocolVersion3: 76 return "ProtocolVersion OSS 3" 77 case ProtocolVersion4: 78 return "ProtocolVersion OSS 4" 79 case ProtocolVersion5: 80 return "ProtocolVersion OSS 5" 81 case ProtocolVersionDse1: 82 return "ProtocolVersion DSE 1" 83 case ProtocolVersionDse2: 84 return "ProtocolVersion DSE 2" 85 } 86 return fmt.Sprintf("ProtocolVersion ? [%#.2X]", uint8(v)) 87 } 88 89 func (v ProtocolVersion) Uses4BytesCollectionLength() bool { 90 return v >= ProtocolVersion3 91 } 92 93 func (v ProtocolVersion) Uses4BytesQueryFlags() bool { 94 return v >= ProtocolVersion5 95 } 96 97 func (v ProtocolVersion) SupportsCompression(compression Compression) bool { 98 switch compression { 99 case CompressionNone: 100 return true 101 case CompressionLz4: 102 return true 103 case CompressionSnappy: 104 return v != ProtocolVersion5 105 } 106 return false // unknown compression 107 } 108 109 func (v ProtocolVersion) SupportsBatchQueryFlags() bool { 110 return v >= ProtocolVersion3 111 } 112 113 func (v ProtocolVersion) SupportsPrepareFlags() bool { 114 return v >= ProtocolVersion5 && v != ProtocolVersionDse1 115 } 116 117 func (v ProtocolVersion) SupportsQueryFlag(flag QueryFlag) bool { 118 switch flag { 119 case QueryFlagValues: 120 return v >= ProtocolVersion2 121 case QueryFlagSkipMetadata: 122 return v >= ProtocolVersion2 123 case QueryFlagPageSize: 124 return v >= ProtocolVersion2 125 case QueryFlagPagingState: 126 return v >= ProtocolVersion2 127 case QueryFlagSerialConsistency: 128 return v >= ProtocolVersion2 129 case QueryFlagDefaultTimestamp: 130 return v >= ProtocolVersion3 131 case QueryFlagValueNames: 132 return v >= ProtocolVersion3 133 case QueryFlagWithKeyspace: 134 return v >= ProtocolVersion5 && v != ProtocolVersionDse1 135 case QueryFlagNowInSeconds: 136 return v >= ProtocolVersion5 && v != ProtocolVersionDse1 && v != ProtocolVersionDse2 137 // DSE-specific flags 138 case QueryFlagDsePageSizeBytes: 139 return v.IsDse() 140 case QueryFlagDseWithContinuousPagingOptions: 141 return v.IsDse() 142 } 143 // Unknown flag 144 return false 145 } 146 147 func (v ProtocolVersion) SupportsResultMetadataId() bool { 148 return v >= ProtocolVersion5 && v != ProtocolVersionDse1 149 } 150 151 func (v ProtocolVersion) SupportsReadWriteFailureReasonMap() bool { 152 return v >= ProtocolVersion5 153 } 154 155 func (v ProtocolVersion) SupportsWriteTimeoutContentions() bool { 156 return v >= ProtocolVersion5 && v != ProtocolVersionDse1 && v != ProtocolVersionDse2 157 } 158 159 func (v ProtocolVersion) SupportsDataType(code DataTypeCode) bool { 160 switch code { 161 case DataTypeCodeCustom: 162 case DataTypeCodeAscii: 163 case DataTypeCodeBigint: 164 case DataTypeCodeBlob: 165 case DataTypeCodeBoolean: 166 case DataTypeCodeCounter: 167 case DataTypeCodeDecimal: 168 case DataTypeCodeDouble: 169 case DataTypeCodeFloat: 170 case DataTypeCodeInt: 171 case DataTypeCodeTimestamp: 172 case DataTypeCodeUuid: 173 case DataTypeCodeVarchar: 174 case DataTypeCodeVarint: 175 case DataTypeCodeTimeuuid: 176 case DataTypeCodeInet: 177 case DataTypeCodeList: 178 case DataTypeCodeMap: 179 case DataTypeCodeSet: 180 case DataTypeCodeText: 181 return v <= ProtocolVersion2 // removed in version 3 182 case DataTypeCodeUdt: 183 return v >= ProtocolVersion3 184 case DataTypeCodeTuple: 185 return v >= ProtocolVersion3 186 case DataTypeCodeDate: 187 return v >= ProtocolVersion4 188 case DataTypeCodeTime: 189 return v >= ProtocolVersion4 190 case DataTypeCodeSmallint: 191 return v >= ProtocolVersion4 192 case DataTypeCodeTinyint: 193 return v >= ProtocolVersion4 194 case DataTypeCodeDuration: 195 return v >= ProtocolVersion5 196 default: 197 // Unknown code 198 return false 199 } 200 return true 201 } 202 203 func (v ProtocolVersion) SupportsSchemaChangeTarget(target SchemaChangeTarget) bool { 204 switch target { 205 case SchemaChangeTargetKeyspace: 206 return true 207 case SchemaChangeTargetTable: 208 return true 209 case SchemaChangeTargetType: 210 return v >= ProtocolVersion3 211 case SchemaChangeTargetFunction: 212 return v >= ProtocolVersion4 213 case SchemaChangeTargetAggregate: 214 return v >= ProtocolVersion4 215 } 216 // Unknown target 217 return false 218 } 219 220 func (v ProtocolVersion) SupportsTopologyChangeType(t TopologyChangeType) bool { 221 switch t { 222 case TopologyChangeTypeNewNode: 223 return true 224 case TopologyChangeTypeRemovedNode: 225 return true 226 case TopologyChangeTypeMovedNode: 227 return v >= ProtocolVersion3 228 } 229 // Unknown type 230 return false 231 } 232 233 func (v ProtocolVersion) SupportsDseRevisionType(t DseRevisionType) bool { 234 switch t { 235 case DseRevisionTypeCancelContinuousPaging: 236 return v >= ProtocolVersionDse1 237 case DseRevisionTypeMoreContinuousPages: 238 return v >= ProtocolVersionDse2 239 } 240 // Unknown type 241 return false 242 } 243 244 const ( 245 FrameHeaderLengthV3AndHigher = 9 246 FrameHeaderLengthV2AndLower = 8 247 ) 248 249 func (v ProtocolVersion) FrameHeaderLengthInBytes() int { 250 if v >= ProtocolVersion3 { 251 return FrameHeaderLengthV3AndHigher 252 } else { 253 return FrameHeaderLengthV2AndLower 254 } 255 } 256 257 func (v ProtocolVersion) SupportsModernFramingLayout() bool { 258 return v >= ProtocolVersion5 && v != ProtocolVersionDse1 && v != ProtocolVersionDse2 259 } 260 261 func (v ProtocolVersion) SupportsUnsetValues() bool { 262 return v >= ProtocolVersion4 263 } 264 265 type OpCode uint8 266 267 // requests 268 const ( 269 OpCodeStartup = OpCode(0x01) 270 OpCodeOptions = OpCode(0x05) 271 OpCodeQuery = OpCode(0x07) 272 OpCodePrepare = OpCode(0x09) 273 OpCodeExecute = OpCode(0x0A) 274 OpCodeRegister = OpCode(0x0B) 275 OpCodeBatch = OpCode(0x0D) 276 OpCodeAuthResponse = OpCode(0x0F) 277 OpCodeDseRevise = OpCode(0xFF) // DSE v1 278 ) 279 280 // responses 281 const ( 282 OpCodeError = OpCode(0x00) 283 OpCodeReady = OpCode(0x02) 284 OpCodeAuthenticate = OpCode(0x03) 285 OpCodeSupported = OpCode(0x06) 286 OpCodeResult = OpCode(0x08) 287 OpCodeEvent = OpCode(0x0C) 288 OpCodeAuthChallenge = OpCode(0x0E) 289 OpCodeAuthSuccess = OpCode(0x10) 290 ) 291 292 func (c OpCode) IsValid() bool { 293 switch c { 294 case OpCodeStartup: 295 case OpCodeOptions: 296 case OpCodeQuery: 297 case OpCodePrepare: 298 case OpCodeExecute: 299 case OpCodeRegister: 300 case OpCodeBatch: 301 case OpCodeAuthResponse: 302 case OpCodeDseRevise: 303 case OpCodeError: 304 case OpCodeReady: 305 case OpCodeAuthenticate: 306 case OpCodeSupported: 307 case OpCodeResult: 308 case OpCodeEvent: 309 case OpCodeAuthChallenge: 310 case OpCodeAuthSuccess: 311 default: 312 return false 313 } 314 return true 315 } 316 317 func (c OpCode) IsRequest() bool { 318 switch c { 319 case OpCodeStartup: 320 case OpCodeOptions: 321 case OpCodeQuery: 322 case OpCodePrepare: 323 case OpCodeExecute: 324 case OpCodeRegister: 325 case OpCodeBatch: 326 case OpCodeAuthResponse: 327 case OpCodeDseRevise: 328 default: 329 return false 330 } 331 return true 332 } 333 334 func (c OpCode) IsResponse() bool { 335 switch c { 336 case OpCodeError: 337 case OpCodeReady: 338 case OpCodeAuthenticate: 339 case OpCodeSupported: 340 case OpCodeResult: 341 case OpCodeEvent: 342 case OpCodeAuthChallenge: 343 case OpCodeAuthSuccess: 344 default: 345 return false 346 } 347 return true 348 } 349 350 func (c OpCode) IsDse() bool { 351 switch c { 352 case OpCodeDseRevise: 353 default: 354 return false 355 } 356 return true 357 } 358 359 func (c OpCode) String() string { 360 switch c { 361 case OpCodeStartup: 362 return "OpCode STARTUP [0x01]" 363 case OpCodeOptions: 364 return "OpCode OPTIONS [0x05]" 365 case OpCodeQuery: 366 return "OpCode QUERY [0x07]" 367 case OpCodePrepare: 368 return "OpCode PREPARE [0x09]" 369 case OpCodeExecute: 370 return "OpCode EXECUTE [0x0A]" 371 case OpCodeRegister: 372 return "OpCode REGISTER [0x0B]" 373 case OpCodeBatch: 374 return "OpCode BATCH [0x0D]" 375 case OpCodeAuthResponse: 376 return "OpCode AUTH RESPONSE [0x0F]" 377 case OpCodeDseRevise: 378 return "OpCode REVISE [0xFF]" 379 // responses 380 case OpCodeError: 381 return "OpCode ERROR [0x00]" 382 case OpCodeReady: 383 return "OpCode READY [0x02]" 384 case OpCodeAuthenticate: 385 return "OpCode AUTHENTICATE [0x03]" 386 case OpCodeSupported: 387 return "OpCode SUPPORTED [0x06]" 388 case OpCodeResult: 389 return "OpCode RESULT [0x08]" 390 case OpCodeEvent: 391 return "OpCode EVENT [0x0C]" 392 case OpCodeAuthChallenge: 393 return "OpCode AUTH CHALLENGE [0x0E]" 394 case OpCodeAuthSuccess: 395 return "OpCode AUTH SUCCESS [0x10]" 396 } 397 return fmt.Sprintf("OpCode ? [%#.2X]", uint8(c)) 398 } 399 400 type ResultType uint32 401 402 const ( 403 ResultTypeVoid = ResultType(0x00000001) 404 ResultTypeRows = ResultType(0x00000002) 405 ResultTypeSetKeyspace = ResultType(0x00000003) 406 ResultTypePrepared = ResultType(0x00000004) 407 ResultTypeSchemaChange = ResultType(0x00000005) 408 ) 409 410 func (t ResultType) IsValid() bool { 411 switch t { 412 case ResultTypeVoid: 413 case ResultTypeRows: 414 case ResultTypeSetKeyspace: 415 case ResultTypePrepared: 416 case ResultTypeSchemaChange: 417 default: 418 return false 419 } 420 return true 421 } 422 423 func (t ResultType) String() string { 424 switch t { 425 case ResultTypeVoid: 426 return "ResultType Void [0x00000001]" 427 case ResultTypeRows: 428 return "ResultType Rows [0x00000002]" 429 case ResultTypeSetKeyspace: 430 return "ResultType SetKeyspace [0x00000003]" 431 case ResultTypePrepared: 432 return "ResultType Prepared [0x00000004]" 433 case ResultTypeSchemaChange: 434 return "ResultType SchemaChange [0x00000005]" 435 } 436 return fmt.Sprintf("ResultType ? [%#.8X]", uint32(t)) 437 } 438 439 type ErrorCode uint32 440 441 // 0xx: fatal errors 442 const ( 443 ErrorCodeServerError = ErrorCode(0x00000000) 444 ErrorCodeProtocolError = ErrorCode(0x0000000A) 445 ErrorCodeAuthenticationError = ErrorCode(0x00000100) 446 ) 447 448 // 1xx: request execution 449 const ( 450 ErrorCodeUnavailable = ErrorCode(0x00001000) 451 ErrorCodeOverloaded = ErrorCode(0x00001001) 452 ErrorCodeIsBootstrapping = ErrorCode(0x00001002) 453 ErrorCodeTruncateError = ErrorCode(0x00001003) 454 ErrorCodeWriteTimeout = ErrorCode(0x00001100) 455 ErrorCodeReadTimeout = ErrorCode(0x00001200) 456 ErrorCodeReadFailure = ErrorCode(0x00001300) 457 ErrorCodeFunctionFailure = ErrorCode(0x00001400) 458 ErrorCodeWriteFailure = ErrorCode(0x00001500) 459 ) 460 461 // 2xx: query validation 462 const ( 463 ErrorCodeSyntaxError = ErrorCode(0x00002000) 464 ErrorCodeUnauthorized = ErrorCode(0x00002100) 465 ErrorCodeInvalid = ErrorCode(0x00002200) 466 ErrorCodeConfigError = ErrorCode(0x00002300) 467 ErrorCodeAlreadyExists = ErrorCode(0x00002400) 468 ErrorCodeUnprepared = ErrorCode(0x00002500) 469 ) 470 471 func (c ErrorCode) IsValid() bool { 472 switch c { 473 case ErrorCodeServerError: 474 case ErrorCodeProtocolError: 475 case ErrorCodeAuthenticationError: 476 case ErrorCodeUnavailable: 477 case ErrorCodeOverloaded: 478 case ErrorCodeIsBootstrapping: 479 case ErrorCodeTruncateError: 480 case ErrorCodeWriteTimeout: 481 case ErrorCodeReadTimeout: 482 case ErrorCodeReadFailure: 483 case ErrorCodeFunctionFailure: 484 case ErrorCodeWriteFailure: 485 case ErrorCodeSyntaxError: 486 case ErrorCodeUnauthorized: 487 case ErrorCodeInvalid: 488 case ErrorCodeConfigError: 489 case ErrorCodeAlreadyExists: 490 case ErrorCodeUnprepared: 491 default: 492 return false 493 } 494 return true 495 } 496 497 func (c ErrorCode) IsFatalError() bool { 498 switch c { 499 case ErrorCodeServerError: 500 case ErrorCodeProtocolError: 501 case ErrorCodeAuthenticationError: 502 default: 503 return false 504 } 505 return true 506 } 507 508 func (c ErrorCode) IsRequestExecutionError() bool { 509 switch c { 510 case ErrorCodeUnavailable: 511 case ErrorCodeOverloaded: 512 case ErrorCodeIsBootstrapping: 513 case ErrorCodeTruncateError: 514 case ErrorCodeWriteTimeout: 515 case ErrorCodeReadTimeout: 516 case ErrorCodeReadFailure: 517 case ErrorCodeFunctionFailure: 518 case ErrorCodeWriteFailure: 519 default: 520 return false 521 } 522 return true 523 } 524 525 func (c ErrorCode) IsQueryValidationError() bool { 526 switch c { 527 case ErrorCodeSyntaxError: 528 case ErrorCodeUnauthorized: 529 case ErrorCodeInvalid: 530 case ErrorCodeConfigError: 531 case ErrorCodeAlreadyExists: 532 case ErrorCodeUnprepared: 533 default: 534 return false 535 } 536 return true 537 } 538 539 func (c ErrorCode) String() string { 540 switch c { 541 case ErrorCodeServerError: 542 return "ErrorCode ServerError [0x00000000]" 543 case ErrorCodeProtocolError: 544 return "ErrorCode ProtocolError [0x0000000A]" 545 case ErrorCodeAuthenticationError: 546 return "ErrorCode AuthenticationError [0x00000100]" 547 case ErrorCodeUnavailable: 548 return "ErrorCode Unavailable [0x00001000]" 549 case ErrorCodeOverloaded: 550 return "ErrorCode Overloaded [0x00001001]" 551 case ErrorCodeIsBootstrapping: 552 return "ErrorCode IsBootstrapping [0x00001002]" 553 case ErrorCodeTruncateError: 554 return "ErrorCode TruncateError [0x00001003]" 555 case ErrorCodeWriteTimeout: 556 return "ErrorCode WriteTimeout [0x00001100]" 557 case ErrorCodeReadTimeout: 558 return "ErrorCode ReadTimeout [0x00001200]" 559 case ErrorCodeReadFailure: 560 return "ErrorCode ReadFailure [0x00001300]" 561 case ErrorCodeFunctionFailure: 562 return "ErrorCode FunctionFailure [0x00001400]" 563 case ErrorCodeWriteFailure: 564 return "ErrorCode WriteFailure [0x00001500]" 565 case ErrorCodeSyntaxError: 566 return "ErrorCode SyntaxError [0x00002000]" 567 case ErrorCodeUnauthorized: 568 return "ErrorCode Unauthorized [0x00002100]" 569 case ErrorCodeInvalid: 570 return "ErrorCode Invalid [0x00002200]" 571 case ErrorCodeConfigError: 572 return "ErrorCode ConfigError [0x00002300]" 573 case ErrorCodeAlreadyExists: 574 return "ErrorCode AlreadyExists [0x00002400]" 575 case ErrorCodeUnprepared: 576 return "ErrorCode Unprepared [0x00002500]" 577 } 578 return fmt.Sprintf("ErrorCode ? [%#.8X]", uint32(c)) 579 } 580 581 // ConsistencyLevel corresponds to protocol section 3 [consistency] data type. 582 type ConsistencyLevel uint16 583 584 const ( 585 ConsistencyLevelAny = ConsistencyLevel(0x0000) 586 ConsistencyLevelOne = ConsistencyLevel(0x0001) 587 ConsistencyLevelTwo = ConsistencyLevel(0x0002) 588 ConsistencyLevelThree = ConsistencyLevel(0x0003) 589 ConsistencyLevelQuorum = ConsistencyLevel(0x0004) 590 ConsistencyLevelAll = ConsistencyLevel(0x0005) 591 ConsistencyLevelLocalQuorum = ConsistencyLevel(0x0006) 592 ConsistencyLevelEachQuorum = ConsistencyLevel(0x0007) 593 ConsistencyLevelSerial = ConsistencyLevel(0x0008) 594 ConsistencyLevelLocalSerial = ConsistencyLevel(0x0009) 595 ConsistencyLevelLocalOne = ConsistencyLevel(0x000A) 596 ) 597 598 func (c ConsistencyLevel) IsValid() bool { 599 switch c { 600 case ConsistencyLevelAny: 601 case ConsistencyLevelOne: 602 case ConsistencyLevelTwo: 603 case ConsistencyLevelThree: 604 case ConsistencyLevelQuorum: 605 case ConsistencyLevelAll: 606 case ConsistencyLevelLocalQuorum: 607 case ConsistencyLevelEachQuorum: 608 case ConsistencyLevelSerial: 609 case ConsistencyLevelLocalSerial: 610 case ConsistencyLevelLocalOne: 611 default: 612 return false 613 } 614 return true 615 } 616 617 func (c ConsistencyLevel) IsSerial() bool { 618 switch c { 619 case ConsistencyLevelSerial: 620 case ConsistencyLevelLocalSerial: 621 default: 622 return false 623 } 624 return true 625 } 626 627 func (c ConsistencyLevel) IsNonSerial() bool { 628 switch c { 629 case ConsistencyLevelAny: 630 case ConsistencyLevelOne: 631 case ConsistencyLevelTwo: 632 case ConsistencyLevelThree: 633 case ConsistencyLevelQuorum: 634 case ConsistencyLevelAll: 635 case ConsistencyLevelLocalQuorum: 636 case ConsistencyLevelEachQuorum: 637 case ConsistencyLevelLocalOne: 638 default: 639 return false 640 } 641 return true 642 } 643 644 func (c ConsistencyLevel) IsLocal() bool { 645 switch c { 646 case ConsistencyLevelLocalQuorum: 647 case ConsistencyLevelLocalSerial: 648 case ConsistencyLevelLocalOne: 649 default: 650 return false 651 } 652 return true 653 } 654 655 func (c ConsistencyLevel) IsNonLocal() bool { 656 switch c { 657 case ConsistencyLevelAny: 658 case ConsistencyLevelOne: 659 case ConsistencyLevelTwo: 660 case ConsistencyLevelThree: 661 case ConsistencyLevelQuorum: 662 case ConsistencyLevelAll: 663 case ConsistencyLevelEachQuorum: 664 case ConsistencyLevelSerial: 665 default: 666 return false 667 } 668 return true 669 } 670 671 func (c ConsistencyLevel) String() string { 672 switch c { 673 case ConsistencyLevelAny: 674 return "ConsistencyLevel ANY [0x0000]" 675 case ConsistencyLevelOne: 676 return "ConsistencyLevel ONE [0x0001]" 677 case ConsistencyLevelTwo: 678 return "ConsistencyLevel TWO [0x0002]" 679 case ConsistencyLevelThree: 680 return "ConsistencyLevel THREE [0x0003]" 681 case ConsistencyLevelQuorum: 682 return "ConsistencyLevel QUORUM [0x0004]" 683 case ConsistencyLevelAll: 684 return "ConsistencyLevel ALL [0x0005]" 685 case ConsistencyLevelLocalQuorum: 686 return "ConsistencyLevel LOCAL_QUORUM [0x0006]" 687 case ConsistencyLevelEachQuorum: 688 return "ConsistencyLevel EACH_QUORUM [0x0007]" 689 case ConsistencyLevelSerial: 690 return "ConsistencyLevel SERIAL [0x0008]" 691 case ConsistencyLevelLocalSerial: 692 return "ConsistencyLevel LOCAL_SERIAL [0x0009]" 693 case ConsistencyLevelLocalOne: 694 return "ConsistencyLevel LOCAL_ONE [0x000A]" 695 } 696 return fmt.Sprintf("ConsistencyLevel ? [%#.4X]", uint16(c)) 697 } 698 699 type WriteType string 700 701 const ( 702 WriteTypeSimple = WriteType("SIMPLE") 703 WriteTypeBatch = WriteType("BATCH") 704 WriteTypeUnloggedBatch = WriteType("UNLOGGED_BATCH") 705 WriteTypeCounter = WriteType("COUNTER") 706 WriteTypeBatchLog = WriteType("BATCH_LOG") 707 WriteTypeCas = WriteType("CAS") 708 WriteTypeView = WriteType("VIEW") 709 WriteTypeCdc = WriteType("CDC") 710 ) 711 712 func (t WriteType) IsValid() bool { 713 switch t { 714 case WriteTypeSimple: 715 case WriteTypeBatch: 716 case WriteTypeUnloggedBatch: 717 case WriteTypeCounter: 718 case WriteTypeBatchLog: 719 case WriteTypeView: 720 case WriteTypeCdc: 721 default: 722 return false 723 } 724 return true 725 } 726 727 type DataTypeCode uint16 728 729 const ( 730 DataTypeCodeCustom = DataTypeCode(0x0000) 731 DataTypeCodeAscii = DataTypeCode(0x0001) 732 DataTypeCodeBigint = DataTypeCode(0x0002) 733 DataTypeCodeBlob = DataTypeCode(0x0003) 734 DataTypeCodeBoolean = DataTypeCode(0x0004) 735 DataTypeCodeCounter = DataTypeCode(0x0005) 736 DataTypeCodeDecimal = DataTypeCode(0x0006) 737 DataTypeCodeDouble = DataTypeCode(0x0007) 738 DataTypeCodeFloat = DataTypeCode(0x0008) 739 DataTypeCodeInt = DataTypeCode(0x0009) 740 DataTypeCodeText = DataTypeCode(0x000A) // removed in v3, alias for DataTypeCodeVarchar 741 DataTypeCodeTimestamp = DataTypeCode(0x000B) 742 DataTypeCodeUuid = DataTypeCode(0x000C) 743 DataTypeCodeVarchar = DataTypeCode(0x000D) 744 DataTypeCodeVarint = DataTypeCode(0x000E) 745 DataTypeCodeTimeuuid = DataTypeCode(0x000F) 746 DataTypeCodeInet = DataTypeCode(0x0010) 747 DataTypeCodeDate = DataTypeCode(0x0011) // v4+ 748 DataTypeCodeTime = DataTypeCode(0x0012) // v4+ 749 DataTypeCodeSmallint = DataTypeCode(0x0013) // v4+ 750 DataTypeCodeTinyint = DataTypeCode(0x0014) // v4+ 751 DataTypeCodeDuration = DataTypeCode(0x0015) // v5, DSE v1 and DSE v2 752 DataTypeCodeList = DataTypeCode(0x0020) 753 DataTypeCodeMap = DataTypeCode(0x0021) 754 DataTypeCodeSet = DataTypeCode(0x0022) 755 DataTypeCodeUdt = DataTypeCode(0x0030) // v3+ 756 DataTypeCodeTuple = DataTypeCode(0x0031) // v3+ 757 ) 758 759 func (c DataTypeCode) IsValid() bool { 760 switch c { 761 case DataTypeCodeCustom: 762 case DataTypeCodeAscii: 763 case DataTypeCodeBigint: 764 case DataTypeCodeBlob: 765 case DataTypeCodeBoolean: 766 case DataTypeCodeCounter: 767 case DataTypeCodeDecimal: 768 case DataTypeCodeDouble: 769 case DataTypeCodeFloat: 770 case DataTypeCodeInt: 771 case DataTypeCodeText: 772 case DataTypeCodeTimestamp: 773 case DataTypeCodeUuid: 774 case DataTypeCodeVarchar: 775 case DataTypeCodeVarint: 776 case DataTypeCodeTimeuuid: 777 case DataTypeCodeInet: 778 case DataTypeCodeDate: 779 case DataTypeCodeTime: 780 case DataTypeCodeSmallint: 781 case DataTypeCodeTinyint: 782 case DataTypeCodeDuration: 783 case DataTypeCodeList: 784 case DataTypeCodeMap: 785 case DataTypeCodeSet: 786 case DataTypeCodeUdt: 787 case DataTypeCodeTuple: 788 default: 789 return false 790 } 791 return true 792 } 793 794 func (c DataTypeCode) IsPrimitive() bool { 795 switch c { 796 case DataTypeCodeCustom: 797 case DataTypeCodeAscii: 798 case DataTypeCodeBigint: 799 case DataTypeCodeBlob: 800 case DataTypeCodeBoolean: 801 case DataTypeCodeCounter: 802 case DataTypeCodeDecimal: 803 case DataTypeCodeDouble: 804 case DataTypeCodeFloat: 805 case DataTypeCodeInt: 806 case DataTypeCodeText: 807 case DataTypeCodeTimestamp: 808 case DataTypeCodeUuid: 809 case DataTypeCodeVarchar: 810 case DataTypeCodeVarint: 811 case DataTypeCodeTimeuuid: 812 case DataTypeCodeInet: 813 case DataTypeCodeDate: 814 case DataTypeCodeTime: 815 case DataTypeCodeSmallint: 816 case DataTypeCodeTinyint: 817 case DataTypeCodeDuration: 818 default: 819 return false 820 } 821 return true 822 } 823 824 func (c DataTypeCode) String() string { 825 switch c { 826 case DataTypeCodeCustom: 827 return "DataTypeCode Custom [0x0000]" 828 case DataTypeCodeAscii: 829 return "DataTypeCode Ascii [0x0001]" 830 case DataTypeCodeBigint: 831 return "DataTypeCode Bigint [0x0002]" 832 case DataTypeCodeBlob: 833 return "DataTypeCode Blob [0x0003]" 834 case DataTypeCodeBoolean: 835 return "DataTypeCode Boolean [0x0004]" 836 case DataTypeCodeCounter: 837 return "DataTypeCode Counter [0x0005]" 838 case DataTypeCodeDecimal: 839 return "DataTypeCode Decimal [0x0006]" 840 case DataTypeCodeDouble: 841 return "DataTypeCode Double [0x0007]" 842 case DataTypeCodeFloat: 843 return "DataTypeCode Float [0x0008]" 844 case DataTypeCodeInt: 845 return "DataTypeCode Int [0x0009]" 846 case DataTypeCodeText: 847 return "DataTypeCode Text [0x000A]" 848 case DataTypeCodeTimestamp: 849 return "DataTypeCode Timestamp [0x000B]" 850 case DataTypeCodeUuid: 851 return "DataTypeCode Uuid [0x000C]" 852 case DataTypeCodeVarchar: 853 return "DataTypeCode Varchar [0x000D]" 854 case DataTypeCodeVarint: 855 return "DataTypeCode Varint [0x000E]" 856 case DataTypeCodeTimeuuid: 857 return "DataTypeCode Timeuuid [0x000F]" 858 case DataTypeCodeInet: 859 return "DataTypeCode Inet [0x0010]" 860 case DataTypeCodeDate: 861 return "DataTypeCode Date [0x0011]" 862 case DataTypeCodeTime: 863 return "DataTypeCode Time [0x0012]" 864 case DataTypeCodeSmallint: 865 return "DataTypeCode Smallint [0x0013]" 866 case DataTypeCodeTinyint: 867 return "DataTypeCode Tinyint [0x0014]" 868 case DataTypeCodeDuration: 869 return "DataTypeCode Duration [0x0015]" 870 case DataTypeCodeList: 871 return "DataTypeCode List [0x0020]" 872 case DataTypeCodeMap: 873 return "DataTypeCode Map [0x0021]" 874 case DataTypeCodeSet: 875 return "DataTypeCode Set [0x0022]" 876 case DataTypeCodeUdt: 877 return "DataTypeCode Udt [0x0030]" 878 case DataTypeCodeTuple: 879 return "DataTypeCode Tuple [0x0031]" 880 } 881 return fmt.Sprintf("DataType ? [%#.4X]", uint16(c)) 882 } 883 884 type EventType string 885 886 const ( 887 EventTypeTopologyChange = EventType("TOPOLOGY_CHANGE") 888 EventTypeStatusChange = EventType("STATUS_CHANGE") 889 EventTypeSchemaChange = EventType("SCHEMA_CHANGE") 890 ) 891 892 func (e EventType) IsValid() bool { 893 switch e { 894 case EventTypeSchemaChange: 895 case EventTypeTopologyChange: 896 case EventTypeStatusChange: 897 default: 898 return false 899 } 900 return true 901 } 902 903 type SchemaChangeType string 904 905 const ( 906 SchemaChangeTypeCreated = SchemaChangeType("CREATED") 907 SchemaChangeTypeUpdated = SchemaChangeType("UPDATED") 908 SchemaChangeTypeDropped = SchemaChangeType("DROPPED") 909 ) 910 911 func (t SchemaChangeType) IsValid() bool { 912 switch t { 913 case SchemaChangeTypeCreated: 914 case SchemaChangeTypeUpdated: 915 case SchemaChangeTypeDropped: 916 default: 917 return false 918 } 919 return true 920 } 921 922 type SchemaChangeTarget string 923 924 const ( 925 SchemaChangeTargetKeyspace = SchemaChangeTarget("KEYSPACE") 926 SchemaChangeTargetTable = SchemaChangeTarget("TABLE") 927 SchemaChangeTargetType = SchemaChangeTarget("TYPE") // v3+ 928 SchemaChangeTargetFunction = SchemaChangeTarget("FUNCTION") // v3+ 929 SchemaChangeTargetAggregate = SchemaChangeTarget("AGGREGATE") // v3+ 930 ) 931 932 func (t SchemaChangeTarget) IsValid() bool { 933 switch t { 934 case SchemaChangeTargetKeyspace: 935 case SchemaChangeTargetTable: 936 case SchemaChangeTargetType: 937 case SchemaChangeTargetFunction: 938 case SchemaChangeTargetAggregate: 939 default: 940 return false 941 } 942 return true 943 } 944 945 type TopologyChangeType string 946 947 const ( 948 TopologyChangeTypeNewNode = TopologyChangeType("NEW_NODE") 949 TopologyChangeTypeRemovedNode = TopologyChangeType("REMOVED_NODE") 950 TopologyChangeTypeMovedNode = TopologyChangeType("MOVED_NODE") // v3+ 951 ) 952 953 func (t TopologyChangeType) IsValid() bool { 954 switch t { 955 case TopologyChangeTypeNewNode: 956 case TopologyChangeTypeRemovedNode: 957 case TopologyChangeTypeMovedNode: 958 default: 959 return false 960 } 961 return true 962 } 963 964 type StatusChangeType string 965 966 const ( 967 StatusChangeTypeUp = StatusChangeType("UP") 968 StatusChangeTypeDown = StatusChangeType("DOWN") 969 ) 970 971 func (t StatusChangeType) IsValid() bool { 972 switch t { 973 case StatusChangeTypeUp: 974 case StatusChangeTypeDown: 975 default: 976 return false 977 } 978 return true 979 } 980 981 type BatchType uint8 982 983 const ( 984 BatchTypeLogged = BatchType(0x00) 985 BatchTypeUnlogged = BatchType(0x01) 986 BatchTypeCounter = BatchType(0x02) 987 ) 988 989 func (t BatchType) IsValid() bool { 990 switch t { 991 case BatchTypeLogged: 992 case BatchTypeUnlogged: 993 case BatchTypeCounter: 994 default: 995 return false 996 } 997 return true 998 } 999 1000 func (t BatchType) String() string { 1001 switch t { 1002 case BatchTypeLogged: 1003 return "BatchType LOGGED [0x00]" 1004 case BatchTypeUnlogged: 1005 return "BatchType UNLOGGED [0x01]" 1006 case BatchTypeCounter: 1007 return "BatchType COUNTER [0x02]" 1008 } 1009 return fmt.Sprintf("BatchType ? [%#.2X]", uint8(t)) 1010 } 1011 1012 type BatchChildType uint8 1013 1014 const ( 1015 BatchChildTypeQueryString = BatchChildType(0x00) 1016 BatchChildTypePreparedId = BatchChildType(0x01) 1017 ) 1018 1019 func (t BatchChildType) IsValid() bool { 1020 switch t { 1021 case BatchChildTypeQueryString: 1022 case BatchChildTypePreparedId: 1023 default: 1024 return false 1025 } 1026 return true 1027 } 1028 1029 func (t BatchChildType) String() string { 1030 switch t { 1031 case BatchChildTypeQueryString: 1032 return "BatchChildType QueryString [0x00]" 1033 case BatchChildTypePreparedId: 1034 return "BatchChildType PreparedId [0x01]" 1035 } 1036 return fmt.Sprintf("BatchChildType ? [%#.2X]", uint8(t)) 1037 } 1038 1039 type HeaderFlag uint8 1040 1041 const ( 1042 HeaderFlagCompressed = HeaderFlag(0x01) 1043 HeaderFlagTracing = HeaderFlag(0x02) 1044 HeaderFlagCustomPayload = HeaderFlag(0x04) 1045 HeaderFlagWarning = HeaderFlag(0x08) 1046 HeaderFlagUseBeta = HeaderFlag(0x10) 1047 ) 1048 1049 func (f HeaderFlag) Add(other HeaderFlag) HeaderFlag { 1050 return f | other 1051 } 1052 1053 func (f HeaderFlag) Remove(other HeaderFlag) HeaderFlag { 1054 return f &^ other 1055 } 1056 1057 func (f HeaderFlag) Contains(other HeaderFlag) bool { 1058 return f&other != 0 1059 } 1060 1061 func (f HeaderFlag) String() string { 1062 switch f { 1063 case HeaderFlagCompressed: 1064 return fmt.Sprintf("HeaderFlag Compressed [0x01 %#.8b]", f) 1065 case HeaderFlagTracing: 1066 return fmt.Sprintf("HeaderFlag Tracing [0x02 %#.8b]", f) 1067 case HeaderFlagCustomPayload: 1068 return fmt.Sprintf("HeaderFlag CustomPayload [0x04 %#.8b]", f) 1069 case HeaderFlagWarning: 1070 return fmt.Sprintf("HeaderFlag Warning [0x08 %#.8b]", f) 1071 case HeaderFlagUseBeta: 1072 return fmt.Sprintf("HeaderFlag UseBeta [0x10 %#.8b]", f) 1073 } 1074 return fmt.Sprintf("HeaderFlag ? [%#.2X %#.8b]", uint8(f), uint8(f)) 1075 } 1076 1077 // QueryFlag was encoded as [byte] in v3 and v4, but changed to [int] in v5. 1078 type QueryFlag uint32 1079 1080 const ( 1081 QueryFlagValues = QueryFlag(0x00000001) 1082 QueryFlagSkipMetadata = QueryFlag(0x00000002) 1083 QueryFlagPageSize = QueryFlag(0x00000004) 1084 QueryFlagPagingState = QueryFlag(0x00000008) 1085 QueryFlagSerialConsistency = QueryFlag(0x00000010) 1086 QueryFlagDefaultTimestamp = QueryFlag(0x00000020) 1087 QueryFlagValueNames = QueryFlag(0x00000040) 1088 QueryFlagWithKeyspace = QueryFlag(0x00000080) // protocol v5+ and DSE v2 1089 QueryFlagNowInSeconds = QueryFlag(0x00000100) // protocol v5+ 1090 ) 1091 1092 // DSE-specific query flags 1093 const ( 1094 QueryFlagDsePageSizeBytes = QueryFlag(0x40000000) // DSE v1+ 1095 QueryFlagDseWithContinuousPagingOptions = QueryFlag(0x80000000) // DSE v1+ 1096 ) 1097 1098 func (f QueryFlag) Add(other QueryFlag) QueryFlag { 1099 return f | other 1100 } 1101 1102 func (f QueryFlag) Remove(other QueryFlag) QueryFlag { 1103 return f &^ other 1104 } 1105 1106 func (f QueryFlag) Contains(other QueryFlag) bool { 1107 return f&other != 0 1108 } 1109 1110 func (f QueryFlag) String() string { 1111 switch f { 1112 case QueryFlagValues: 1113 return fmt.Sprintf("QueryFlag Values [0x00000001 %#.32b]", f) 1114 case QueryFlagSkipMetadata: 1115 return fmt.Sprintf("QueryFlag SkipMetadata [0x00000002 %#.32b]", f) 1116 case QueryFlagPageSize: 1117 return fmt.Sprintf("QueryFlag PageSize [0x00000004 %#.32b]", f) 1118 case QueryFlagPagingState: 1119 return fmt.Sprintf("QueryFlag PagingState [0x00000008 %#.32b]", f) 1120 case QueryFlagSerialConsistency: 1121 return fmt.Sprintf("QueryFlag SerialConsistency [0x00000010 %#.32b]", f) 1122 case QueryFlagDefaultTimestamp: 1123 return fmt.Sprintf("QueryFlag DefaultTimestamp [0x00000020 %#.32b]", f) 1124 case QueryFlagValueNames: 1125 return fmt.Sprintf("QueryFlag ValueNames [0x00000040 %#.32b]", f) 1126 case QueryFlagWithKeyspace: 1127 return fmt.Sprintf("QueryFlag WithKeyspace [0x00000080 %#.32b]", f) 1128 case QueryFlagNowInSeconds: 1129 return fmt.Sprintf("QueryFlag NowInSeconds [0x00000100 %#.32b]", f) 1130 case QueryFlagDsePageSizeBytes: 1131 return fmt.Sprintf("QueryFlag DsePageSizeBytes [0x40000000 %#.32b]", f) 1132 case QueryFlagDseWithContinuousPagingOptions: 1133 return fmt.Sprintf("QueryFlag DseWithContinuousPagingOptions [0x80000000 %#.32b]", f) 1134 } 1135 return fmt.Sprintf("QueryFlag ? [%#.8X %#.32b]", uint32(f), uint32(f)) 1136 } 1137 1138 type RowsFlag uint32 1139 1140 const ( 1141 RowsFlagGlobalTablesSpec = RowsFlag(0x00000001) 1142 RowsFlagHasMorePages = RowsFlag(0x00000002) 1143 RowsFlagNoMetadata = RowsFlag(0x00000004) 1144 RowsFlagMetadataChanged = RowsFlag(0x00000008) 1145 ) 1146 1147 // DSE-specific rows flags 1148 const ( 1149 RowsFlagDseContinuousPaging = RowsFlag(0x40000000) // DSE v1+ 1150 RowsFlagDseLastContinuousPage = RowsFlag(0x80000000) // DSE v1+ 1151 ) 1152 1153 func (f RowsFlag) Add(other RowsFlag) RowsFlag { 1154 return f | other 1155 } 1156 1157 func (f RowsFlag) Remove(other RowsFlag) RowsFlag { 1158 return f &^ other 1159 } 1160 1161 func (f RowsFlag) Contains(other RowsFlag) bool { 1162 return f&other != 0 1163 } 1164 1165 func (f RowsFlag) String() string { 1166 switch f { 1167 case RowsFlagGlobalTablesSpec: 1168 return fmt.Sprintf("RowsFlag GlobalTablesSpec [0x00000001 %#.32b]", f) 1169 case RowsFlagHasMorePages: 1170 return fmt.Sprintf("RowsFlag HasMorePages [0x00000002 %#.32b]", f) 1171 case RowsFlagNoMetadata: 1172 return fmt.Sprintf("RowsFlag NoMetadata [0x00000004 %#.32b]", f) 1173 case RowsFlagMetadataChanged: 1174 return fmt.Sprintf("RowsFlag MetadataChanged [0x00000008 %#.32b]", f) 1175 // DSE-specific flags 1176 case RowsFlagDseContinuousPaging: 1177 return fmt.Sprintf("RowsFlag ContinuousPaging [0x40000000 %#.32b]", f) 1178 case RowsFlagDseLastContinuousPage: 1179 return fmt.Sprintf("RowsFlag LastContinuousPage [0x80000000 %#.32b]", f) 1180 } 1181 return fmt.Sprintf("RowsFlag ? [%#.8X %#.32b]", uint32(f), uint32(f)) 1182 } 1183 1184 type VariablesFlag uint32 1185 1186 const ( 1187 VariablesFlagGlobalTablesSpec = VariablesFlag(0x00000001) 1188 ) 1189 1190 func (f VariablesFlag) Add(other VariablesFlag) VariablesFlag { 1191 return f | other 1192 } 1193 1194 func (f VariablesFlag) Remove(other VariablesFlag) VariablesFlag { 1195 return f &^ other 1196 } 1197 1198 func (f VariablesFlag) Contains(other VariablesFlag) bool { 1199 return f&other != 0 1200 } 1201 1202 func (f VariablesFlag) String() string { 1203 switch f { 1204 case VariablesFlagGlobalTablesSpec: 1205 return fmt.Sprintf("VariablesFlag GlobalTablesSpec [0x00000001 %#.32b]", f) 1206 } 1207 return fmt.Sprintf("VariablesFlag ? [%#.8X %#.32b]", uint32(f), uint32(f)) 1208 } 1209 1210 type PrepareFlag uint32 1211 1212 const ( 1213 PrepareFlagWithKeyspace = PrepareFlag(0x00000001) // v5 and DSE v2 1214 ) 1215 1216 func (f PrepareFlag) Add(other PrepareFlag) PrepareFlag { 1217 return f | other 1218 } 1219 1220 func (f PrepareFlag) Remove(other PrepareFlag) PrepareFlag { 1221 return f &^ other 1222 } 1223 1224 func (f PrepareFlag) Contains(other PrepareFlag) bool { 1225 return f&other != 0 1226 } 1227 1228 func (f PrepareFlag) String() string { 1229 switch f { 1230 case PrepareFlagWithKeyspace: 1231 return fmt.Sprintf("PrepareFlag WithKeyspace [0x00000001 %#.32b]", f) 1232 } 1233 return fmt.Sprintf("PrepareFlag ? [%#.8X %#.32b]", uint32(f), uint32(f)) 1234 } 1235 1236 type DseRevisionType uint32 1237 1238 const ( 1239 DseRevisionTypeCancelContinuousPaging = DseRevisionType(0x00000001) 1240 DseRevisionTypeMoreContinuousPages = DseRevisionType(0x00000002) // DSE v2+ 1241 ) 1242 1243 func (t DseRevisionType) IsValid() bool { 1244 switch t { 1245 case DseRevisionTypeCancelContinuousPaging: 1246 case DseRevisionTypeMoreContinuousPages: 1247 default: 1248 return false 1249 } 1250 return true 1251 } 1252 1253 func (t DseRevisionType) String() string { 1254 switch t { 1255 case DseRevisionTypeCancelContinuousPaging: 1256 return "DseRevisionType CancelContinuousPaging [0x00000001]" 1257 case DseRevisionTypeMoreContinuousPages: 1258 return "DseRevisionType MoreContinuousPages [0x00000002]" 1259 } 1260 return fmt.Sprintf("DseRevisionType ? [%#.8X]", uint32(t)) 1261 } 1262 1263 type FailureCode uint16 1264 1265 const ( 1266 FailureCodeUnknown = FailureCode(0x0000) 1267 FailureCodeTooManyTombstonesRead = FailureCode(0x0001) 1268 FailureCodeIndexNotAvailable = FailureCode(0x0002) 1269 FailureCodeCdcSpaceFull = FailureCode(0x0003) 1270 FailureCodeCounterWrite = FailureCode(0x0004) 1271 FailureCodeTableNotFound = FailureCode(0x0005) 1272 FailureCodeKeyspaceNotFound = FailureCode(0x0006) 1273 ) 1274 1275 func (c FailureCode) IsValid() bool { 1276 switch c { 1277 case FailureCodeUnknown: 1278 case FailureCodeTooManyTombstonesRead: 1279 case FailureCodeIndexNotAvailable: 1280 case FailureCodeCdcSpaceFull: 1281 case FailureCodeCounterWrite: 1282 case FailureCodeTableNotFound: 1283 case FailureCodeKeyspaceNotFound: 1284 default: 1285 return false 1286 } 1287 return true 1288 } 1289 1290 func (c FailureCode) String() string { 1291 switch c { 1292 case FailureCodeUnknown: 1293 return "FailureCode Unknown [0x0000]" 1294 case FailureCodeTooManyTombstonesRead: 1295 return "FailureCode TooManyTombstonesRead [0x0001]" 1296 case FailureCodeIndexNotAvailable: 1297 return "FailureCode IndexNotAvailable [0x0002]" 1298 case FailureCodeCdcSpaceFull: 1299 return "FailureCode CdcSpaceFull [0x0003]" 1300 case FailureCodeCounterWrite: 1301 return "FailureCode CounterWrite [0x0004]" 1302 case FailureCodeTableNotFound: 1303 return "FailureCode TableNotFound [0x0005]" 1304 case FailureCodeKeyspaceNotFound: 1305 return "FailureCode KeyspaceNotFound [0x0006]" 1306 } 1307 return fmt.Sprintf("FailureCode ? [%#.4X]", uint16(c)) 1308 } 1309 1310 type Compression string 1311 1312 const ( 1313 CompressionNone Compression = "NONE" 1314 CompressionLz4 Compression = "LZ4" 1315 CompressionSnappy Compression = "SNAPPY" 1316 ) 1317 1318 func (c Compression) IsValid() bool { 1319 switch c { 1320 case CompressionNone: 1321 case CompressionLz4: 1322 case CompressionSnappy: 1323 default: 1324 return false 1325 } 1326 return true 1327 }