sfc-gh-mbojanczyk commented on code in PR #344: URL: https://github.com/apache/arrow-go/pull/344#discussion_r2064760350
########## 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 subtlety here: you need to be able to decode things of widths 1-8 _inclusive_. For example, the [field offset size](https://github.com/apache/parquet-format/blob/master/VariantEncoding.md#value-header-for-object-basic_type2) of an object can be 1, 2, 3, or 4 bytes. `binary.Decode` can handle the 1, 2, and 4 case, but cannot handle the 3-byte width case (see [this example](https://go.dev/play/p/5QKZ1ove5Ab) in the Go playground). For the odd-width cases I suppose we could pad the buffer with additional zeros, but that's getting gnarly just to make `binary.Decode` work IMO -- 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