Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
Syyong committed Oct 20, 2018
1 parent 4c747e8 commit 544d2dc
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: go

go:
- 1.9.x
- 1.9.x
67 changes: 45 additions & 22 deletions php2go.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@
package php2go

import (
"time"
"fmt"
"archive/zip"
"bytes"
"crypto/md5"
"encoding/hex"
"io/ioutil"
"net/url"
"strings"
"math"
"crypto/sha1"
"encoding/base64"
"encoding/binary"
"encoding/csv"
"encoding/hex"
"encoding/json"
"os"
"strconv"
"syscall"
"bytes"
"unicode/utf8"
"path/filepath"
"math/rand"
"crypto/sha1"
"fmt"
"hash/crc32"
"html"
"unicode"
"io"
"encoding/csv"
"runtime"
"archive/zip"
"reflect"
"io/ioutil"
"math"
"math/rand"
"net"
"net/url"
"os"
"os/exec"
"path/filepath"
"reflect"
"regexp"
"net"
"encoding/binary"
"runtime"
"strconv"
"strings"
"syscall"
"time"
"unicode"
"unicode/utf8"
)

//////////// Date/Time Functions ////////////
Expand Down Expand Up @@ -1978,6 +1978,29 @@ func ZipOpen(filename string) (*zip.ReadCloser, error) {
return zip.OpenReader(filename)
}

// pack()
func Pack(order binary.ByteOrder, data interface{}) (string, error) {
buf := new(bytes.Buffer)
err := binary.Write(buf, order, data)
if err != nil {
return "", err
}

return buf.String(), nil
}

// unpack()
func Unpack(order binary.ByteOrder, data string) (interface{}, error) {
var result []byte
r := bytes.NewReader([]byte(data))
err := binary.Read(r, order, &result)
if err != nil {
return nil, err
}

return result, nil
}

// Ternary expression
// max := Ternary(a > b, a, b).(int)
func Ternary(condition bool, trueVal, falseVal interface{}) interface{} {
Expand Down
16 changes: 13 additions & 3 deletions php2go_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package php2go

import (
"testing"
"reflect"
"bytes"
"unicode/utf8"
"encoding/binary"
"fmt"
"os"
"reflect"
"testing"
"unicode/utf8"
)

func TestTime(t *testing.T) {
Expand Down Expand Up @@ -336,6 +338,14 @@ func TestMisc(t *testing.T) {

tMemoryGetUsage := MemoryGetUsage(true)
gt(t, float64(tMemoryGetUsage), 0)

tPack, err := Pack(binary.LittleEndian, []byte("abc"))
fmt.Println(err)
fmt.Println(tPack)

tUnpack, err := Unpack(binary.LittleEndian, tPack)
fmt.Println(err)
fmt.Println(tUnpack)
}

func BenchmarkFn(b *testing.B) {
Expand Down

0 comments on commit 544d2dc

Please sign in to comment.