Jens Geyer | 0853ab6 | 2013-12-17 21:38:44 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | package thrift |
| 21 | |
| 22 | /////////////////////////////////////////////////////////////////////////////// |
| 23 | // This file is home to helpers that convert from various base types to |
| 24 | // respective pointer types. This is necessary because Go does not permit |
| 25 | // references to constants, nor can a pointer type to base type be allocated |
| 26 | // and initialized in a single expression. |
| 27 | // |
| 28 | // E.g., this is not allowed: |
| 29 | // |
| 30 | // var ip *int = &5 |
| 31 | // |
| 32 | // But this *is* allowed: |
| 33 | // |
| 34 | // func IntPtr(i int) *int { return &i } |
| 35 | // var ip *int = IntPtr(5) |
| 36 | // |
| 37 | // Since pointers to base types are commonplace as [optional] fields in |
| 38 | // exported thrift structs, we factor such helpers here. |
| 39 | /////////////////////////////////////////////////////////////////////////////// |
| 40 | |
| 41 | func Float32Ptr(v float32) *float32 { return &v } |
| 42 | func Float64Ptr(v float64) *float64 { return &v } |
| 43 | func IntPtr(v int) *int { return &v } |
| 44 | func Int32Ptr(v int32) *int32 { return &v } |
| 45 | func Int64Ptr(v int64) *int64 { return &v } |
| 46 | func StringPtr(v string) *string { return &v } |
| 47 | func Uint32Ptr(v uint32) *uint32 { return &v } |
| 48 | func Uint64Ptr(v uint64) *uint64 { return &v } |
Jens Geyer | 731975a | 2014-05-02 00:24:24 +0200 | [diff] [blame] | 49 | func BoolPtr(v bool) *bool { return &v } |
| 50 | func ByteSlicePtr(v []byte) *[]byte { return &v } |