github.com/cloudwego/frugal@v0.1.15/internal/binary/decoder/errors.go (about) 1 /* 2 * Copyright 2022 ByteDance Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package decoder 18 19 import ( 20 `fmt` 21 `math/bits` 22 23 `github.com/cloudwego/frugal/internal/atm/hir` 24 `github.com/cloudwego/frugal/internal/rt` 25 ) 26 27 //go:nosplit 28 func error_eof(n int) error { 29 return fmt.Errorf("frugal: unexpected EOF: %d bytes short", n) 30 } 31 32 //go:nosplit 33 func error_skip(e int) error { 34 switch e { 35 case ETAG : return fmt.Errorf("frugal: error when skipping fields: -1 (invalid tag)") 36 case EEOF : return fmt.Errorf("frugal: error when skipping fields: -2 (unexpected EOF)") 37 case ESTACK : return fmt.Errorf("frugal: error when skipping fields: -3 (value nesting too deep)") 38 default : return fmt.Errorf("frugal: error when skipping fields: %d (unknown error)", e) 39 } 40 } 41 42 //go:nosplit 43 func error_type(e uint8, t uint8) error { 44 return fmt.Errorf("frugal: type mismatch: %d expected, got %d", e, t) 45 } 46 47 //go:nosplit 48 func error_missing(t *rt.GoType, i int, m uint64) error { 49 return fmt.Errorf("frugal: missing required field %d for type %s", i * 64 + bits.TrailingZeros64(m), t) 50 } 51 52 var ( 53 F_error_eof = hir.RegisterGCall(error_eof, emu_gcall_error_eof) 54 F_error_skip = hir.RegisterGCall(error_skip, emu_gcall_error_skip) 55 F_error_type = hir.RegisterGCall(error_type, emu_gcall_error_type) 56 F_error_missing = hir.RegisterGCall(error_missing, emu_gcall_error_missing) 57 )