sfc-gh-mbojanczyk commented on code in PR #344:
URL: https://github.com/apache/arrow-go/pull/344#discussion_r2054810924


##########
parquet/variants/util.go:
##########
@@ -0,0 +1,154 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package variants
+
+import (
+       "fmt"
+       "io"
+       "reflect"
+       "time"
+)
+
+// Reads a little-endian encoded uint (betwen 1 and 8 bytes wide) from a raw 
buffer at a specified
+// offset and returns its value. If any part of the read would be out of 
bounds, this returns an error.
+func readUint(raw []byte, offset, size int) (uint64, error) {
+       if size < 1 || size > 8 {
+               return 0, fmt.Errorf("invalid size, must be in range [1,8]: 
%d", size)
+       }
+       if maxPos := offset + size; maxPos > len(raw) {
+               return 0, fmt.Errorf("out of bounds: trying to access position 
%d, max position is %d", maxPos, len(raw))
+       }
+       var ret uint64
+       for i := range size {
+               ret |= uint64(raw[i+offset]) << (8 * i)
+       }
+       return ret, nil
+}

Review Comment:
   The unfortunate bit here: we need to handle uints of varying widths from 1-8 
bytes, but the `binary` package expects things of a set width (eg. `Uint64()` 
wants to [read 8 
bytes](https://cs.opensource.google/go/go/+/refs/tags/go1.24.2:src/encoding/binary/binary.go;l=115-119)
 always, so that would panic for anything smaller).
   
   So as-is, `binary` can't really handle all the different widths we need to 
here, which is why I rolled my own.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to