代码拉取完成,页面将自动刷新
同步操作将从 Hprose/hprose-go 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/**********************************************************\
| |
| hprose |
| |
| Official WebSite: http://www.hprose.com/ |
| http://www.hprose.org/ |
| |
\**********************************************************/
/**********************************************************\
* *
* hprose/formatter.go *
* *
* hprose Formatter for Go. *
* *
* LastModified: May 24, 2015 *
* Author: Ma Bingyao <andot@hprose.com> *
* *
\**********************************************************/
package hprose
import (
"bytes"
"io"
"unicode/utf8"
)
// BytesReader is a bytes reader
type BytesReader struct {
Bytes []byte
Pos int
}
// NewBytesReader is the constructor of BytesReader
func NewBytesReader(b []byte) (reader *BytesReader) {
reader = new(BytesReader)
reader.Bytes = b
return
}
// Read bytes from BytesReader
func (r *BytesReader) Read(b []byte) (n int, err error) {
if len(b) == 0 {
return 0, nil
}
if r.Pos >= len(r.Bytes) {
return 0, io.EOF
}
n = copy(b, r.Bytes[r.Pos:])
r.Pos += n
return n, nil
}
// ReadByte from BytesReader
func (r *BytesReader) ReadByte() (b byte, err error) {
if r.Pos >= len(r.Bytes) {
return 0, io.EOF
}
b = r.Bytes[r.Pos]
r.Pos++
return
}
// ReadRune from BytesReader
func (r *BytesReader) ReadRune() (ch rune, size int, err error) {
if r.Pos >= len(r.Bytes) {
return 0, 0, io.EOF
}
if c := r.Bytes[r.Pos]; c < utf8.RuneSelf {
r.Pos++
return rune(c), 1, nil
}
ch, size = utf8.DecodeRune(r.Bytes[r.Pos:])
r.Pos += size
return
}
// ReadString from BytesReader
func (r *BytesReader) ReadString(delim byte) (line string, err error) {
i := bytes.IndexByte(r.Bytes[r.Pos:], delim)
end := r.Pos + i + 1
if i < 0 {
end = len(r.Bytes)
err = io.EOF
}
line = string(r.Bytes[r.Pos:end])
r.Pos = end
return line, err
}
// Serialize data
func Serialize(v interface{}, simple bool) ([]byte, error) {
buf := new(bytes.Buffer)
writer := NewWriter(buf, simple)
err := writer.Serialize(v)
return buf.Bytes(), err
}
// Marshal data
func Marshal(v interface{}) ([]byte, error) {
return Serialize(v, true)
}
// Unserialize data
func Unserialize(b []byte, p interface{}, simple bool) error {
buf := NewBytesReader(b)
reader := NewReader(buf, simple)
return reader.Unserialize(p)
}
// Unmarshal data
func Unmarshal(b []byte, p interface{}) error {
return Unserialize(b, p, true)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。