blob: 8d6b2c2159dcc2e8281232b645e6e927ca471f7d [file] [log] [blame]
Jens Geyer0853ab62013-12-17 21:38:44 +01001/*
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
20package 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
41func Float32Ptr(v float32) *float32 { return &v }
42func Float64Ptr(v float64) *float64 { return &v }
43func IntPtr(v int) *int { return &v }
44func Int32Ptr(v int32) *int32 { return &v }
45func Int64Ptr(v int64) *int64 { return &v }
46func StringPtr(v string) *string { return &v }
47func Uint32Ptr(v uint32) *uint32 { return &v }
48func Uint64Ptr(v uint64) *uint64 { return &v }
Jens Geyer731975a2014-05-02 00:24:24 +020049func BoolPtr(v bool) *bool { return &v }
50func ByteSlicePtr(v []byte) *[]byte { return &v }