github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/s3select/genmessage.go (about) 1 //go:build ignore 2 // +build ignore 3 4 // Copyright (c) 2015-2021 MinIO, Inc. 5 // 6 // This file is part of MinIO Object Storage stack 7 // 8 // This program is free software: you can redistribute it and/or modify 9 // it under the terms of the GNU Affero General Public License as published by 10 // the Free Software Foundation, either version 3 of the License, or 11 // (at your option) any later version. 12 // 13 // This program is distributed in the hope that it will be useful 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 // GNU Affero General Public License for more details. 17 // 18 // You should have received a copy of the GNU Affero General Public License 19 // along with this program. If not, see <http://www.gnu.org/licenses/>. 20 21 package s3select 22 23 import ( 24 "bytes" 25 "encoding/binary" 26 "fmt" 27 "hash/crc32" 28 ) 29 30 func genRecordsHeader() { 31 buf := new(bytes.Buffer) 32 33 buf.WriteByte(13) 34 buf.WriteString(":message-type") 35 buf.WriteByte(7) 36 buf.Write([]byte{0, 5}) 37 buf.WriteString("event") 38 39 buf.WriteByte(13) 40 buf.WriteString(":content-type") 41 buf.WriteByte(7) 42 buf.Write([]byte{0, 24}) 43 buf.WriteString("application/octet-stream") 44 45 buf.WriteByte(11) 46 buf.WriteString(":event-type") 47 buf.WriteByte(7) 48 buf.Write([]byte{0, 7}) 49 buf.WriteString("Records") 50 51 fmt.Println(buf.Bytes()) 52 } 53 54 // Continuation Message 55 // ==================== 56 // Header specification 57 // -------------------- 58 // Continuation messages contain two headers, as follows: 59 // https://docs.aws.amazon.com/AmazonS3/latest/API/images/s3select-frame-diagram-cont.png 60 // 61 // Payload specification 62 // --------------------- 63 // Continuation messages have no payload. 64 func genContinuationMessage() { 65 buf := new(bytes.Buffer) 66 67 buf.WriteByte(13) 68 buf.WriteString(":message-type") 69 buf.WriteByte(7) 70 buf.Write([]byte{0, 5}) 71 buf.WriteString("event") 72 73 buf.WriteByte(11) 74 buf.WriteString(":event-type") 75 buf.WriteByte(7) 76 buf.Write([]byte{0, 4}) 77 buf.WriteString("Cont") 78 79 header := buf.Bytes() 80 headerLength := len(header) 81 payloadLength := 0 82 totalLength := totalByteLength(headerLength, payloadLength) 83 84 buf = new(bytes.Buffer) 85 binary.Write(buf, binary.BigEndian, uint32(totalLength)) 86 binary.Write(buf, binary.BigEndian, uint32(headerLength)) 87 prelude := buf.Bytes() 88 binary.Write(buf, binary.BigEndian, crc32.ChecksumIEEE(prelude)) 89 buf.Write(header) 90 message := buf.Bytes() 91 binary.Write(buf, binary.BigEndian, crc32.ChecksumIEEE(message)) 92 93 fmt.Println(buf.Bytes()) 94 } 95 96 func genProgressHeader() { 97 buf := new(bytes.Buffer) 98 99 buf.WriteByte(13) 100 buf.WriteString(":message-type") 101 buf.WriteByte(7) 102 buf.Write([]byte{0, 5}) 103 buf.WriteString("event") 104 105 buf.WriteByte(13) 106 buf.WriteString(":content-type") 107 buf.WriteByte(7) 108 buf.Write([]byte{0, 8}) 109 buf.WriteString("text/xml") 110 111 buf.WriteByte(11) 112 buf.WriteString(":event-type") 113 buf.WriteByte(7) 114 buf.Write([]byte{0, 8}) 115 buf.WriteString("Progress") 116 117 fmt.Println(buf.Bytes()) 118 } 119 120 func genStatsHeader() { 121 buf := new(bytes.Buffer) 122 123 buf.WriteByte(13) 124 buf.WriteString(":message-type") 125 buf.WriteByte(7) 126 buf.Write([]byte{0, 5}) 127 buf.WriteString("event") 128 129 buf.WriteByte(13) 130 buf.WriteString(":content-type") 131 buf.WriteByte(7) 132 buf.Write([]byte{0, 8}) 133 buf.WriteString("text/xml") 134 135 buf.WriteByte(11) 136 buf.WriteString(":event-type") 137 buf.WriteByte(7) 138 buf.Write([]byte{0, 5}) 139 buf.WriteString("Stats") 140 141 fmt.Println(buf.Bytes()) 142 } 143 144 // End Message 145 // =========== 146 // Header specification 147 // -------------------- 148 // End messages contain two headers, as follows: 149 // https://docs.aws.amazon.com/AmazonS3/latest/API/images/s3select-frame-diagram-end.png 150 // 151 // Payload specification 152 // --------------------- 153 // End messages have no payload. 154 func genEndMessage() { 155 buf := new(bytes.Buffer) 156 157 buf.WriteByte(13) 158 buf.WriteString(":message-type") 159 buf.WriteByte(7) 160 buf.Write([]byte{0, 5}) 161 buf.WriteString("event") 162 163 buf.WriteByte(11) 164 buf.WriteString(":event-type") 165 buf.WriteByte(7) 166 buf.Write([]byte{0, 3}) 167 buf.WriteString("End") 168 169 header := buf.Bytes() 170 headerLength := len(header) 171 payloadLength := 0 172 totalLength := totalByteLength(headerLength, payloadLength) 173 174 buf = new(bytes.Buffer) 175 binary.Write(buf, binary.BigEndian, uint32(totalLength)) 176 binary.Write(buf, binary.BigEndian, uint32(headerLength)) 177 prelude := buf.Bytes() 178 binary.Write(buf, binary.BigEndian, crc32.ChecksumIEEE(prelude)) 179 buf.Write(header) 180 message := buf.Bytes() 181 binary.Write(buf, binary.BigEndian, crc32.ChecksumIEEE(message)) 182 183 fmt.Println(buf.Bytes()) 184 }